Search in sources :

Example 6 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class TestCMIS method testInvalidMethods.

// @Test
public void testInvalidMethods() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    Iterator<String> personIt = network1.getPersonIds().iterator();
    final String person = personIt.next();
    assertNotNull(person);
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
        publicApiClient.post(Binding.atom, CMIS_VERSION_10, null, null);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
        publicApiClient.head(Binding.atom, CMIS_VERSION_10, null, null);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
        publicApiClient.options(Binding.atom, CMIS_VERSION_10, null, null);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
        publicApiClient.trace(Binding.atom, CMIS_VERSION_10, null, null);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person));
        publicApiClient.patch(Binding.atom, CMIS_VERSION_10, null, null);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext)

Example 7 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class TestCMIS method testObjectIds.

/*
     * This test requires lucene, and needs to probably be moved to the repository project or in a system test
     * See REPO-2028 and follow up : REPO-3019
     */
@Test
@Category({ LuceneTests.class, RedundantTests.class })
public void testObjectIds() throws Exception {
    String username = "enterpriseuser" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = repoService.createUser(personInfo, username, null);
    String personId = person.getId();
    final List<NodeRef> folders = new ArrayList<NodeRef>();
    final List<NodeRef> documents = new ArrayList<NodeRef>();
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            folders.add(folderNodeRef);
            name = GUID.generate();
            NodeRef docNodeRef = repoService.createDocument(folderNodeRef, name, "test content");
            documents.add(docNodeRef);
            return null;
        }
    }, personId);
    NodeRef folderNodeRef = folders.get(0);
    NodeRef docNodeRef = documents.get(0);
    publicApiClient.setRequestContext(new RequestContext(personId));
    // use cmisatom endpoint
    List<Repository> repositories = publicApiClient.getCMISRepositories();
    CmisSession cmisSession = publicApiClient.getCMISSession(repositories.get(0));
    // test CMIS accepts NodeRefs and guids as input
    // if input is NodeRef, return NodeRef. If input is guid, return guid.
    {
        String nodeRefStr = docNodeRef.toString();
        CmisObject o = cmisSession.getObject(nodeRefStr);
        assertEquals(docNodeRef.toString(), stripCMISSuffix(o.getId()));
        nodeRefStr = folderNodeRef.toString();
        o = cmisSession.getObject(nodeRefStr);
        assertEquals(folderNodeRef.toString(), stripCMISSuffix(o.getId()));
        String objectId = docNodeRef.getId();
        o = cmisSession.getObject(objectId);
        assertEquals(objectId, stripCMISSuffix(o.getId()));
        objectId = folderNodeRef.getId();
        o = cmisSession.getObject(objectId);
        assertEquals(objectId, stripCMISSuffix(o.getId()));
    }
    // query
    {
        // searching by NodeRef, expect result objectIds to be Noderefs
        Set<String> expectedObjectIds = new HashSet<String>();
        expectedObjectIds.add(docNodeRef.toString());
        int numMatchingDocs = 0;
        // NodeRef input
        List<CMISNode> results = cmisSession.query("SELECT * FROM cmis:document WHERE IN_TREE('" + folderNodeRef.toString() + "')", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
        // searching by guid, expect result objectIds to be NodeRefs
        numMatchingDocs = 0;
        // node guid input
        results = cmisSession.query("SELECT * FROM cmis:document WHERE IN_TREE('" + folderNodeRef.getId() + "')", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            System.out.println("objectId = " + objectId);
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
    }
    // public api
    Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
    final TestNetwork network1 = networksIt.next();
    Iterator<String> personIt = network1.getPersonIds().iterator();
    final String person1Id = personIt.next();
    final List<NodeRef> folders1 = new ArrayList<NodeRef>();
    final List<NodeRef> documents1 = new ArrayList<NodeRef>();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            folders1.add(folderNodeRef);
            name = GUID.generate();
            NodeRef docNodeRef = repoService.createDocument(folderNodeRef, name, "test content");
            documents1.add(docNodeRef);
            return null;
        }
    }, person1Id, network1.getId());
    folderNodeRef = folders1.get(0);
    docNodeRef = documents1.get(0);
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    // test CMIS accepts NodeRefs and guids as input
    // objectIds returned from public api CMIS are always the guid
    {
        String nodeRefStr = docNodeRef.toString();
        CmisObject o = cmisSession.getObject(nodeRefStr);
        String objectId = docNodeRef.getId();
        assertEquals(objectId, stripCMISSuffix(o.getId()));
        nodeRefStr = folderNodeRef.toString();
        o = cmisSession.getObject(nodeRefStr);
        objectId = folderNodeRef.getId();
        assertEquals(objectId, stripCMISSuffix(o.getId()));
        o = cmisSession.getObject(objectId);
        assertEquals(objectId, stripCMISSuffix(o.getId()));
        objectId = folderNodeRef.getId();
        o = cmisSession.getObject(objectId);
        assertEquals(objectId, stripCMISSuffix(o.getId()));
    }
    // query
    {
        // searching by NodeRef, expect result objectIds to be objectId
        Set<String> expectedObjectIds = new HashSet<String>();
        expectedObjectIds.add(docNodeRef.getId());
        int numMatchingDocs = 0;
        // NodeRef input
        List<CMISNode> results = cmisSession.query("SELECT * FROM cmis:document WHERE IN_TREE('" + folderNodeRef.toString() + "')", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
        // searching by guid, expect result objectIds to be objectId
        numMatchingDocs = 0;
        // node guid input
        results = cmisSession.query("SELECT * FROM cmis:document WHERE IN_TREE('" + folderNodeRef.getId() + "')", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            System.out.println("objectId = " + objectId);
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
    }
}
Also used : CMISNode(org.alfresco.rest.api.tests.client.data.CMISNode) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) Repository(org.apache.chemistry.opencmis.client.api.Repository) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Category(org.junit.experimental.categories.Category) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 8 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class TestCMIS method testAppendContentStream.

@Test
public void testAppendContentStream() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    String name = "mydoc-" + GUID.generate() + ".txt";
    Map<String, String> properties = new HashMap<String, String>();
    {
        // create a document with 2 aspects
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    // append a few times
    for (int i = 0; i < 5; i++) {
        fileContent = new ContentStreamImpl();
        {
            ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
            writer.putContent("Ipsum and so on");
            ContentReader reader = writer.getReader();
            fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            fileContent.setStream(reader.getContentInputStream());
        }
        doc.appendContentStream(fileContent, false);
    }
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    doc.appendContentStream(fileContent, true);
    // check the appends
    String path = "/Sites/" + siteName + "/documentLibrary/" + name;
    Document doc1 = (Document) cmisSession.getObjectByPath(path);
    ContentStream contentStream = doc1.getContentStream();
    InputStream in = contentStream.getStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(in, writer, "UTF-8");
    String content = writer.toString();
    assertEquals("Ipsum and so onIpsum and so onIpsum and so onIpsum and so onIpsum and so onIpsum and so onIpsum and so on", content);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) StringWriter(java.io.StringWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 9 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class TestCMIS method testMNT12956QueryingCMIS11UsesDictionary11.

@Test
public void testMNT12956QueryingCMIS11UsesDictionary11() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = network1.createUser(personInfo);
    String personId = person.getId();
    final List<NodeRef> documents = new ArrayList<NodeRef>();
    final String filename = GUID.generate();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            NodeRef docNodeRef = repoService.createDocument(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), filename, "test content");
            documents.add(docNodeRef);
            return null;
        }
    }, personId, network1.getId());
    NodeRef docNodeRef = documents.get(0);
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
    CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    CmisSession atomCmisSession11 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    // query
    {
        // searching by NodeRef, expect result objectIds to be objectId
        Set<String> expectedObjectIds = new HashSet<String>();
        expectedObjectIds.add(docNodeRef.getId());
        int numMatchingDocs = 0;
        // NodeRef input
        List<CMISNode> results = atomCmisSession11.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
        assertEquals(expectedObjectIds.size(), results.size());
        for (CMISNode node : results) {
            String objectId = stripCMISSuffix((String) node.getProperties().get(PropertyIds.OBJECT_ID));
            if (expectedObjectIds.contains(objectId)) {
                numMatchingDocs++;
            }
        }
        assertEquals(expectedObjectIds.size(), numMatchingDocs);
        try {
            results = atomCmisSession10.query("SELECT cmis:objectId,cmis:name,cmis:secondaryObjectTypeIds FROM cmis:document WHERE cmis:name LIKE '" + filename + "'", false, 0, Integer.MAX_VALUE);
            fail("OpenCMIS 1.0 knows nothing about cmis:secondaryObjectTypeIds");
        } catch (CmisInvalidArgumentException expectedException) {
        // ok
        }
    }
}
Also used : CMISNode(org.alfresco.rest.api.tests.client.data.CMISNode) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) Set(java.util.Set) HashSet(java.util.HashSet) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ArrayList(java.util.ArrayList) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 10 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class TestCMIS method testAppendContentVersioning.

/* MNT-10175 test */
@Test
public void testAppendContentVersioning() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    // Use CMIS 1.1 to test content appending
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    String name = GUID.generate() + ".txt";
    Map<String, String> properties = new HashMap<String, String>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    // Create content to append
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    String versionLabel1 = doc.getObjectOfLatestVersion(false).getVersionLabel();
    // append a few times
    for (int i = 0; i < 5; i++) {
        doc.appendContentStream(fileContent, false);
    }
    String versionLabel2 = doc.getObjectOfLatestVersion(false).getVersionLabel();
    // Version label should not be incremented by appending with isLustChunk = false
    assertEquals(versionLabel1, versionLabel2);
    doc.appendContentStream(fileContent, true);
    String versionLabel3 = doc.getObjectOfLatestVersion(false).getVersionLabel();
    Integer majorVer1 = Integer.valueOf(versionLabel2.substring(0, 1));
    Integer majorVer2 = Integer.valueOf(versionLabel3.substring(0, 1));
    Integer minorVer1 = Integer.valueOf(versionLabel2.substring(2, 3));
    Integer minorVer2 = Integer.valueOf(versionLabel3.substring(2, 3));
    // Only one MINOR version should be created
    assertEquals(majorVer1, majorVer2);
    assertEquals(Integer.valueOf(minorVer1 + 1), minorVer2);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) BigInteger(java.math.BigInteger) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Aggregations

RequestContext (org.alfresco.rest.api.tests.client.RequestContext)185 Test (org.junit.Test)174 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)102 JSONObject (org.json.simple.JSONObject)67 HashMap (java.util.HashMap)58 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)52 ArrayList (java.util.ArrayList)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)45 Task (org.activiti.engine.task.Task)44 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)39 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)38 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)36 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)36 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)33 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)26 Person (org.alfresco.rest.api.tests.client.data.Person)25 JSONArray (org.json.simple.JSONArray)25 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)24 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)24 List (java.util.List)23