Merge from SEAMIST3

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10722 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-09-04 10:44:42 +00:00
parent 617f8e0b2c
commit f51be032bc
170 changed files with 18520 additions and 203 deletions

View File

@@ -0,0 +1,105 @@
package org.alfresco.repo.cmis.ws;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import junit.framework.TestCase;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.springframework.context.support.FileSystemXmlApplicationContext;
/**
* @author Michael Shavnev
*/
public abstract class AbstractServiceTest extends TestCase
{
protected ServiceRegistry serviceRegistry;
protected static NodeRef ALFRESCO_TUTORIAL_NODE_REF = null;
protected static NodeRef COMPANY_HOME_NODE_REF = null;
protected static FileSystemXmlApplicationContext fContext = null;
protected Object servicePort = null;
@Override
protected void setUp() throws Exception
{
super.setUp();
if (fContext == null)
{
fContext = new FileSystemXmlApplicationContext("classpath:alfresco/application-context.xml");
AuthenticationComponent authenticationComponent = (AuthenticationComponent) fContext.getBean("authenticationComponent");
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
serviceRegistry = (ServiceRegistry) fContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
ResultSet resultSet = serviceRegistry.getSearchService().query(new StoreRef("workspace://SpacesStore"), "lucene", "@cm\\:name:Alfresco-Tutorial.pdf");
ALFRESCO_TUTORIAL_NODE_REF = resultSet.getNodeRef(0);
resultSet = serviceRegistry.getSearchService().query(new StoreRef("workspace://SpacesStore"), "lucene", "@cm\\:name:Company Home");
COMPANY_HOME_NODE_REF = resultSet.getNodeRef(0);
authenticationComponent.clearCurrentSecurityContext();
}
}
public AbstractServiceTest()
{
servicePort = getServicePort();
Map<String, Object> wss4jOutInterceptorProp = new HashMap<String, Object>();
wss4jOutInterceptorProp.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.TIMESTAMP);
wss4jOutInterceptorProp.put(WSHandlerConstants.USER, getUserName());
// outProps.setProperty(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
wss4jOutInterceptorProp.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
wss4jOutInterceptorProp.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler()
{
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword(getPassword());
}
});
WSS4JOutInterceptor wss4jOutInterceptor = new WSS4JOutInterceptor(wss4jOutInterceptorProp);
Client client = ClientProxy.getClient(servicePort);
client.getEndpoint().getOutInterceptors().add(new SAAJOutInterceptor());
client.getEndpoint().getOutInterceptors().add(wss4jOutInterceptor);
}
protected abstract Object getServicePort();
protected String getUserName()
{
return "admin";
}
protected String getPassword()
{
return "admin";
}
}

View File

@@ -0,0 +1,144 @@
package org.alfresco.repo.cmis.ws;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* Base class for all CMIS content tests
*
* @author Dmitry Lazurkin
*
*/
public class BaseServicePortContentTest extends BaseServicePortTest
{
protected CheckOutCheckInService checkOutCheckInService;
private static final String IMPORT = "import-for-cmis-ws-test.acp";
protected static final String L0_FILE_0 = "L0-File-0";
protected static final String L0_FILE_1 = "L0-File-1";
protected static final String L0_FILE_2 = "L0-File-2";
protected static final String L1_FILE_0 = "L1-File-0";
protected static final String L1_FILE_1 = "L1-File-1";
protected static final String L1_FILE_VERSIONABLE = "L1-File-Versionable";
protected static final String L0_FOLDER_0 = "L0-Folder-0";
protected static final String L0_FOLDER_1 = "L0-Folder-1";
protected static final String L0_FOLDER_2 = "L0-Folder-2";
protected static final String L1_FOLDER_0 = "L1-Folder-0";
protected static final String L1_FOLDER_1 = "L1-Folder-1";
protected NodeRef L0_FILE_0_NODEREF;
protected NodeRef L0_FILE_1_NODEREF;
protected NodeRef L0_FILE_2_NODEREF;
protected NodeRef L1_FILE_0_NODEREF;
protected NodeRef L1_FILE_1_NODEREF;
protected NodeRef L0_FOLDER_0_NODEREF;
protected NodeRef L0_FOLDER_1_NODEREF;
protected NodeRef L0_FOLDER_2_NODEREF;
protected NodeRef L1_FOLDER_0_NODEREF;
protected NodeRef L1_FOLDER_1_NODEREF;
protected NodeRef L0_NONEXISTENT_NODEREF;
protected NodeRef L1_FILE_VERSION_2_1_NODEREF;
protected NodeRef L1_FILE_VERSION_2_0_NODEREF;
protected NodeRef L1_FILE_VERSION_1_0_NODEREF;
protected AssociationRef L0_FILE_1_TO_L0_FILE_0_ASSOCREF;
protected AssociationRef NONEXISTENT_ASSOCREF;
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
checkOutCheckInService = serviceRegistry.getCheckOutCheckInService();
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
InputStream is = getClass().getClassLoader().getResourceAsStream(IMPORT);
if (is == null)
{
throw new NullPointerException("Test resource not found: " + IMPORT);
}
NodeRef importForTest = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "import-for-test.acp"), ContentModel.TYPE_CONTENT).getChildRef();
ContentService contentService = serviceRegistry.getContentService();
ContentWriter writer = contentService.getWriter(importForTest, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
writer.setEncoding("UTF-8");
writer.putContent(is);
Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, rootNodeRef);
params.put(ImporterActionExecuter.PARAM_ENCODING, "UTF-8");
ActionService actionService = serviceRegistry.getActionService();
Action action = actionService.createAction(ImporterActionExecuter.NAME, params);
action.setExecuteAsynchronously(false);
actionService.executeAction(action, importForTest);
nodeService.deleteNode(importForTest);
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
VersionService versionService = serviceRegistry.getVersionService();
L0_FILE_0_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FILE_0)).getNodeRef();
L0_FILE_1_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FILE_1)).getNodeRef();
L0_FILE_2_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FILE_2)).getNodeRef();
L0_FOLDER_0_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FOLDER_0)).getNodeRef();
L0_FOLDER_1_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FOLDER_1)).getNodeRef();
L0_FOLDER_2_NODEREF = fileFolderService.resolveNamePath(rootNodeRef, Collections.singletonList(L0_FOLDER_2)).getNodeRef();
L1_FILE_0_NODEREF = fileFolderService.resolveNamePath(L0_FOLDER_0_NODEREF, Collections.singletonList(L1_FILE_0)).getNodeRef();
L1_FILE_1_NODEREF = fileFolderService.resolveNamePath(L0_FOLDER_1_NODEREF, Collections.singletonList(L1_FILE_1)).getNodeRef();
L1_FILE_VERSION_2_1_NODEREF = fileFolderService.resolveNamePath(L0_FOLDER_2_NODEREF, Collections.singletonList(L1_FILE_VERSIONABLE)).getNodeRef();
nodeService.addAspect(L1_FILE_VERSION_2_1_NODEREF, ContentModel.ASPECT_VERSIONABLE, Collections.singletonMap(ContentModel.PROP_AUTO_VERSION, (Serializable) Boolean.FALSE));
contentService.getWriter(L1_FILE_VERSION_2_1_NODEREF, ContentModel.PROP_CONTENT, true).putContent("1.0");
L1_FILE_VERSION_1_0_NODEREF = versionService.createVersion(L1_FILE_VERSION_2_1_NODEREF, createVersionProps("1.0", VersionType.MAJOR)).getFrozenStateNodeRef();
contentService.getWriter(L1_FILE_VERSION_2_1_NODEREF, ContentModel.PROP_CONTENT, true).putContent("2.0");
L1_FILE_VERSION_2_0_NODEREF = versionService.createVersion(L1_FILE_VERSION_2_1_NODEREF, createVersionProps("2.0", VersionType.MAJOR)).getFrozenStateNodeRef();
contentService.getWriter(L1_FILE_VERSION_2_1_NODEREF, ContentModel.PROP_CONTENT, true).putContent("2.1");
versionService.createVersion(L1_FILE_VERSION_2_1_NODEREF, createVersionProps("2.1", VersionType.MINOR));
L1_FOLDER_0_NODEREF = fileFolderService.resolveNamePath(L0_FOLDER_0_NODEREF, Collections.singletonList(L1_FOLDER_0)).getNodeRef();
L1_FOLDER_1_NODEREF = fileFolderService.resolveNamePath(L0_FOLDER_0_NODEREF, Collections.singletonList(L1_FOLDER_1)).getNodeRef();
L0_NONEXISTENT_NODEREF = importForTest;
L0_FILE_1_TO_L0_FILE_0_ASSOCREF = nodeService.createAssociation(L0_FILE_1_NODEREF, L0_FILE_0_NODEREF, ContentModel.ASSOC_REFERENCES);
NONEXISTENT_ASSOCREF = new AssociationRef(L1_FILE_0_NODEREF, ContentModel.ASSOC_REFERENCES, L1_FILE_1_NODEREF);
authenticationComponent.clearCurrentSecurityContext();
}
private Map<String, Serializable> createVersionProps(String comment, VersionType versionType)
{
Map<String, Serializable> props = new HashMap<String, Serializable>(1, 1.0f);
props.put(Version.PROP_DESCRIPTION, comment);
props.put(VersionModel.PROP_VERSION_TYPE, versionType);
return props;
}
}

View File

@@ -0,0 +1,102 @@
package org.alfresco.repo.cmis.ws;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/**
* Base class for all CMIS tests
*
* @author Dmitry Lazurkin
*
*/
public class BaseServicePortTest extends AbstractDependencyInjectionSpringContextTests
{
protected AuthenticationService authenticationService;
protected TransactionService transactionService;
protected NodeService nodeService;
protected ServiceRegistry serviceRegistry;
protected DictionaryService dictionaryService;
protected AuthenticationComponent authenticationComponent;
private UserTransaction txn;
protected NodeRef rootNodeRef;
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
authenticationService = serviceRegistry.getAuthenticationService();
transactionService = serviceRegistry.getTransactionService();
nodeService = serviceRegistry.getNodeService();
dictionaryService = serviceRegistry.getDictionaryService();
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
// start the transaction
txn = transactionService.getUserTransaction();
txn.begin();
IntegrityChecker.setWarnInTransaction();
// authenticate
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
// create a test store if need
StoreRef storeRef = new StoreRef("workspace://CmisTestWorkspace");
if (nodeService.exists(storeRef) == false)
{
storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "CmisTestWorkspace");
}
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
rootNodeRef = new NodeRef(storeRef, "alf:root_folder");
if (nodeService.exists(rootNodeRef) == false)
{
rootNodeRef = nodeService.createNode(storeRootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "root_folder"),
ContentModel.TYPE_FOLDER).getChildRef();
}
authenticationComponent.clearCurrentSecurityContext();
}
@Override
protected void onTearDown() throws Exception
{
try
{
txn.rollback();
}
catch (Throwable e)
{
e.printStackTrace();
}
}
@Override
protected String[] getConfigLocations()
{
return new String[] { "classpath:alfresco/application-context.xml", "classpath:test-cmis-context.xml" };
}
}

View File

@@ -0,0 +1,251 @@
package org.alfresco.repo.cmis.ws;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cmis.ws.OIDUtils;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @see org.alfresco.cmis.ws.NavigationServicePortDM
*
* @author Dmitry Lazurkin
*
*/
public class DMNavigationServicePortTest extends BaseServicePortContentTest
{
private NavigationServicePort navigationServicePort;
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
navigationServicePort = (NavigationServicePort) applicationContext.getBean("dmNavigationService");
}
public void testGetChildrenFolders() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF };
checkListExact(listing, 0, 3, expectedNodeRefs);
}
public void testGetChildrenDocuments() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.DOCUMENTS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkListExact(listing, 3, 0, expectedNodeRefs);
}
public void testGetChildrenSkipCount() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setSkipCount(BigInteger.valueOf(1));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkList(listing, 5, 3, 3, expectedNodeRefs);
}
public void testGetChildrenMaxItems() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setMaxItems(BigInteger.valueOf(3));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkList(listing, 3, 3, 3, expectedNodeRefs);
}
public void testGetChildrenMaxItemsMore() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setMaxItems(BigInteger.valueOf(10));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkList(listing, 6, 3, 3, expectedNodeRefs);
}
public void testGetChildrenSkipCountMore() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setSkipCount(BigInteger.valueOf(10));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkList(listing, 0, 3, 3, expectedNodeRefs);
}
public void testGetChildrenMaxItemsSkipCount() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setSkipCount(BigInteger.valueOf(5));
request.setMaxItems(BigInteger.valueOf(4));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkList(listing, 1, 3, 3, expectedNodeRefs);
}
public void testGetChildrenMaxItemsZero() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setMaxItems(BigInteger.valueOf(0));
request.setFolderId(OIDUtils.toOID(rootNodeRef));
request.setType(TypesOfObjectsEnum.FOLDERS_AND_DOCUMETS);
GetChildrenResponse response = navigationServicePort.getChildren(request);
List<DocumentOrFolderObjectType> listing = response.getDocumentAndFolderCollection().getObject();
NodeRef[] expectedNodeRefs = new NodeRef[] { L0_FOLDER_0_NODEREF, L0_FOLDER_1_NODEREF, L0_FOLDER_2_NODEREF, L0_FILE_0_NODEREF, L0_FILE_1_NODEREF, L0_FILE_2_NODEREF };
checkListExact(listing, 3, 3, expectedNodeRefs);
}
public void testGetChildrenForDocument() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setFolderId(OIDUtils.toOID(L0_FILE_0_NODEREF));
request.setType(TypesOfObjectsEnum.FOLDERS);
try
{
navigationServicePort.getChildren(request);
}
catch (FolderNotValidException e)
{
return;
}
fail("Expects exception");
}
public void testGetChildrenForRelationship() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetChildren request = new GetChildren();
request.setFolderId(OIDUtils.toOID(L0_FILE_1_TO_L0_FILE_0_ASSOCREF));
request.setType(TypesOfObjectsEnum.FOLDERS);
try
{
navigationServicePort.getChildren(request);
}
catch (FolderNotValidException e)
{
return;
}
fail("Expects exception");
}
private void checkListExact(List<DocumentOrFolderObjectType> objects, int expectedFileCount, int expectedFolderCount, NodeRef[] expectedNodeRefs)
{
int fileCount = 0;
int folderCount = 0;
List<NodeRef> check = new ArrayList<NodeRef>(8);
for (NodeRef nodeRef : expectedNodeRefs)
{
check.add(nodeRef);
}
for (DocumentOrFolderObjectType object : objects)
{
NodeRef nodeRef = OIDUtils.OIDtoNodeRef(object.getObjectID());
if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER))
{
folderCount++;
}
else
{
fileCount++;
}
assertTrue(check.remove(nodeRef));
}
assertTrue("Name list was not exact - remaining: " + check, check.size() == 0);
assertEquals("Incorrect number of files", expectedFileCount, fileCount);
assertEquals("Incorrect number of folders", expectedFolderCount, folderCount);
}
private void checkList(List<DocumentOrFolderObjectType> objects, int expectedCount, int expectedMaxFileCount, int expectedMaxFolderCount, NodeRef[] expectedNodeRefs)
{
int fileCount = 0;
int folderCount = 0;
List<NodeRef> check = new ArrayList<NodeRef>(8);
for (NodeRef nodeRef : expectedNodeRefs)
{
check.add(nodeRef);
}
for (DocumentOrFolderObjectType object : objects)
{
NodeRef nodeRef = OIDUtils.OIDtoNodeRef(object.getObjectID());
if (dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER))
{
folderCount++;
}
else
{
fileCount++;
}
assertTrue(check.remove(nodeRef));
}
assertTrue((fileCount + folderCount) == expectedCount);
assertTrue(fileCount <= expectedMaxFileCount);
assertTrue(folderCount <= expectedMaxFolderCount);
}
}

View File

@@ -0,0 +1,231 @@
package org.alfresco.repo.cmis.ws;
import java.math.BigInteger;
import org.alfresco.repo.cmis.ws.OIDUtils;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @see org.alfresco.cmis.ws.ObjectServicePortDM
*
* @author Dmitry Lazurkin
*
*/
public class DMObjectServicePortTest extends BaseServicePortContentTest
{
private ObjectServicePort objectServicePort;
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
objectServicePort = (ObjectServicePort) applicationContext.getBean("dmObjectService");
}
public void testGetExistentFolderProperties() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(L0_FOLDER_0_NODEREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertEquals(OIDUtils.toOID(rootNodeRef), response.getObject().getParent());
assertEquals(L0_FOLDER_0, response.getObject().getName());
}
public void testGetExistentDocumentPropertiesThis() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(L1_FILE_VERSION_1_0_NODEREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertEquals(response.getObject().getCheckinComment(), "1.0");
assertEquals(response.getObject().isIsMajorVersion(), Boolean.TRUE);
assertEquals(response.getObject().isIsLatestMajorVersion(), Boolean.FALSE);
assertEquals(response.getObject().isIsLatestVersion(), Boolean.FALSE);
}
public void testGetExistentDocumentPropertiesLatestMajor() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setReturnVersion(VersionEnum.LATEST_MAJOR);
request.setObjectId(OIDUtils.toOID(L1_FILE_VERSION_1_0_NODEREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertEquals(response.getObject().getCheckinComment(), "2.0");
assertEquals(response.getObject().isIsMajorVersion(), Boolean.TRUE);
assertEquals(response.getObject().isIsLatestMajorVersion(), Boolean.TRUE);
assertEquals(response.getObject().isIsLatestVersion(), Boolean.FALSE);
}
public void testGetExistentDocumentPropertiesLatest() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setReturnVersion(VersionEnum.LATEST);
request.setObjectId(OIDUtils.toOID(L1_FILE_VERSION_2_0_NODEREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertEquals(response.getObject().getCheckinComment(), "2.1");
assertEquals(response.getObject().isIsMajorVersion(), Boolean.FALSE);
assertEquals(response.getObject().isIsLatestMajorVersion(), Boolean.FALSE);
assertEquals(response.getObject().isIsLatestVersion(), Boolean.TRUE);
}
public void testGetExistentRelationshipProperties() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(L0_FILE_1_TO_L0_FILE_0_ASSOCREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertEquals(OIDUtils.toOID(L0_FILE_1_TO_L0_FILE_0_ASSOCREF.getSourceRef()), response.getObject().getSourceOID());
assertEquals(OIDUtils.toOID(L0_FILE_1_TO_L0_FILE_0_ASSOCREF.getTargetRef()), response.getObject().getTargetOID());
fail("Not implement");
}
public void testGetNonExistentObjectProperties() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(L0_NONEXISTENT_NODEREF));
try
{
objectServicePort.getProperties(request);
}
catch (ObjectNotFoundException e)
{
return;
}
fail("Expects exception");
}
public void testGetNonExistentRelationshipProperties() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(NONEXISTENT_ASSOCREF));
try
{
objectServicePort.getProperties(request);
}
catch (ObjectNotFoundException e)
{
return;
}
fail("Expects exception");
}
public void testGetPropertiesForInvalidOID() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetProperties request = new GetProperties();
request.setObjectId("invalid OID");
try
{
objectServicePort.getProperties(request);
}
catch (InvalidArgumentException e)
{
return;
}
fail("Expects exception");
}
public void testGetPropertiesCheckedout() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
NodeRef workingCopyNodeRef = checkOutCheckInService.checkout(L0_FILE_0_NODEREF);
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(L0_FILE_0_NODEREF));
GetPropertiesResponse response = objectServicePort.getProperties(request);
assertNotNull(response);
assertNull(response.getObject().getCheckinComment());
assertTrue(response.getObject().isIsMajorVersion());
assertTrue(response.getObject().isIsLatestMajorVersion());
assertTrue(response.getObject().isIsLatestVersion());
assertTrue(response.getObject().isVersionSeriesIsCheckedOut());
assertEquals(response.getObject().getVersionSeriesCheckedOutBy(), authenticationComponent.getSystemUserName());
assertEquals(response.getObject().getVersionSeriesCheckedOutOID(), OIDUtils.toOID(workingCopyNodeRef));
request = new GetProperties();
request.setObjectId(OIDUtils.toOID(workingCopyNodeRef));
response = objectServicePort.getProperties(request);
assertNotNull(response);
assertNull(response.getObject().getCheckinComment());
assertFalse(response.getObject().isIsMajorVersion());
assertFalse(response.getObject().isIsLatestMajorVersion());
assertFalse(response.getObject().isIsLatestVersion());
assertTrue(response.getObject().isVersionSeriesIsCheckedOut());
assertEquals(response.getObject().getVersionSeriesCheckedOutBy(), authenticationComponent.getSystemUserName());
assertEquals(response.getObject().getVersionSeriesCheckedOutOID(), OIDUtils.toOID(workingCopyNodeRef));
}
public void testGetContentStream() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
String documentId = OIDUtils.toOID(L0_FILE_0_NODEREF);
for (int offset = 0; offset < 10; offset++)
{
for (int length = 0; length < 10; length++)
{
BigInteger offsetBig = new BigInteger(String.valueOf(offset));
BigInteger lengthBig = new BigInteger(String.valueOf(length));
byte[] result = objectServicePort.getContentStream(documentId, offsetBig, lengthBig);
assertNotNull(result);
if (result.length > length)
{
fail();
}
}
}
byte[] result = objectServicePort.getContentStream(documentId, null, null);
assertNotNull(result);
try
{result = objectServicePort.getContentStream("Invalid", null, null);}
catch (InvalidArgumentException e) {}
catch (Throwable e){fail();}
try
{result = objectServicePort.getContentStream(documentId + "s", null, null);}
catch (ObjectNotFoundException e) {}
catch (Throwable e){fail();}
try
{result = objectServicePort.getContentStream(OIDUtils.toOID(L0_FOLDER_0_NODEREF), null, null);}
catch (StreamNotSupportedException e) {}
catch (Throwable e){fail();}
}
}

View File

@@ -0,0 +1,104 @@
package org.alfresco.repo.cmis.ws;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.alfresco.repo.cmis.ws.OIDUtils;
public class DMObjectServiceTest extends AbstractServiceTest
{
public final static String SERVICE_WSDL_LOCATION = "http://localhost:8080/alfresco/cmis/ObjectService?wsdl";
public final static QName SERVICE_NAME = new QName("http://www.cmis.org/ns/1.0", "ObjectService");
protected Object getServicePort()
{
URL serviceWsdlURL;
try
{
serviceWsdlURL = new URL(SERVICE_WSDL_LOCATION);
}
catch (MalformedURLException e)
{
throw new java.lang.RuntimeException("Cannot get service Wsdl URL", e);
}
Service service = Service.create(serviceWsdlURL, SERVICE_NAME);
return service.getPort(ObjectServicePort.class);
}
public void testGetDocumentProperties() throws Exception
{
GetProperties request = new GetProperties();
request.setObjectId(OIDUtils.toOID(ALFRESCO_TUTORIAL_NODE_REF));
GetPropertiesResponse response = ((ObjectServicePort) servicePort).getProperties(request);
assertNotNull(response);
}
public void testGetPropertiesForInvalidOID() throws Exception
{
GetProperties request = new GetProperties();
request.setObjectId("invalid OID");
try
{
((ObjectServicePort) servicePort).getProperties(request);
}
catch (InvalidArgumentException e)
{
return;
}
fail("Expects exception");
}
public void testGetContentStream() throws Exception
{
String documentId = OIDUtils.toOID(ALFRESCO_TUTORIAL_NODE_REF);
for (int offset = 0; offset < 10; offset++)
{
for (int length = 0; length < 10; length++)
{
BigInteger offsetBig = new BigInteger(String.valueOf(offset));
BigInteger lengthBig = new BigInteger(String.valueOf(length));
byte[] result = ((ObjectServicePort) servicePort).getContentStream(documentId, offsetBig, lengthBig);
assertNotNull(result);
if (result.length > length)
{
fail();
}
}
}
byte[] result = ((ObjectServicePort) servicePort).getContentStream(documentId, null, BigInteger.valueOf(20));
assertNotNull(result);
try
{result = ((ObjectServicePort) servicePort).getContentStream("Invalid", null, null);}
catch (InvalidArgumentException e) {}
catch (Throwable e){fail();}
try
{result = ((ObjectServicePort) servicePort).getContentStream(documentId + "s", null, null);}
catch (ObjectNotFoundException e) {}
catch (Throwable e){fail();}
try
{result = ((ObjectServicePort) servicePort).getContentStream(OIDUtils.toOID(COMPANY_HOME_NODE_REF), null, null);}
catch (StreamNotSupportedException e) {}
catch (Throwable e){fail();}
}
}

View File

@@ -0,0 +1,36 @@
package org.alfresco.repo.cmis.ws;
import org.alfresco.repo.cmis.ws.OIDUtils;
/**
* @see org.alfresco.cmis.ws.RepositoryServicePortDM
*
* @author Dmitry Lazurkin
*
*/
public class DMRepositoryServicePortTest extends BaseServicePortTest
{
private RepositoryServicePort repositoryServicePort;
@Override
protected void onSetUp() throws Exception
{
super.onSetUp();
repositoryServicePort = (RepositoryServicePort) applicationContext.getBean("dmRepositoryService");
}
public void testGetRootFolder() throws Exception
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
GetRootFolder request = new GetRootFolder();
request.setFilter("*");
GetRootFolderResponse response = repositoryServicePort.getRootFolder(request);
FolderObjectType rootFolder = response.getRootFolder();
assertEquals(rootNodeRef, OIDUtils.OIDtoNodeRef(rootFolder.getObjectID()));
}
}

View File

@@ -0,0 +1,65 @@
package org.alfresco.repo.cmis.ws;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
/**
* @author Michael Shavnev
*/
public class DMRepositoryServiceTest extends AbstractServiceTest
{
public final static String SERVICE_WSDL_LOCATION = "http://localhost:8080/alfresco/cmis/RepositoryService?wsdl";
public final static QName SERVICE_NAME = new QName("http://www.cmis.org/ns/1.0", "RepositoryService");
protected Object getServicePort()
{
URL serviceWsdlURL;
try
{
serviceWsdlURL = new URL(SERVICE_WSDL_LOCATION);
}
catch (MalformedURLException e)
{
throw new java.lang.RuntimeException("Cannot get service Wsdl URL", e);
}
Service service = Service.create(serviceWsdlURL, SERVICE_NAME);
return service.getPort(RepositoryServicePort.class);
}
public void testGetRootFolder()
{
GetRootFolder getRootFolder = new GetRootFolder();
try
{
getRootFolder.setFilter("*");
((RepositoryServicePort) servicePort).getRootFolder(getRootFolder);
}
catch (Throwable e)
{
e.printStackTrace();
fail();
}
try
{
getRootFolder.setFilter("name");
((RepositoryServicePort) servicePort).getRootFolder(getRootFolder);
fail();
}
catch (FilterNotValidException e)
{
// expected
}
catch (Throwable e)
{
e.printStackTrace();
fail();
}
}
}