Search in sources :

Example 46 with TestNetwork

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

the class TestCMIS method testTypeFiltering.

/**
 * ALF-18968
 *
 * @see QNameFilterImpl#listOfHardCodedExcludedTypes()
 */
@Test
public void testTypeFiltering() throws Exception {
    // Force an exclusion in order to test the exclusion inheritance
    cmisTypeExclusions.setExcluded(ActionModel.TYPE_ACTION_BASE, true);
    // Quick check
    assertTrue(cmisTypeExclusions.isExcluded(ActionModel.TYPE_ACTION_BASE));
    // Test that a type defined with this excluded parent type does not break the CMIS dictionary
    DictionaryBootstrap bootstrap = new DictionaryBootstrap();
    List<String> bootstrapModels = new ArrayList<String>();
    bootstrapModels.add("publicapi/test-model.xml");
    bootstrap.setModels(bootstrapModels);
    bootstrap.setDictionaryDAO(dictionaryDAO);
    bootstrap.setTenantService(tenantService);
    bootstrap.bootstrap();
    cmisDictionary.afterDictionaryInit();
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, TEST_PASSWORD, null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    // test that this type is excluded; the 'action' model (act prefix) is in the list of hardcoded exclusions
    QName type = QName.createQName("{http://www.alfresco.org/test/testCMIS}type1");
    assertTrue(cmisTypeExclusions.isExcluded(type));
    // and that we can't get to it through CMIS
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_10, AlfrescoObjectFactoryImpl.class.getName());
    try {
        cmisSession.getTypeDefinition("D:testCMIS:type1");
        fail("Type should not be available");
    } catch (CmisObjectNotFoundException e) {
    // ok
    }
}
Also used : AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) DictionaryBootstrap(org.alfresco.repo.dictionary.DictionaryBootstrap) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 47 with TestNetwork

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

the class TestCustomConstraint method testCreateConstraintAndAddToProperty.

@Test
public void testCreateConstraintAndAddToProperty() throws Exception {
    setRequestContext(customModelAdmin);
    String modelName = "testModelConstraint" + System.currentTimeMillis();
    final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
    // Create the model as a Model Administrator
    createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
    // Create RegEx constraint
    String regExConstraintName = "testFileNameRegEx" + System.currentTimeMillis();
    CustomModelConstraint regExConstraint = new CustomModelConstraint();
    regExConstraint.setName(regExConstraintName);
    regExConstraint.setType("REGEX");
    regExConstraint.setTitle("test RegEx title");
    regExConstraint.setDescription("test RegEx desc");
    // Create the RegEx constraint's parameters
    List<CustomModelNamedValue> parameters = new ArrayList<>(2);
    parameters.add(buildNamedValue("expression", "(.*[\\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)"));
    parameters.add(buildNamedValue("requiresMatch", "false"));
    // Add the parameters into the constraint
    regExConstraint.setParameters(parameters);
    // Create constraint as a Model Administrator
    post("cmm/" + modelName + "/constraints", RestApiUtil.toJsonAsString(regExConstraint), 201);
    // Retrieve the created constraint
    HttpResponse response = getSingle("cmm/" + modelName + "/constraints", regExConstraintName, 200);
    CustomModelConstraint returnedConstraint = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelConstraint.class);
    // Retrieve all the model's constraints
    Paging paging = getPaging(0, Integer.MAX_VALUE);
    response = getAll("cmm/" + modelName + "/constraints", paging, 200);
    List<CustomModelConstraint> constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
    assertEquals(1, constraints.size());
    // Create aspect
    String aspectName = "testAspect1" + System.currentTimeMillis();
    createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
    // Update the Aspect by adding property
    CustomAspect payload = new CustomAspect();
    payload.setName(aspectName);
    final String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
    CustomModelProperty aspectProp = new CustomModelProperty();
    aspectProp.setName(aspectPropName);
    aspectProp.setTitle("property title");
    aspectProp.setDataType("d:text");
    // Add the constraint ref
    aspectProp.setConstraintRefs(Arrays.asList(returnedConstraint.getPrefixedName()));
    List<CustomModelProperty> props = new ArrayList<>(1);
    props.add(aspectProp);
    payload.setProperties(props);
    // Create the property
    put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
    // Activate the model
    CustomModel updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.ACTIVE);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    // Retrieve all the model's constraints
    // Test to see if the API took care of duplicate constraints when referencing a constraint within a property.
    response = getAll("cmm/" + modelName + "/constraints", paging, 200);
    constraints = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModelConstraint.class);
    assertEquals(1, constraints.size());
    // Test RegEx constrain enforcement
    {
        final NodeService nodeService = repoService.getNodeService();
        final QName aspectQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectName);
        TestNetwork testNetwork = getTestFixture().getRandomNetwork();
        TestPerson person = testNetwork.createUser();
        final String siteName = "site" + System.currentTimeMillis();
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
                TestSite site = repoService.createSite(null, siteInfo);
                NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc", "Test Content");
                nodeService.addAspect(nodeRef, aspectQName, null);
                assertTrue(nodeService.hasAspect(nodeRef, aspectQName));
                try {
                    QName propQName = QName.createQName("{" + namespacePair.getFirst() + "}" + aspectPropName);
                    nodeService.setProperty(nodeRef, propQName, "Invalid$Char.");
                    fail("Invalid property value. Should have caused integrity violations.");
                } catch (Exception e) {
                // Expected
                }
                // Permanently remove model from repository
                nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
                nodeService.deleteNode(nodeRef);
                return null;
            }
        }, person.getId(), testNetwork.getId());
    }
    setRequestContext(customModelAdmin);
    // Deactivate the model
    updatePayload = new CustomModel();
    updatePayload.setStatus(ModelStatus.DRAFT);
    put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), SELECT_STATUS_QS, 200);
    // Test update the namespace prefix (test to see if the API updates the constraints refs with this new prefix)
    CustomModel updateModelPayload = new CustomModel();
    String modifiedPrefix = namespacePair.getSecond() + "Modified";
    updateModelPayload.setNamespacePrefix(modifiedPrefix);
    updateModelPayload.setNamespaceUri(namespacePair.getFirst());
    response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
    CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix());
    assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri());
    // Test update the namespace URI
    updateModelPayload = new CustomModel();
    updateModelPayload.setNamespacePrefix(modifiedPrefix);
    String modifiedURI = namespacePair.getFirst() + "Modified";
    updateModelPayload.setNamespaceUri(modifiedURI);
    response = put("cmm", modelName, RestApiUtil.toJsonAsString(updateModelPayload), null, 200);
    returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
    assertEquals(modifiedURI, returnedModel.getNamespaceUri());
    assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
}
Also used : QName(org.alfresco.service.namespace.QName) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) NodeService(org.alfresco.service.cmr.repository.NodeService) ArrayList(java.util.ArrayList) CustomAspect(org.alfresco.rest.api.model.CustomAspect) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) CustomModel(org.alfresco.rest.api.model.CustomModel) ConstraintException(org.alfresco.service.cmr.dictionary.ConstraintException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) CustomModelNamedValue(org.alfresco.rest.api.model.CustomModelNamedValue) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) Test(org.junit.Test)

Example 48 with TestNetwork

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

the class TestFavourites method setup.

@Override
@Before
public void setup() throws Exception {
    // init networks
    super.setup();
    final Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        @SuppressWarnings("synthetic-access")
        public Void execute() throws Throwable {
            try {
                AuthenticationUtil.pushAuthentication();
                AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
                // create some users
                TestFavourites.this.network1 = networksIt.next();
                String name = GUID.generate();
                PersonInfo personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
                TestFavourites.this.person10 = network1.createUser(personInfo);
                assertNotNull(TestFavourites.this.person10);
                TestFavourites.this.person10Id = TestFavourites.this.person10.getId();
                name = GUID.generate();
                personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
                TestFavourites.this.person11 = network1.createUser(personInfo);
                assertNotNull(TestFavourites.this.person11);
                TestFavourites.this.person11Id = TestFavourites.this.person11.getId();
                name = GUID.generate();
                personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
                TestFavourites.this.person12 = network1.createUser(personInfo);
                assertNotNull(TestFavourites.this.person12);
                TestFavourites.this.person12Id = TestFavourites.this.person12.getId();
                name = GUID.generate();
                personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
                TestFavourites.this.person14 = network1.createUser(personInfo);
                assertNotNull(TestFavourites.this.person14);
                TestFavourites.this.person14Id = TestFavourites.this.person14.getId();
                TestFavourites.this.network2 = networksIt.next();
                name = GUID.generate();
                personInfo = new PersonInfo(name, name, name, "password", null, null, null, null, null, null, null);
                TestFavourites.this.person21 = network2.createUser(personInfo);
                assertNotNull(TestFavourites.this.person21);
                TestFavourites.this.person21Id = TestFavourites.this.person21.getId();
                return null;
            } finally {
                AuthenticationUtil.popAuthentication();
            }
        }
    }, false, true);
    // Create some favourite targets, sites, files and folders
    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);
            person1PublicSites.add(site);
            NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
            person1PublicDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description");
            person1PublicFolders.add(nodeRef);
            nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
            person1PublicDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description");
            person1PublicFolders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content");
            person1PublicDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description");
            person1PublicFolders.add(nodeRef);
            siteName = "site" + GUID.generate();
            siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            site = network1.createSite(siteInfo);
            person1PublicSites.add(site);
            siteName = "site" + GUID.generate();
            siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            site = network1.createSite(siteInfo);
            person1PrivateSites.add(site);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
            person1PrivateDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1", "Test Folder1 Title", "Test Folder1 Description");
            person1PrivateFolders.add(nodeRef);
            nodeRef = repoService.createDocument(nodeRef, "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
            person1PrivateDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2", "Test Folder2 Title", "Test Folder2 Description");
            person1PrivateFolders.add(nodeRef);
            nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Doc3 Title", "Test Doc3 Description", "Test Content");
            person1PrivateDocs.add(nodeRef);
            nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3", "Test Folder3 Title", "Test Folder3 Description");
            person1PrivateFolders.add(nodeRef);
            return null;
        }
    }, person11Id, 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);
            person1PublicSites.add(site);
            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;
        }
    }, person10Id, 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);
            personSites.add(site);
            site.inviteToSite(person11Id, SiteRole.SiteCollaborator);
            siteName = "site" + GUID.generate();
            siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            site = network1.createSite(siteInfo);
            personSites.add(site);
            return null;
        }
    }, person10Id, network1.getId());
    this.favouritesProxy = publicApiClient.favourites();
    this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ParseException(java.text.ParseException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) Before(org.junit.Before)

Example 49 with TestNetwork

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

the class TestNetworks method testALF20098.

// ALF-20216, ALF-20217, ALF-20098
// http://localhost:8080/alfresco/api/-default-
@Test
public void testALF20098() throws Exception {
    final TestNetwork testAccount = getTestFixture().getRandomNetwork();
    Iterator<TestPerson> personIt = testAccount.getPeople().iterator();
    final TestPerson person = personIt.next();
    RequestContext rc = new RequestContext("-default-", person.getId());
    publicApiClient.setRequestContext(rc);
    HttpResponse response = publicApiClient.get("-default-", null);
    assertEquals(200, response.getStatusCode());
}
Also used : TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Test(org.junit.Test)

Example 50 with TestNetwork

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

the class TestNetworks method testPersonNetworks.

@Test
public void testPersonNetworks() throws Exception {
    People peopleProxy = publicApiClient.people();
    {
        /**
         * Test http://<host>:<port>/alfresco/a i.e. tenant servlet root - should return user's networks
         */
        final TestNetwork testAccount = getTestFixture().getRandomNetwork();
        Iterator<TestPerson> personIt = testAccount.getPeople().iterator();
        final TestPerson person = personIt.next();
        RequestContext rc = new RequestContext(null, person.getId());
        publicApiClient.setRequestContext(rc);
        HttpResponse response = publicApiClient.delete(null, null, null, null, null);
        // url /null/alfresco/versions/1 does not map to a Web Script
        assertEquals(404, response.getStatusCode());
        PublicApiClient.ExpectedErrorResponse errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        response = publicApiClient.put(null, null, null, null, null, null, null);
        assertEquals(404, response.getStatusCode());
        errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        response = publicApiClient.post(null, null, null, null, null, null);
        assertEquals(404, response.getStatusCode());
        errorResponse = RestApiUtil.parseErrorResponse(response.getJsonResponse());
        assertNotNull(errorResponse);
        assertNotNull(errorResponse.getErrorKey());
        assertNotNull(errorResponse.getBriefSummary());
        List<PersonNetwork> expectedNetworkMembers = person.getNetworkMemberships();
        int expectedTotal = expectedNetworkMembers.size();
        {
            // GET / - users networks
            Paging paging = getPaging(0, Integer.MAX_VALUE, expectedTotal, expectedTotal);
            publicApiClient.setRequestContext(new RequestContext("-default-", person.getId()));
            response = publicApiClient.index(createParams(paging, null));
            ListResponse<PersonNetwork> resp = PersonNetwork.parseNetworkMembers(response.getJsonResponse());
            assertEquals(200, response.getStatusCode());
            checkList(new ArrayList<PersonNetwork>(expectedNetworkMembers), paging.getExpectedPaging(), resp);
        }
    }
    // user from another network
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person21.getId()));
        List<PersonNetwork> networksMemberships = Collections.emptyList();
        try {
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
            peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
    }
    // user from the same network
    try {
        List<PersonNetwork> networksMemberships = person12.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person12.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    List<PersonNetwork> networksMemberships = person11.getNetworkMemberships();
    // Test Case cloud-2203
    // Test Case cloud-1498
    // test paging
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(person11.getId(), createParams(paging, null));
        checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems, networksMemberships.size(), networksMemberships.size());
        ListResponse<PersonNetwork> resp = peopleProxy.getNetworkMemberships(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(networksMemberships.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // unknown person id
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
        peopleProxy.getNetworkMemberships("invalidUser", createParams(expectedPaging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // invalid caller authentication
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems, networkMemberships.size(), networkMemberships.size());
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // unknown person id
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        assertTrue(networkMemberships.size() > 0);
        PersonNetwork network = networkMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.getNetworkMembership("invalidUser", network.getId());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // invalid caller authentication
    try {
        List<PersonNetwork> networkMemberships = person11.getNetworkMemberships();
        assertTrue(networkMemberships.size() > 0);
        PersonNetwork network = networkMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId(), GUID.generate()));
        peopleProxy.getNetworkMembership(person11.getId(), network.getId());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
    }
    // incorrect network id
    try {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.getNetworkMembership(person11.getId(), GUID.generate());
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // POST, POST networkId, PUT, PUT networkId, DELETE, DELETE networkId
    try {
        PersonNetwork pn = new PersonNetwork(GUID.generate());
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.create("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to POST to person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.create("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to POST to a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = new PersonNetwork(GUID.generate());
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.update("people", person11.getId(), "networks", null, pn.toJSON().toString(), "Unable to PUT person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.update("people", person11.getId(), "networks", pn.getId(), pn.toJSON().toString(), "Unable to PUT a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.remove("people", person11.getId(), "networks", null, "Unable to DELETE person networks");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        PersonNetwork pn = networksMemberships.get(0);
        publicApiClient.setRequestContext(new RequestContext("-default-", person11.getId()));
        peopleProxy.remove("people", person11.getId(), "networks", pn.getId(), "Unable to DELETE a person network");
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    // user not a member of the network
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
        int skipCount = 0;
        int maxItems = 2;
        Paging expectedPaging = getPaging(skipCount, maxItems);
        peopleProxy.getNetworkMemberships(person11.getId(), createParams(expectedPaging, null));
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_UNAUTHORIZED, 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) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) PersonNetwork(org.alfresco.rest.api.tests.client.data.PersonNetwork) Test(org.junit.Test)

Aggregations

TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)65 Test (org.junit.Test)51 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)50 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)47 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)38 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)33 HashMap (java.util.HashMap)29 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)26 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)25 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)23 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)22 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)22 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)21 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)21 ArrayList (java.util.ArrayList)18 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)18 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)15 Document (org.apache.chemistry.opencmis.client.api.Document)15