Search in sources :

Example 31 with TestPerson

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

the class TestCMIS method testVersioningUsingUpdateProperties.

/**
 * Test that updating properties does automatically create a new version if
 * <b>autoVersion</b>, <b>initialVersion</b> and <b>autoVersionOnUpdateProps</b> are TRUE
 */
@Test
public void testVersioningUsingUpdateProperties() throws Exception {
    final TestNetwork network1 = getTestFixture().getRandomNetwork();
    String username = "user" + System.currentTimeMillis();
    PersonInfo personInfo = new PersonInfo(username, username, username, "password", null, null, null, null, null, null, null);
    TestPerson person1 = network1.createUser(personInfo);
    String person1Id = person1.getId();
    final String siteName = "site" + System.currentTimeMillis();
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
            TestSite site = repoService.createSite(null, siteInfo);
            String name = GUID.generate();
            NodeRef folderNodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, "1.0", AlfrescoObjectFactoryImpl.class.getName());
    AlfrescoFolder docLibrary = (AlfrescoFolder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    Map<String, String> properties = new HashMap<String, String>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        properties.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    AlfrescoDocument doc = (AlfrescoDocument) docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    String versionLabel = doc.getVersionLabel();
    String nodeRefStr = doc.getPropertyValue(NodeRefProperty.NodeRefPropertyId).toString();
    final NodeRef nodeRef = new NodeRef(nodeRefStr);
    TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            // ensure autoversioning is enabled
            assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE));
            Map<QName, Serializable> versionProperties = new HashMap<QName, Serializable>();
            versionProperties.put(ContentModel.PROP_AUTO_VERSION, true);
            versionProperties.put(ContentModel.PROP_INITIAL_VERSION, true);
            versionProperties.put(ContentModel.PROP_AUTO_VERSION_PROPS, true);
            nodeService.addProperties(nodeRef, versionProperties);
            return null;
        }
    }, person1Id, network1.getId());
    // ...and check that updating its properties creates a new minor version...
    properties = new HashMap<String, String>();
    {
        properties.put(PropertyIds.DESCRIPTION, GUID.generate());
    }
    AlfrescoDocument doc1 = (AlfrescoDocument) doc.getObjectOfLatestVersion(false).updateProperties(properties);
    doc1 = (AlfrescoDocument) doc.getObjectOfLatestVersion(false);
    String versionLabel1 = doc1.getVersionLabel();
    assertTrue(Double.parseDouble(versionLabel) < Double.parseDouble(versionLabel1));
    // ...and check that updating its content creates a new version
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum and so on and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    doc1.setContentStream(fileContent, true);
    AlfrescoDocument doc2 = (AlfrescoDocument) doc1.getObjectOfLatestVersion(false);
    String versionLabel2 = doc2.getVersionLabel();
    assertTrue("Set content stream should create a new version automatically", Double.parseDouble(versionLabel1) < Double.parseDouble(versionLabel2));
    assertTrue("It should be latest version : " + versionLabel2, doc2.isLatestVersion());
    doc2.deleteContentStream();
    AlfrescoDocument doc3 = (AlfrescoDocument) doc2.getObjectOfLatestVersion(false);
    String versionLabel3 = doc3.getVersionLabel();
    assertTrue("Delete content stream should create a new version automatically", Double.parseDouble(versionLabel1) < Double.parseDouble(versionLabel3));
    assertTrue("It should be latest version : " + versionLabel3, doc3.isLatestVersion());
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Serializable(java.io.Serializable) HashMap(java.util.HashMap) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) AlfrescoObjectFactoryImpl(org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) QName(org.alfresco.service.namespace.QName) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) ContentReader(org.alfresco.service.cmr.repository.ContentReader) CmisUpdateConflictException(org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 32 with TestPerson

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

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

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

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

TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)43 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)36 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)34 Test (org.junit.Test)34 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)33 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)30 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)20 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)19 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)19 HashMap (java.util.HashMap)18 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)18 ArrayList (java.util.ArrayList)17 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)17 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)17 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)17 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)17 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)15 List (java.util.List)12 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)12