Search in sources :

Example 36 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestNodeComments method testNodeCommentsAndLocking.

@Test
public void testNodeCommentsAndLocking() throws Exception {
    Comments commentsProxy = publicApiClient.comments();
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                TestSite site = sites.get(0);
                site.updateMember(person13.getId(), SiteRole.SiteManager);
                site.updateMember(person14.getId(), SiteRole.SiteManager);
                return null;
            }
        }, person11.getId(), network1.getId());
        Comment comment = new Comment();
        comment.setContent("my comment");
        Comment createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                repoService.lockNode(nodeRef1);
                return null;
            }
        }, person13.getId(), network1.getId());
        // change to not lock owner and not node owner
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14.getId()));
        // test GET for a locked node
        int skipCount = 0;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems);
        commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null));
        // test POST for a locked node
        try {
            comment = new Comment();
            comment.setContent("my other comment");
            createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // test PUT for a locked node
        try {
            Comment updatedComment = new Comment();
            updatedComment.setContent("my comment");
            commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // test DELETE for a locked node
        try {
            commentsProxy.removeNodeComment(nodeRef1.getId(), createdComment.getId());
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // change to node creator
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        // test POST for a locked node
        try {
            comment = new Comment();
            comment.setContent("my other comment");
            createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // test PUT for a locked node
        try {
            Comment updatedComment = new Comment();
            updatedComment.setContent("my comment");
            commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment);
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // test DELETE for a locked node
        try {
            commentsProxy.removeNodeComment(nodeRef1.getId(), createdComment.getId());
            fail("");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode());
        }
        // change to lock owner
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId()));
        // test GET for a locked node
        commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null));
        // test POST for a locked node
        comment = new Comment();
        comment.setContent("my other comment");
        createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment);
        // test PUT for a locked node
        Comment updatedComment = new Comment();
        updatedComment.setContent("my comment");
        commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment);
        // test DELETE for a locked node
        commentsProxy.removeNodeComment(nodeRef1.getId(), createdComment.getId());
    } finally {
        // undo the lock
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                repoService.unlockNode(nodeRef1);
                return null;
            }
        }, person13.getId(), network1.getId());
        // put the other members back to SiteCollaborator
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                TestSite site = sites.get(0);
                site.updateMember(person13.getId(), SiteRole.SiteCollaborator);
                site.updateMember(person14.getId(), SiteRole.SiteCollaborator);
                return null;
            }
        }, person11.getId(), network1.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Comment(org.alfresco.rest.api.tests.client.data.Comment) Comments(org.alfresco.rest.api.tests.client.PublicApiClient.Comments) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Test(org.junit.Test)

Example 37 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite 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 38 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testSitesWithSameTitles.

// ACE-4823
@Test
public void testSitesWithSameTitles() throws Exception {
    // Creates 3 sites
    initializeSites();
    final String site4_name = "d_" + GUID.generate();
    // Same title as site3
    final String site4_title = site3_title;
    final SiteRole site4_role = SiteRole.SiteCollaborator;
    TestSite site4 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {

        @Override
        public TestSite doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(site4_name, site4_title, site4_title, SiteVisibility.PRIVATE);
            TestSite site = network1.createSite(siteInfo);
            site.inviteToSite(person32.getId(), site4_role);
            return site;
        }
    }, person31.getId(), network1.getId());
    assertNotNull(site4);
    // paging
    int totalResults = 4;
    Paging paging = getPaging(null, null, totalResults, totalResults);
    // get memberships
    ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(null, null, false);
    // check results
    List<MemberOfSite> expectedList = new LinkedList<>();
    expectedList.add(new MemberOfSite(site2, site2_role));
    expectedList.add(new MemberOfSite(site3, site3_role));
    expectedList.add(new MemberOfSite(site4, site4_role));
    expectedList.add(new MemberOfSite(site1, site1_role));
    try {
        checkList(expectedList, paging.getExpectedPaging(), resp);
    } catch (AssertionError error) {
        // Site3 and Site4 have a same title, and as we are sorting on titles (default sorting),
        // we can't guarantee the order in which the sites will
        // return, hence swap the sites and compare again.
        Collections.swap(expectedList, 1, 2);
        checkList(expectedList, paging.getExpectedPaging(), resp);
    }
}
Also used : SiteRole(org.alfresco.rest.api.tests.client.data.SiteRole) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) LinkedList(java.util.LinkedList) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) Test(org.junit.Test)

Example 39 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestPersonSites method testPersonSites.

@Test
public void testPersonSites() throws Exception {
    Set<MemberOfSite> personSites = new TreeSet<MemberOfSite>();
    // Get last site for use with personRemoveSite
    TestSite personRemoveSite = sites.get(sites.size() - 1);
    sites.remove(sites.size() - 1);
    personSites.addAll(network1.getSiteMemberships(person11.getId()));
    // Create some sites
    personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {

        @Override
        public List<MemberOfSite> doWork() throws Exception {
            List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
            TestSite site = network1.createSite(SiteVisibility.PRIVATE);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            site = network1.createSite(SiteVisibility.PUBLIC);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            site = network1.createSite(SiteVisibility.MODERATED);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteManager));
            return expectedSites;
        }
    }, person11.getId(), network1.getId()));
    personSites.addAll(TenantUtil.runAsUserTenant(new TenantRunAsWork<List<MemberOfSite>>() {

        @Override
        public List<MemberOfSite> doWork() throws Exception {
            List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>();
            TestSite site = network1.createSite(SiteVisibility.PRIVATE);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            site = network1.createSite(SiteVisibility.PUBLIC);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            site = network1.createSite(SiteVisibility.MODERATED);
            site.inviteToSite(person11.getId(), SiteRole.SiteConsumer);
            expectedSites.add(new MemberOfSite(site, SiteRole.SiteConsumer));
            return expectedSites;
        }
    }, person12.getId(), network1.getId()));
    final List<MemberOfSite> expectedSites = new ArrayList<MemberOfSite>(personSites);
    Sites sitesProxy = publicApiClient.sites();
    // unknown user
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSites(GUID.generate(), null);
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // Test Case cloud-2200
    // Test Case cloud-2213
    // user should be able to list their sites
    {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    {
        int skipCount = 2;
        int maxItems = 8;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        ListResponse<MemberOfSite> resp = sitesProxy.getPersonSites(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // a user in another tenant should not be able to list a user's sites
    try {
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
        sitesProxy.getPersonSites(person11.getId(), createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // Test case cloud-1488
    {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        MemberOfSite ret = sitesProxy.getPersonSite(person11.getId(), memberOfSite.getSiteId());
        memberOfSite.expected(ret);
    }
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(person11.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // unknown person id
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(GUID.generate(), memberOfSite.getSiteId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.getPersonSite(person11.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    {
        // Tests removing a person from the site
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.remove("people", person11.getId(), "sites", personRemoveSite.getSiteId(), "Unable to DELETE a person site");
        try {
            sitesProxy.getPersonSite(person11.getId(), personRemoveSite.getSiteId());
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
    }
    // Not allowed methods
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.create("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to POST to a person site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.create("people", person11.getId(), "sites", null, null, "Unable to POST to person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        MemberOfSite memberOfSite = expectedSites.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.update("people", person11.getId(), "sites", memberOfSite.getSiteId(), null, "Unable to PUT a person site");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.update("people", person11.getId(), "sites", null, null, "Unable to PUT person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
        sitesProxy.remove("people", person11.getId(), "sites", null, "Unable to DELETE person sites");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) Sites(org.alfresco.rest.api.tests.client.PublicApiClient.Sites) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TreeSet(java.util.TreeSet) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 40 with TestSite

use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.

the class TestSiteMembershipRequests method setup.

@Override
@Before
public void setup() throws Exception {
    // init networks
    super.setup();
    Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
    this.network1 = networksIt.next();
    Iterator<String> personIt = network1.getPersonIds().iterator();
    this.person11Id = personIt.next();
    assertNotNull(person11Id);
    this.person12Id = personIt.next();
    assertNotNull(person12Id);
    this.person13Id = personIt.next();
    assertNotNull(person13Id);
    this.person14Id = personIt.next();
    assertNotNull(person14Id);
    this.person15Id = personIt.next();
    assertNotNull(person15Id);
    this.network2 = networksIt.next();
    Iterator<String> person1It = network2.getPersonIds().iterator();
    this.person24Id = person1It.next();
    assertNotNull(person24Id);
    // Create some sites, files and folders
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String guid = GUID.generate();
            String[] siteNames = new String[] { "sitex" + guid, "sitea" + guid, "sitef" + guid, "site234" + guid, "sitey" + guid, "siteb" + guid, "site643" + guid, "site24" + guid, "site8d6sc" + guid };
            String siteName = siteNames[0];
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
            TestSite site = network1.createSite(siteInfo);
            person1ModeratedSites.add(site);
            for (int i = 1; i < siteNames.length; i++) {
                siteName = siteNames[i];
                siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
                site = network1.createSite(siteInfo);
                person1ModeratedSites.add(site);
            }
            String[] mixedCaseSiteNames = new String[] { "MixedCase" + guid, "mixedCaseA" + guid };
            for (int i = 0; i < mixedCaseSiteNames.length; i++) {
                siteName = mixedCaseSiteNames[i];
                siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
                site = network1.createSite(siteInfo);
                person1MixedCaseModeratedSites.add(site);
            }
            for (int i = 0; i < 1; i++) {
                siteName = "privatesite" + GUID.generate();
                siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
                site = network1.createSite(siteInfo);
                person1PrivateSites.add(site);
            }
            NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
            person1Docs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
            person1Folders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
            person1Docs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
            person1Folders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
            person1Docs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
            person1Folders.add(nodeRef);
            siteName = "site" + GUID.generate();
            siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            site = network1.createSite(siteInfo);
            person1PublicSites.add(site);
            return null;
        }
    }, person12Id, network1.getId());
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + System.currentTimeMillis();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            TestSite site = network1.createSite(siteInfo);
            NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
            personDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
            personFolders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
            personDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
            personFolders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
            personDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
            personFolders.add(nodeRef);
            return null;
        }
    }, person11Id, network1.getId());
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + GUID.generate();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            TestSite site = network1.createSite(siteInfo);
            personPublicSites.add(site);
            site.inviteToSite(person12Id, SiteRole.SiteCollaborator);
            siteName = "site" + GUID.generate();
            siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            site = network1.createSite(siteInfo);
            personPublicSites.add(site);
            return null;
        }
    }, person11Id, network1.getId());
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            String siteName = "site" + GUID.generate();
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
            TestSite site = network1.createSite(siteInfo);
            person4ModeratedSites.add(site);
            return null;
        }
    }, person24Id, network2.getId());
    this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ParseException(java.text.ParseException) Before(org.junit.Before)

Aggregations

TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)47 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)42 Test (org.junit.Test)39 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)35 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)33 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)31 NodeRef (org.alfresco.service.cmr.repository.NodeRef)29 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)27 ArrayList (java.util.ArrayList)23 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)19 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)19 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)19 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)19 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)19 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)19 HashMap (java.util.HashMap)18 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)18 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)17 List (java.util.List)15 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)15