Search in sources :

Example 16 with Person

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

the class QueriesPeopleApiTest method checkApiCall.

private void checkApiCall(String term, String orderBy, String fields, Paging paging, int expectedStatus, List<String> expectedPeople, int... userIds) throws Exception {
    createParamIdNotNull(Queries.PARAM_TERM, term);
    createParamIdNotNull(Queries.PARAM_ORDERBY, orderBy);
    createParamIdNotNull(Queries.PARAM_FIELDS, fields);
    dummySearchServiceQueryNodeRefs.clear();
    for (int i : userIds) {
        NodeRef nodeRef = testPersonNodeRefs.get(i);
        dummySearchServiceQueryNodeRefs.add(nodeRef);
    }
    response = getAll(URL_QUERIES_LSP, paging, params, expectedStatus);
    if (expectedStatus == 200) {
        String termWithEscapedAsterisks = term.replaceAll("\\*", "\\\\*");
        String expectedQuery = "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (\"*" + termWithEscapedAsterisks + "*\")";
        ArgumentCaptor<SearchParameters> searchParametersCaptor = ArgumentCaptor.forClass(SearchParameters.class);
        verify(mockSearchService, times(++callCountToMockSearchService)).query(searchParametersCaptor.capture());
        SearchParameters parameters = searchParametersCaptor.getValue();
        assertEquals("Query", expectedQuery, parameters.getQuery());
        people = Person.parsePeople(response.getJsonResponse()).getList();
        if (!expectedPeople.isEmpty()) {
            StringJoiner actual = new StringJoiner("\n");
            StringJoiner expected = new StringJoiner("\n");
            for (String people : expectedPeople) {
                expected.add(people);
            }
            for (Person person : people) {
                actual.add(person.toString());
            }
            String exp = expected.toString().replaceAll(TEST_TERM_PREFIX, "");
            String act = actual.toString().replaceAll(TEST_TERM_PREFIX, "");
            assertEquals(exp, act);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Person(org.alfresco.rest.api.tests.client.data.Person) StringJoiner(java.util.StringJoiner)

Example 17 with Person

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

the class TestCMIS method testCMIS.

/**
 * Tests OpenCMIS api.
 */
@SuppressWarnings("unchecked")
@Test
public void testCMIS() throws Exception {
    // Test Case cloud-2353
    // Test Case cloud-2354
    // Test Case cloud-2356
    // Test Case cloud-2378
    // Test Case cloud-2357
    // Test Case cloud-2358
    // Test Case cloud-2360
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    Iterator<String> personIt = network1.getPersonIds().iterator();
    final String personId = personIt.next();
    assertNotNull(personId);
    Person person = repoService.getPerson(personId);
    assertNotNull(person);
    // Create a site
    final TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

        @Override
        public TestSite doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = network1.createSite(siteInfo);
            return site;
        }
    }, personId, network1.getId());
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    Nodes nodesProxy = publicApiClient.nodes();
    Comments commentsProxy = publicApiClient.comments();
    String expectedContent = "Ipsum and so on";
    Document doc = null;
    Folder documentLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary");
    FolderNode expectedDocumentLibrary = (FolderNode) CMISNode.createNode(documentLibrary);
    Document testDoc = null;
    Folder testFolder = null;
    FolderNode testFolderNode = null;
    // create some sub-folders and documents
    {
        for (int i = 0; i < 3; i++) {
            Map<String, String> properties = new HashMap<String, String>();
            {
                properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
                properties.put(PropertyIds.NAME, "folder-" + i);
            }
            Folder f = documentLibrary.createFolder(properties);
            FolderNode fn = (FolderNode) CMISNode.createNode(f);
            if (testFolder == null) {
                testFolder = f;
                testFolderNode = fn;
            }
            expectedDocumentLibrary.addFolder(fn);
            for (int k = 0; k < 3; k++) {
                properties = new HashMap<String, String>();
                {
                    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
                    properties.put(PropertyIds.NAME, "folder-" + k);
                }
                Folder f1 = f.createFolder(properties);
                FolderNode childFolder = (FolderNode) CMISNode.createNode(f1);
                fn.addFolder(childFolder);
            }
            for (int j = 0; j < 3; j++) {
                properties = new HashMap<String, String>();
                {
                    properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
                    properties.put(PropertyIds.NAME, "doc-" + j);
                }
                ContentStreamImpl fileContent = new ContentStreamImpl();
                {
                    ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
                    writer.putContent(expectedContent);
                    ContentReader reader = writer.getReader();
                    fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                    fileContent.setStream(reader.getContentInputStream());
                }
                Document d = f.createDocument(properties, fileContent, VersioningState.MAJOR);
                if (testDoc == null) {
                    testDoc = d;
                }
                CMISNode childDocument = CMISNode.createNode(d);
                fn.addNode(childDocument);
            }
        }
        for (int i = 0; i < 10; i++) {
            Map<String, String> properties = new HashMap<String, String>();
            {
                properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
                properties.put(PropertyIds.NAME, "doc-" + i);
            }
            ContentStreamImpl fileContent = new ContentStreamImpl();
            {
                ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
                writer.putContent(expectedContent);
                ContentReader reader = writer.getReader();
                fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                fileContent.setStream(reader.getContentInputStream());
            }
            documentLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
        }
    }
    // try to add and remove ratings, comments, tags to folders created by CMIS
    {
        Aggregate aggregate = new Aggregate(1, null);
        NodeRating expectedNodeRating = new NodeRating("likes", true, aggregate);
        Comment expectedComment = new Comment("commenty", "commenty", false, null, person, person);
        Tag expectedTag = new Tag("taggy");
        NodeRating rating = nodesProxy.createNodeRating(testFolder.getId(), expectedNodeRating);
        expectedNodeRating.expected(rating);
        assertNotNull(rating.getId());
        // REPO-2028 - remove lucene tests
        // Tag tag = nodesProxy.createNodeTag(testFolder.getId(), expectedTag);
        // expectedTag.expected(tag);
        // assertNotNull(tag.getId());
        Comment comment = commentsProxy.createNodeComment(testFolder.getId(), expectedComment);
        expectedComment.expected(comment);
        assertNotNull(comment.getId());
    }
    // try to add and remove ratings, comments, tags to documents created by CMIS
    {
        Aggregate aggregate = new Aggregate(1, null);
        NodeRating expectedNodeRating = new NodeRating("likes", true, aggregate);
        Comment expectedComment = new Comment("commenty", "commenty", false, null, person, person);
        Tag expectedTag = new Tag("taggy");
        NodeRating rating = nodesProxy.createNodeRating(testDoc.getId(), expectedNodeRating);
        expectedNodeRating.expected(rating);
        assertNotNull(rating.getId());
        // REPO-2028 - remove lucene tests
        // Tag tag = nodesProxy.createNodeTag(testDoc.getId(), expectedTag);
        // expectedTag.expected(tag);
        // assertNotNull(tag.getId());
        Comment comment = commentsProxy.createNodeComment(testDoc.getId(), expectedComment);
        expectedComment.expected(comment);
        assertNotNull(comment.getId());
    }
    // descendants
    {
        List<Tree<FileableCmisObject>> descendants = documentLibrary.getDescendants(4);
        expectedDocumentLibrary.checkDescendants(descendants);
    }
    // upload/setContent
    {
        Map<String, String> fileProps = new HashMap<String, String>();
        {
            fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
            fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
        }
        ContentStreamImpl fileContent = new ContentStreamImpl();
        {
            ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
            writer.putContent(expectedContent);
            ContentReader reader = writer.getReader();
            fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            fileContent.setStream(reader.getContentInputStream());
        }
        doc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
        String nodeId = stripCMISSuffix(doc.getId());
        final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
        ContentReader reader = TenantUtil.runAsUserTenant(new TenantRunAsWork<ContentReader>() {

            @Override
            public ContentReader doWork() throws Exception {
                ContentReader reader = repoService.getContent(nodeRef, ContentModel.PROP_CONTENT);
                return reader;
            }
        }, personId, network1.getId());
        String actualContent = reader.getContentString();
        assertEquals(expectedContent, actualContent);
    }
    // get content
    {
        ContentStream stream = doc.getContentStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(stream.getStream(), writer, "UTF-8");
        String actualContent = writer.toString();
        assertEquals(expectedContent, actualContent);
    }
    // get children
    {
        Folder folder = (Folder) cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary/" + testFolder.getName());
        ItemIterable<CmisObject> children = folder.getChildren();
        testFolderNode.checkChildren(children);
    }
    // REPO-2028 - remove lucene tests
    // query
    // {
    // Folder folder = (Folder)cmisSession.getObjectByPath("/Sites/" + site.getSiteId() + "/documentLibrary/" + testFolder.getName());
    // String folderId = folder.getId();
    // 
    // Set<String> expectedFolderNames = new HashSet<String>();
    // for(CMISNode n : testFolderNode.getFolderNodes().values())
    // {
    // expectedFolderNames.add((String)n.getProperty("cmis:name"));
    // }
    // int expectedNumFolders = expectedFolderNames.size();
    // int numMatchingFoldersFound = 0;
    // List<CMISNode> results = cmisSession.query("SELECT * FROM cmis:folder WHERE IN_TREE('" + folderId + "')", false, 0, Integer.MAX_VALUE);
    // for(CMISNode node : results)
    // {
    // String name = (String)node.getProperties().get("cmis:name");
    // if(expectedFolderNames.contains(name))
    // {
    // numMatchingFoldersFound++;
    // }
    // }
    // assertEquals(expectedNumFolders, numMatchingFoldersFound);
    // 
    // Set<String> expectedDocNames = new HashSet<String>();
    // for(CMISNode n : testFolderNode.getDocumentNodes().values())
    // {
    // expectedDocNames.add((String)n.getProperty("cmis:name"));
    // }
    // int expectedNumDocs = expectedDocNames.size();
    // int numMatchingDocsFound = 0;
    // results = cmisSession.query("SELECT * FROM cmis:document where IN_TREE('" + folderId + "')", false, 0, Integer.MAX_VALUE);
    // for(CMISNode node : results)
    // {
    // String name = (String)node.getProperties().get("cmis:name");
    // if(expectedDocNames.contains(name))
    // {
    // numMatchingDocsFound++;
    // }
    // }
    // assertEquals(expectedNumDocs, numMatchingDocsFound);
    // }
    // versioning
    {
        String nodeId = stripCMISSuffix(doc.getId());
        final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
        // checkout
        ObjectId pwcId = doc.checkOut();
        Document pwc = (Document) cmisSession.getObject(pwcId.getId());
        Boolean isCheckedOut = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {

            @Override
            public Boolean doWork() throws Exception {
                Boolean isCheckedOut = repoService.isCheckedOut(nodeRef);
                return isCheckedOut;
            }
        }, personId, network1.getId());
        assertTrue(isCheckedOut);
        // checkin with new content
        expectedContent = "Big bad wolf";
        ContentStreamImpl fileContent = new ContentStreamImpl();
        {
            ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
            writer.putContent(expectedContent);
            ContentReader reader = writer.getReader();
            fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            fileContent.setStream(reader.getContentInputStream());
        }
        ObjectId checkinId = pwc.checkIn(true, Collections.EMPTY_MAP, fileContent, "checkin 1");
        doc = (Document) cmisSession.getObject(checkinId.getId());
        isCheckedOut = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {

            @Override
            public Boolean doWork() throws Exception {
                Boolean isCheckedOut = repoService.isCheckedOut(nodeRef);
                return isCheckedOut;
            }
        }, personId, network1.getId());
        assertFalse(isCheckedOut);
        // check that the content has been updated
        ContentStream stream = doc.getContentStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(stream.getStream(), writer, "UTF-8");
        String actualContent = writer.toString();
        assertEquals(expectedContent, actualContent);
        List<Document> allVersions = doc.getAllVersions();
        assertEquals(2, allVersions.size());
        assertEquals("2.0", allVersions.get(0).getVersionLabel());
        assertEquals(CMIS_VERSION_10, allVersions.get(1).getVersionLabel());
    }
    {
        // https://issues.alfresco.com/jira/browse/PUBLICAPI-95
        // Test that documents are created with autoVersion=true
        Map<String, String> fileProps = new HashMap<String, String>();
        {
            fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
            fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
        }
        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());
        }
        {
            // a versioned document
            Document autoVersionedDoc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
            String objectId = autoVersionedDoc.getId();
            String bareObjectId = stripCMISSuffix(objectId);
            final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, bareObjectId);
            Boolean autoVersion = TenantUtil.runAsUserTenant(new TenantRunAsWork<Boolean>() {

                @Override
                public Boolean doWork() throws Exception {
                    Boolean autoVersion = (Boolean) repoService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION);
                    return autoVersion;
                }
            }, personId, network1.getId());
            assertEquals(Boolean.TRUE, autoVersion);
        }
        // https://issues.alfresco.com/jira/browse/PUBLICAPI-92
        // Test that a get on an objectId without a version suffix returns the current version of the document
        {
            // do a few checkout, checkin cycles to create some versions
            fileProps = new HashMap<String, String>();
            {
                fileProps.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
                fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
            }
            Document autoVersionedDoc = documentLibrary.createDocument(fileProps, fileContent, VersioningState.MAJOR);
            String objectId = autoVersionedDoc.getId();
            String bareObjectId = stripCMISSuffix(objectId);
            for (int i = 0; i < 3; i++) {
                Document doc1 = (Document) cmisSession.getObject(bareObjectId);
                ObjectId pwcId = doc1.checkOut();
                Document pwc = (Document) cmisSession.getObject(pwcId.getId());
                ContentStreamImpl contentStream = new ContentStreamImpl();
                {
                    ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
                    expectedContent = GUID.generate();
                    writer.putContent(expectedContent);
                    ContentReader reader = writer.getReader();
                    contentStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
                    contentStream.setStream(reader.getContentInputStream());
                }
                pwc.checkIn(true, Collections.EMPTY_MAP, contentStream, "checkin " + i);
            }
            // get the object, supplying an objectId without a version suffix
            Document doc1 = (Document) cmisSession.getObject(bareObjectId);
            String versionLabel = doc1.getVersionLabel();
            ContentStream cs = doc1.getContentStream();
            String content = IOUtils.toString(cs.getStream());
            assertEquals("4.0", versionLabel);
            assertEquals(expectedContent, content);
        }
    }
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) CMISNode(org.alfresco.rest.api.tests.client.data.CMISNode) FolderNode(org.alfresco.rest.api.tests.client.data.FolderNode) HashMap(java.util.HashMap) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) NodeRating(org.alfresco.rest.api.tests.client.data.NodeRating) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) StringWriter(java.io.StringWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) Comment(org.alfresco.rest.api.tests.client.data.Comment) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) 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) Nodes(org.alfresco.rest.api.tests.client.PublicApiClient.Nodes) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) ItemIterable(org.apache.chemistry.opencmis.client.api.ItemIterable) Tag(org.alfresco.rest.api.tests.client.data.Tag) Aggregate(org.alfresco.rest.api.tests.client.data.NodeRating.Aggregate) Person(org.alfresco.rest.api.tests.client.data.Person) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 18 with Person

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

the class TestNetworks method testCLOUD1856.

/*
	 * CLOUD-1856: test that a network id of the form "cmis*" works
	 */
@Test
public void testCLOUD1856() throws Exception {
    People peopleProxy = publicApiClient.people();
    publicApiClient.setRequestContext(new RequestContext(network3.getId(), person31.getId()));
    Person ret = peopleProxy.getPerson(person31.getId());
    person31.expected(ret);
}
Also used : People(org.alfresco.rest.api.tests.client.PublicApiClient.People) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 19 with Person

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

the class TestPeople method testUpdatePersonUpdateAsAdmin.

@Test
public void testUpdatePersonUpdateAsAdmin() throws Exception {
    final String personId = account3.createUser().getId();
    publicApiClient.setRequestContext(new RequestContext(account3.getId(), account3Admin, "admin"));
    String firstName = "updatedFirstName";
    String lastName = "updatedLastName";
    String description = "updatedDescription";
    String email = "updated@example.com";
    String skypeId = "updated.skype.id";
    String googleId = "googleId";
    String instantMessageId = "updated.user@example.com";
    String jobTitle = "updatedJobTitle";
    String location = "updatedLocation";
    Company company = new Company("updatedOrganization", "updatedAddress1", "updatedAddress2", "updatedAddress3", "updatedPostcode", "updatedTelephone", "updatedFax", "updatedEmail");
    String mobile = "mobile";
    String telephone = "telephone";
    String userStatus = "userStatus";
    Boolean enabled = true;
    Boolean emailNotificationsEnabled = false;
    Map<String, String> params = new HashMap<>();
    params.put("fields", "id,firstName,lastName,description,avatarId,email,skypeId,googleId,instantMessageId,jobTitle,location,mobile,telephone,userStatus,emailNotificationsEnabled,enabled,company");
    HttpResponse response = people.update("people", personId, null, null, "{\n" + "  \"firstName\": \"" + firstName + "\",\n" + "  \"lastName\": \"" + lastName + "\",\n" + "  \"description\": \"" + description + "\",\n" + "  \"email\": \"" + email + "\",\n" + "  \"skypeId\": \"" + skypeId + "\",\n" + "  \"googleId\": \"" + googleId + "\",\n" + "  \"instantMessageId\": \"" + instantMessageId + "\",\n" + "  \"jobTitle\": \"" + jobTitle + "\",\n" + "  \"location\": \"" + location + "\",\n" + "  \"company\": {\n" + "    \"organization\": \"" + company.getOrganization() + "\",\n" + "    \"address1\": \"" + company.getAddress1() + "\",\n" + "    \"address2\": \"" + company.getAddress2() + "\",\n" + "    \"address3\": \"" + company.getAddress3() + "\",\n" + "    \"postcode\": \"" + company.getPostcode() + "\",\n" + "    \"telephone\": \"" + company.getTelephone() + "\",\n" + "    \"fax\": \"" + company.getFax() + "\",\n" + "    \"email\": \"" + company.getEmail() + "\"\n" + "  },\n" + "  \"mobile\": \"" + mobile + "\",\n" + "  \"telephone\": \"" + telephone + "\",\n" + "  \"userStatus\": \"" + userStatus + "\",\n" + "  \"emailNotificationsEnabled\": \"" + emailNotificationsEnabled + "\",\n" + "  \"enabled\": \"" + enabled + "\"\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    Person updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getId());
    assertEquals(firstName, updatedPerson.getFirstName());
    assertEquals(lastName, updatedPerson.getLastName());
    assertEquals(description, updatedPerson.getDescription());
    assertEquals(email, updatedPerson.getEmail());
    assertEquals(skypeId, updatedPerson.getSkypeId());
    assertEquals(googleId, updatedPerson.getGoogleId());
    assertEquals(instantMessageId, updatedPerson.getInstantMessageId());
    assertEquals(jobTitle, updatedPerson.getJobTitle());
    assertEquals(location, updatedPerson.getLocation());
    assertNotNull(updatedPerson.getCompany());
    company.expected(updatedPerson.getCompany());
    assertEquals(mobile, updatedPerson.getMobile());
    assertEquals(telephone, updatedPerson.getTelephone());
    assertEquals(userStatus, updatedPerson.getUserStatus());
    assertEquals(emailNotificationsEnabled, updatedPerson.isEmailNotificationsEnabled());
    assertEquals(enabled, updatedPerson.isEnabled());
    // test ability to unset optional fields (could be one or more - here all) including individual company fields
    response = people.update("people", personId, null, null, "{\n" + "  \"lastName\":null,\n" + "  \"description\":null,\n" + "  \"skypeId\":null,\n" + "  \"googleId\":null,\n" + "  \"instantMessageId\":null,\n" + "  \"jobTitle\":null,\n" + "  \"location\":null,\n" + "  \"company\": {\n" + "    \"address1\":null,\n" + "    \"address2\":null,\n" + "    \"address3\":null,\n" + "    \"postcode\":null,\n" + "    \"telephone\":null,\n" + "    \"fax\":null,\n" + "    \"email\":null\n" + "  },\n" + "  \"mobile\":null,\n" + "  \"telephone\":null,\n" + "  \"userStatus\":null\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getId());
    assertNull(updatedPerson.getLastName());
    assertNull(updatedPerson.getDescription());
    assertNull(updatedPerson.getSkypeId());
    assertNull(updatedPerson.getGoogleId());
    assertNull(updatedPerson.getInstantMessageId());
    assertNull(updatedPerson.getJobTitle());
    assertNull(updatedPerson.getLocation());
    assertNotNull(updatedPerson.getCompany());
    assertNotNull(updatedPerson.getCompany().getOrganization());
    assertNull(updatedPerson.getCompany().getAddress1());
    assertNull(updatedPerson.getCompany().getAddress2());
    assertNull(updatedPerson.getCompany().getAddress3());
    assertNull(updatedPerson.getCompany().getPostcode());
    assertNull(updatedPerson.getCompany().getFax());
    assertNull(updatedPerson.getCompany().getEmail());
    assertNull(updatedPerson.getCompany().getTelephone());
    assertNull(updatedPerson.getMobile());
    assertNull(updatedPerson.getTelephone());
    assertNull(updatedPerson.getUserStatus());
    // test ability to unset company fields as a whole
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": {} \n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    // note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
    assertNotNull(updatedPerson.getCompany());
    assertNull(updatedPerson.getCompany().getOrganization());
    // set at least one company field
    String updatedOrgName = "another org";
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": {\n" + "    \"organization\":\"" + updatedOrgName + "\"\n" + "  }\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    assertNotNull(updatedPerson.getCompany());
    assertEquals(updatedOrgName, updatedPerson.getCompany().getOrganization());
    // test ability to unset company fields as a whole
    response = people.update("people", personId, null, null, "{\n" + "  \"company\": null\n" + "}", params, "Expected 200 response when updating " + personId, 200);
    updatedPerson = Person.parsePerson((JSONObject) response.getJsonResponse().get("entry"));
    // note: empty company object is returned for backwards compatibility (with pre-existing getPerson API <= 5.1)
    assertNotNull(updatedPerson.getCompany());
    assertNull(updatedPerson.getCompany().getOrganization());
}
Also used : Company(org.alfresco.rest.api.tests.client.data.Company) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) Test(org.junit.Test)

Example 20 with Person

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

the class TestPeople method testPagingAndSortingByIdDesc.

/**
 * Tests the capability to sort and paginate the list of people orderBy =
 * username DESC skip = 1, count = 3
 *
 * @throws Exception
 */
@Test
public void testPagingAndSortingByIdDesc() throws Exception {
    publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
    // paging
    int skipCount = 1;
    int maxItems = 3;
    int totalResults = 5;
    PublicApiClient.Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
    // orderBy=userName DESC
    PublicApiClient.ListResponse<Person> resp = listPeople(paging, "id", false, 200);
    List<Person> expectedList = new LinkedList<>();
    expectedList.add((Person) personBen);
    expectedList.add((Person) personAliceD);
    expectedList.add((Person) personAlice);
    checkList(expectedList, paging.getExpectedPaging(), resp);
}
Also used : PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Person(org.alfresco.rest.api.tests.client.data.Person) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Person (org.alfresco.rest.api.tests.client.data.Person)30 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)25 Test (org.junit.Test)24 PublicApiClient (org.alfresco.rest.api.tests.client.PublicApiClient)10 HashMap (java.util.HashMap)9 LinkedList (java.util.LinkedList)8 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 ArrayList (java.util.ArrayList)6 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)6 JSONObject (org.json.simple.JSONObject)6 Map (java.util.Map)5 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)5 Serializable (java.io.Serializable)4 List (java.util.List)4 Company (org.alfresco.rest.api.tests.client.data.Company)4 QName (org.alfresco.service.namespace.QName)4 Date (java.util.Date)3 Iterator (java.util.Iterator)3 MimeMessage (javax.mail.internet.MimeMessage)3