Search in sources :

Example 6 with People

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

the class TestNodeRatings method testNodeRatings.

@Test
public void testNodeRatings() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    assertTrue(networksIt.hasNext());
    final TestNetwork network1 = networksIt.next();
    assertTrue(networksIt.hasNext());
    final TestNetwork network2 = networksIt.next();
    final List<TestPerson> people = new ArrayList<TestPerson>(3);
    // create users
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network1.createUser();
            people.add(person);
            person = network1.createUser();
            people.add(person);
            return null;
        }
    }, network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network2.createUser();
            people.add(person);
            return null;
        }
    }, network2.getId());
    final TestPerson person11 = people.get(0);
    final TestPerson person12 = people.get(1);
    final TestPerson person21 = people.get(2);
    PublicApiClient.Sites sitesProxy = publicApiClient.sites();
    Comments commentsProxy = publicApiClient.comments();
    People peopleProxy = publicApiClient.people();
    Nodes nodesProxy = publicApiClient.nodes();
    DateFormat format = PublicApiDateFormat.getDateFormat();
    // Create site and document
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
    String siteId = "TESTSITE" + GUID.generate();
    Site site = new SiteImpl(siteId, siteId, siteId, SiteVisibility.PRIVATE.toString());
    site = sitesProxy.createSite(site);
    SiteContainer sc = sitesProxy.getSingleSiteContainer(site.getSiteId(), "documentLibrary");
    final String node1Id = createTextFile(sc.getId(), "Test Doc 1.txt", "Test Content").getId();
    // TEMP - pending remote api to list node ratings
    NodeRef nodeRef1 = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, node1Id);
    // try to add a rating to a comment
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        Comment comment = new Comment("Test Comment", "Test Comment");
        Comment newComment = commentsProxy.createNodeComment(node1Id, comment);
        NodeRating rating = new NodeRating("likes", true);
        nodesProxy.createNodeRating(newComment.getId(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // invalid node id
    try {
        NodeRating rating = new NodeRating("likes", true);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(GUID.generate(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // try to add a rating to a tag
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        Tag tag = new Tag("testTag");
        Tag newTag = nodesProxy.createNodeTag(node1Id, tag);
        NodeRating rating = new NodeRating("likes", true);
        nodesProxy.createNodeRating(newTag.getId(), rating);
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // invalid rating scheme
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("missingRatingScheme", Double.valueOf(1.0f)));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("likes", Double.valueOf(2.0f)));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", true));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // invalid rating - can't rate own content for fiveStar
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", 5));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
    }
    // valid ratings
    {
        NodeRating rating = new NodeRating("likes", true);
        Date time = new Date();
        // rate by multiple users in more than 1 network
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        NodeRating ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(1, null), ret.getAggregate());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        ret = nodesProxy.createNodeRating(node1Id, rating);
        assertEquals(rating.getMyRating(), ret.getMyRating());
        assertTrue(format.parse(ret.getRatedAt()).after(time));
        assertEquals(rating.getId(), ret.getId());
        assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
        // different network - unauthorized
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            nodesProxy.createNodeRating(node1Id, rating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        // Test Case cloud-2209
        // Test Case cloud-2220
        // Test Case cloud-1520
        // check that the node ratings are there, test paging
        {
            // person11
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            List<NodeRating> expectedRatings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
            {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = Integer.MAX_VALUE;
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = expectedRatings.size();
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
            // person12
            List<NodeRating> expectedRatings = repoService.getNodeRatings(person12.getId(), network1.getId(), nodeRef1);
            {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
            {
                int skipCount = 1;
                int maxItems = Integer.MAX_VALUE;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
            }
        }
        {
            // person21
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            List<NodeRating> expectedRatings = Collections.emptyList();
            try {
                int skipCount = 0;
                int maxItems = 1;
                Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
                nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
                fail();
            } catch (PublicApiException e) {
                assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
            }
        }
        // invalid node id
        try {
            int skipCount = 1;
            int maxItems = Integer.MAX_VALUE;
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(skipCount, maxItems);
            nodesProxy.getNodeRatings(GUID.generate(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // check activities have been raised for the created ratings
        repoService.generateFeed();
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(0, Integer.MAX_VALUE);
            ListResponse<Activity> activities = peopleProxy.getActivities(person11.getId(), createParams(paging, null));
            boolean found = false;
            for (Activity activity : activities.getList()) {
                String activityType = activity.getActivityType();
                if (activityType.equals(ActivityType.FILE_LIKED)) {
                    Map<String, Object> summary = activity.getSummary();
                    assertNotNull(summary);
                    String objectId = (String) summary.get("objectId");
                    assertNotNull(objectId);
                    if (node1Id.equals(objectId)) {
                        found = true;
                        break;
                    }
                }
            }
            assertTrue(found);
        }
    }
    {
        // remove node rating
        NodeRating rating = new NodeRating("likes", null);
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
            nodesProxy.removeNodeRating(node1Id, rating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
            nodesProxy.removeNodeRating(node1Id, rating);
        }
        // check list
        {
            List<NodeRating> ratings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            Paging paging = getPaging(skipCount, maxItems, ratings.size(), ratings.size());
            ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
            checkList(ratings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
    // get a node rating
    // 1977
    {
        NodeRating rating = new NodeRating("likes", true);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        NodeRating expected = nodesProxy.createNodeRating(node1Id, rating);
        NodeRating actual = nodesProxy.getNodeRating(node1Id, "likes");
        expected.expected(actual);
    }
    {
        // update node rating
        NodeRating rating = new NodeRating("fiveStar", 2);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
        // create initial rating
        NodeRating createdRating = nodesProxy.createNodeRating(node1Id, rating);
        NodeRating updateRating = new NodeRating(createdRating.getId(), 5);
        // update - not supported
        try {
            nodesProxy.updateNodeRating(node1Id, updateRating);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
    }
    // Test Case cloud-1977
    // invalid methods
    {
        try {
            // -ve test - cannot create multiple ratings in single POST call (unsupported)
            List<NodeRating> ratings = new ArrayList<>(2);
            ratings.add(new NodeRating("likes", true));
            ratings.add(new NodeRating("likes", false));
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.create("nodes", node1Id, "ratings", null, JSONArray.toJSONString(ratings), "Unable to POST to multiple ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        // get an arbitrary rating
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(getPaging(0, Integer.MAX_VALUE), null));
        List<NodeRating> nodeRatings = resp.getList();
        assertTrue(nodeRatings.size() > 0);
        try {
            NodeRating rating = new NodeRating("likes", true);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.create("nodes", node1Id, "ratings", "likes", rating.toJSON().toString(), "Unable to POST to a node rating");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.update("nodes", node1Id, "ratings", null, null, "Unable to PUT node ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.remove("nodes", node1Id, "ratings", null, "Unable to DELETE node ratings");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
        try {
            NodeRating rating = nodeRatings.get(0);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
            nodesProxy.update("nodes", node1Id, "ratings", rating.getId(), null, "Unable to PUT a node rating");
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
        }
    }
    // Test case ACE-5453
    {
        try {
            testSkipCountLargeValue(person11, network1, nodeRef1, nodesProxy);
        } catch (PublicApiException e) {
            fail();
        }
    }
}
Also used : TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Site(org.alfresco.rest.api.tests.client.data.Site) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.tests.client.data.Activity) NodeRating(org.alfresco.rest.api.tests.client.data.NodeRating) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Comment(org.alfresco.rest.api.tests.client.data.Comment) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Nodes(org.alfresco.rest.api.tests.client.PublicApiClient.Nodes) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) SiteImpl(org.alfresco.rest.api.tests.client.data.SiteImpl) DateFormat(java.text.DateFormat) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) PublicApiClient(org.alfresco.rest.api.tests.client.PublicApiClient) Tag(org.alfresco.rest.api.tests.client.data.Tag) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) SiteContainer(org.alfresco.rest.api.tests.client.data.SiteContainer) Test(org.junit.Test)

Example 7 with People

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

the class TestUserPreferences method testUserPreferences.

@Test
public void testUserPreferences() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    assertTrue(networksIt.hasNext());
    final TestNetwork network1 = networksIt.next();
    assertTrue(networksIt.hasNext());
    final TestNetwork network2 = networksIt.next();
    final List<TestPerson> people = new ArrayList<TestPerson>(3);
    // create users and some preferences
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network1.createUser();
            people.add(person);
            person = network1.createUser();
            people.add(person);
            return null;
        }
    }, network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network2.createUser();
            people.add(person);
            return null;
        }
    }, network2.getId());
    final TestPerson person1 = people.get(0);
    final TestPerson person2 = people.get(1);
    final TestPerson person3 = people.get(2);
    final List<Preference> expectedPreferences = new ArrayList<Preference>();
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
    // new preference name for issue REPO-855
    expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            for (Preference pref : expectedPreferences) {
                // TODO add preferences thru api
                repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
            }
            return null;
        }
    }, person1.getId(), network1.getId());
    Collections.sort(expectedPreferences);
    People peopleProxy = publicApiClient.people();
    // unknown user
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // test paging
    {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    {
        int skipCount = 2;
        int maxItems = 10;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // invalid user - 404
    try {
        int skipCount = 2;
        int maxItems = 10;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences("invalid.user", createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // user from another account - 401
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        // ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        // checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
    }
    // another user from the same account - 403
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
    }
    // get a single preference
    // Test Case: cloud-1493
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Preference pref = expectedPreferences.get(0);
        Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
        pref.expected(ret);
    }
    // unknown person id
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        peopleProxy.getPreference(GUID.generate(), pref.getId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // unknown preference id
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.getPreference(person1.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // Test case: cloud-1968
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.update("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to PUT a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    {
        // REPO-1061, REPO-890
        try {
            String skipCount = "a";
            String maxItems = "hi";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "a";
            String maxItems = "null";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String maxItems = "Red";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "yuck";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "-1";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String maxItems = "0";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Preference(org.alfresco.rest.api.tests.client.data.Preference) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Test(org.junit.Test)

Aggregations

People (org.alfresco.rest.api.tests.client.PublicApiClient.People)7 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)7 Test (org.junit.Test)7 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)6 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)6 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)4 Activity (org.alfresco.rest.api.tests.client.data.Activity)4 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)3 DateFormat (java.text.DateFormat)2 Date (java.util.Date)2 Map (java.util.Map)2 Comments (org.alfresco.rest.api.tests.client.PublicApiClient.Comments)2 Nodes (org.alfresco.rest.api.tests.client.PublicApiClient.Nodes)2 Comment (org.alfresco.rest.api.tests.client.data.Comment)2 Tag (org.alfresco.rest.api.tests.client.data.Tag)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1