Search in sources :

Example 1 with CmisSession

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

the class TestCMIS method testMNT_10161.

/* MNT-10161 related test - mapping of cmis:description for CMIS 1.1 */
@Test
public void testMNT_10161() 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();
    final String nodeDescription = "Test description";
    final String nodeName = GUID.generate();
    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);
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef(DOCUMENT_LIBRARY_CONTAINER_NAME), nodeName);
            /* create node with property description */
            return repoService.createDocument(folderNodeRef, nodeName, "title", nodeDescription, "content");
        }
    }, person1Id, network1.getId());
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Document doc = (Document) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary/" + nodeName + "/" + nodeName);
    /* ensure we got the node */
    assertNotNull(doc);
    /* get mapped cmis:description */
    Property<?> descrProperty = doc.getProperty(PropertyIds.DESCRIPTION);
    /* ensure that cmis:description is set properly */
    assertTrue(nodeDescription.equals(descrProperty.getValue()));
}
Also used : CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) 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 2 with CmisSession

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

the class TestCMIS method testContentDisposition_MNT_17477.

@Test
public void testContentDisposition_MNT_17477() 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();
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.browser, CMIS_VERSION_11, AlfrescoObjectFactoryImpl.class.getName());
    Folder folder = (Folder) cmisSession.getObjectByPath("/Shared");
    // 
    // Upload test JPG document
    // 
    String name = GUID.generate() + ".jpg";
    Map<String, Object> properties = new HashMap<>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        fileContent.setMimeType(MimetypeMap.MIMETYPE_IMAGE_JPEG);
        fileContent.setStream(this.getClass().getResourceAsStream("/test.jpg"));
    }
    Document doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
    String docId = doc.getId();
    // note: Content-Disposition can be "inline or "attachment" for content types that are white-listed (eg. specific image types & pdf)
    HttpResponse response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("inline"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=attachment", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
    // note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment"));
    // 
    // Create test HTML document
    // 
    name = GUID.generate() + ".html";
    properties = new HashMap<>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".html"));
        writer.putContent("<html><script>alert(123);</script><body>Hello <b>world</b></body</html>");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_HTML);
        fileContent.setStream(reader.getContentInputStream());
    }
    doc = folder.createDocument(properties, fileContent, VersioningState.MAJOR);
    docId = doc.getId();
    // note: Content-Disposition will always be "attachment" for content types that are not white-listed
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/browser/root/Shared/" + name + "?download=inline", null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
    // note: AtomPub binding (via OpenCMIS) does not support "download" query parameter
    response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content?id=" + docId, null);
    assertEquals(200, response.getStatusCode());
    assertTrue(response.getHeaders().get("Content-Disposition").startsWith("attachment;"));
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) 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) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) 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 3 with CmisSession

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

the class TestCMIS method testMnt11631.

@Test
public void testMnt11631() throws Exception {
    final TestNetwork network = getTestFixture().getRandomNetwork();
    String username = String.format(TEST_USER_NAME_PATTERN, System.currentTimeMillis());
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person = network.createUser(personInfo);
    String personId = person.getId();
    final String siteName = String.format(TEST_SITE_NAME_PATTERN, 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;
        }
    }, personId, network.getId());
    publicApiClient.setRequestContext(new RequestContext(network.getId(), personId));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath(String.format(DOCUMENT_LIBRARY_PATH_PATTERN, siteName));
    String name = String.format(TEST_DOCUMENT_NAME_PATTERN, GUID.generate());
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
    properties.put(PropertyIds.NAME, name);
    ContentStreamImpl fileContent = new ContentStreamImpl();
    ByteArrayInputStream stream = new ByteArrayInputStream(GUID.generate().getBytes());
    fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    fileContent.setStream(stream);
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    ObjectId pwcId = doc.checkOut();
    Document pwc = (Document) cmisSession.getObject(pwcId.getId());
    assertIsPwcProperty(pwc, false);
    cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10);
    CmisObject pwc10 = cmisSession.getObject(pwc.getId());
    assertIsPwcProperty(pwc10, true);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) 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 4 with CmisSession

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

the class TestCMIS method testGetXmlWithCorrectCurrencySymbols.

/**
 * 1) Creating a file with currency symbols in the name, title and description (MNT-15044)
 * 2) Get the document with correct chars in the properties.
 * @throws Exception
 */
@Test
public void testGetXmlWithCorrectCurrencySymbols() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    NodeRef fileNode = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            final TestSite site = network1.createSite(siteInfo);
            NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Euro \u20AC Pound \u00A3 Franc \u20A3.txt", "Euro \u20AC Pound \u00A3 Franc \u20A3 File", "\u20A3 \u00A3 \u20A3", "\u20A3 \u00A3 \u20A3");
            return resNode;
        }
    }, person1Id, network1.getId());
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession atomCmisSession10 = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    String objectId = fileNode.getId();
    Document doc = (Document) atomCmisSession10.getObject(objectId);
    String name = (String) doc.getProperty(PropertyIds.NAME).getFirstValue();
    String title = (String) doc.getProperty("cm:title").getFirstValue();
    String description = (String) doc.getProperty("cm:description").getFirstValue();
    assertEquals("Euro \u20AC Pound \u00A3 Franc \u20A3.txt", name);
    assertEquals("Euro \u20AC Pound \u00A3 Franc \u20A3 File", title);
    assertEquals("\u20A3 \u00A3 \u20A3", description);
}
Also used : AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) 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 5 with CmisSession

use of org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession 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)

Aggregations

VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)23 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)23 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)23 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)23 Test (org.junit.Test)23 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)20 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)20 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)20 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)19 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)19 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)18 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)18 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)18 HashMap (java.util.HashMap)16 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)15 Document (org.apache.chemistry.opencmis.client.api.Document)15 ContentStreamImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl)15