diff --git a/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java b/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java index d63f134f0a..5e67fda0a8 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestCMIS.java @@ -25,6 +25,7 @@ */ package org.alfresco.rest.api.tests; +import static org.alfresco.model.ContentModel.ASSOC_ORIGINAL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -51,12 +52,14 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.StringJoiner; import org.alfresco.cmis.client.AlfrescoDocument; import org.alfresco.cmis.client.AlfrescoFolder; import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl; import org.alfresco.cmis.client.type.AlfrescoType; import org.alfresco.model.ContentModel; +import org.alfresco.model.RenditionModel; import org.alfresco.opencmis.CMISDispatcherRegistry.Binding; import org.alfresco.opencmis.PublicApiAlfrescoCmisServiceFactory; import org.alfresco.opencmis.dictionary.CMISStrictDictionaryService; @@ -98,14 +101,17 @@ import org.alfresco.rest.api.tests.client.data.SiteRole; import org.alfresco.rest.api.tests.client.data.Tag; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockType; +import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentReader; +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.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.alfresco.util.TempFileProvider; @@ -141,6 +147,7 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.extensions.surf.util.URLEncoder; @@ -174,9 +181,16 @@ public class TestCMIS extends EnterpriseTestApi private CMISStrictDictionaryService cmisDictionary; private QNameFilter cmisTypeExclusions; private NodeService nodeService; + private FileFolderService fileFolderService; + protected ContentService contentService; private PermissionService permissionService; private Properties globalProperties; + private TestNetwork testNetwork; + private TestSite testSite; + private String testPersonId; + private String testFileIdWithTwoRenditions; + @Before public void before() throws Exception { @@ -187,6 +201,8 @@ public class TestCMIS extends EnterpriseTestApi this.cmisDictionary = (CMISStrictDictionaryService)ctx.getBean("OpenCMISDictionaryService"); this.cmisTypeExclusions = (QNameFilter)ctx.getBean("cmisTypeExclusions"); this.nodeService = (NodeService) ctx.getBean("NodeService"); + this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService"); + this.contentService = (ContentService)applicationContext.getBean("ContentService"); this.permissionService = (PermissionService) ctx.getBean("permissionService"); this.globalProperties = (Properties) ctx.getBean("global-properties"); @@ -199,6 +215,256 @@ public class TestCMIS extends EnterpriseTestApi this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "false"); } + private TestNetwork getTestNetwork() throws Exception + { + if (testNetwork == null) + { + testNetwork = getTestFixture().getRandomNetwork(); + } + return testNetwork; + } + + private String getTestPersonId() throws Exception + { + if (testPersonId == null) + { + getTestNetwork(); + + String username = "user" + System.currentTimeMillis(); + PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null); + TestPerson person = testNetwork.createUser(personInfo); + testPersonId = person.getId(); + } + return testPersonId; + } + + private TestSite getTestSite() throws Exception + { + if (testSite == null) + { + getTestNetwork(); + getTestPersonId(); + + String siteName = "site" + System.currentTimeMillis(); + testSite = TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public TestSite doWork() throws Exception + { + SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC); + return testNetwork.createSite(siteInfo); + } + }, testPersonId, testNetwork.getId()); + } + return testSite; + } + + private NodeRef makeRenditionNode(NodeRef parent, String title, String name, String mimetype) + { + Map props = new HashMap(); + props.put(ContentModel.PROP_NAME, name); + props.put(ContentModel.PROP_TITLE, title); + QName assocQName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, name); + ChildAssociationRef assoc = nodeService.createNode(parent, RenditionModel.ASSOC_RENDITION, + assocQName, ContentModel.TYPE_THUMBNAIL, props); + NodeRef childRef = assoc.getChildRef(); + + if (!nodeService.hasAspect(parent, RenditionModel.ASPECT_RENDITIONED)) + { + nodeService.addAspect(parent, RenditionModel.ASPECT_RENDITIONED, null); + } + + ContentWriter writer = contentService.getWriter(childRef, ContentModel.PROP_CONTENT, true); + writer.setMimetype(mimetype); + writer.setEncoding("UTF-8"); + writer.putContent("Dummy "+name+" content"); + + return childRef; + } + + private String getTestFileIdWithTwoRenditionsOneSourceAndTwoTargetAssociations() throws Exception + { + if (testFileIdWithTwoRenditions == null) + { + getTestNetwork(); + getTestPersonId(); + getTestSite(); + + NodeRef fileNode = TenantUtil.runAsUserTenant(new TenantRunAsWork() + { + @Override + public NodeRef doWork() throws Exception + { + NodeRef documentLibrary = testSite.getContainerNodeRef("documentLibrary"); + NodeRef folder = repoService.createFolder(documentLibrary, "myFoder"); + NodeRef testFile1 = repoService.createDocument(folder, + "testdoc1.txt", "Test title 1", "Test description 1", "Test content 2"); + + makeRenditionNode(testFile1, "pdf", "pdf", "application/pdf"); + makeRenditionNode(testFile1, "doclib", "thumbnail", "image/png"); + + // Make three more files and associate one as the source of testFile1 and the others as a copy of it. + NodeRef testFile0 = repoService.createDocument(folder, + "testdoc0.txt", "Test title 0", "Test description 0", "Test content 0"); + NodeRef testFile2 = repoService.createDocument(folder, + "testdoc2.txt", "Test title 2", "Test description 2", "Test content 2"); + NodeRef testFile3 = repoService.createDocument(folder, + "testdoc3.txt", "Test title 3", "Test description 3", "Test content 3"); + nodeService.addAspect(testFile1, ContentModel.ASPECT_COPIEDFROM, null); + nodeService.addAspect(testFile2, ContentModel.ASPECT_COPIEDFROM, null); + nodeService.addAspect(testFile3, ContentModel.ASPECT_COPIEDFROM, null); + nodeService.createAssociation(testFile1, testFile0, ASSOC_ORIGINAL); + nodeService.createAssociation(testFile2, testFile1, ASSOC_ORIGINAL); + nodeService.createAssociation(testFile3, testFile1, ASSOC_ORIGINAL); + + return testFile1; + } + }, testPersonId, testNetwork.getId()); + testFileIdWithTwoRenditions = fileNode.getId(); + } + return testFileIdWithTwoRenditions; + } + + private void assertGetIdFilterParams(int expectedProperties, + int expectedRenditions, + int expecteRelationships, + int expectedAllowableActions, + int expectedPolicyIds, + int expectedAcls, + String... params) throws Exception + { + String cmisId = getTestFileIdWithTwoRenditionsOneSourceAndTwoTargetAssociations(); + + HashMap reqParams = new HashMap<>(); + reqParams.put("id", cmisId); + StringJoiner sj = new StringJoiner(", "); + for (int i=0; i reqParams = new HashMap<>(); + reqParams.put("id", cmisId); + + publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), testPersonId)); + HttpResponse resp = publicApiClient.get(Binding.atom, CMIS_VERSION_11, "id", reqParams); + String xml = resp.getResponse(); + + System.out.println(xml); + + String tmp1 = xml.split("cmis:properties")[1]; + String tmp2 = tmp1.substring(0, tmp1.indexOf(" names = new ArrayList<>(); + for (int j=1; j duplicates = new HashSet(); + final Set uniqueNames = new HashSet(); + for (String name : names) + { + if (!uniqueNames.add(name)) + { + duplicates.add(name); + } + } + if (!duplicates.isEmpty()) + { + StringJoiner sj = new StringJoiner((", ")); + for (String duplicate : duplicates) + { + sj.add(duplicate); + } + fail("The following property names were repeated: "+sj); + } + } }