Search in sources :

Example 31 with TestSite

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

the class TestCMIS method testMNT_10687.

/* MNT-10687 related test - appendContent to PWC CMIS 1.1 */
@Test
public void testMNT_10687() throws Exception {
    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();
    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(DOCUMENT_LIBRARY_CONTAINER_NAME), name);
            return folderNodeRef;
        }
    }, person1Id, network1.getId());
    // Create a document...
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    CmisSession cmisSession = publicApiClient.createPublicApiCMISSession(Binding.atom, CMIS_VERSION_11);
    Folder docLibrary = (Folder) cmisSession.getObjectByPath("/Sites/" + siteName + "/documentLibrary");
    String name = "mydoc-" + GUID.generate() + ".txt";
    Map<String, Object> properties = new HashMap<String, Object>();
    {
        properties.put(PropertyIds.OBJECT_TYPE_ID, TYPE_CMIS_DOCUMENT);
        properties.put(PropertyIds.NAME, name);
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent("Ipsum");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    /* Create document */
    Document doc = docLibrary.createDocument(properties, fileContent, VersioningState.MAJOR);
    /* Checkout document */
    ObjectId pwcId = doc.checkOut();
    Document pwc = (Document) cmisSession.getObject(pwcId.getId());
    /* append content to PWC */
    fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(GUID.generate(), ".txt"));
        writer.putContent(" and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    pwc.appendContentStream(fileContent, true);
    pwc.checkIn(false, null, null, "Check In");
    ContentStream contentStream = doc.getObjectOfLatestVersion(false).getContentStream();
    InputStream in = contentStream.getStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(in, writer, "UTF-8");
    String content = writer.toString();
    assertEquals("Ipsum and so on", content);
}
Also used : ContentStreamImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl) HashMap(java.util.HashMap) AlfrescoFolder(org.alfresco.cmis.client.AlfrescoFolder) Folder(org.apache.chemistry.opencmis.client.api.Folder) AlfrescoDocument(org.alfresco.cmis.client.AlfrescoDocument) Document(org.apache.chemistry.opencmis.client.api.Document) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) StringWriter(java.io.StringWriter) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) CmisSession(org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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) FileableCmisObject(org.apache.chemistry.opencmis.client.api.FileableCmisObject) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) VersionableAspectTest(org.alfresco.repo.version.VersionableAspectTest) Test(org.junit.Test)

Example 32 with TestSite

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

the class TestCMIS method testGetXmlWithIncorrectDescription.

/**
 * 1) Creating a file with incorrect char in description property
 * 2) Get xml with incorrect char in description
 * 3) Check xml
 * @throws Exception
 */
@Test
public void testGetXmlWithIncorrectDescription() 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();
    NodeRef fileNode = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() throws Exception {
            SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
            final TestSite site = network1.createSite(siteInfo);
            NodeRef resNode = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "testdoc \u0010.txt", "Test Doc1 Title \u0010", "d\u0010", "Test Content");
            return resNode;
        }
    }, person1Id, network1.getId());
    String cmisId = fileNode.getId();
    HashMap<String, String> reqParams = new HashMap<String, String>();
    reqParams.put("id", cmisId + ";1.0");
    reqParams.put("filter", "*");
    reqParams.put("includeAllowableActions", "true");
    reqParams.put("includeACL", "true");
    reqParams.put("includePolicyIds", "true");
    reqParams.put("includeRelationships", "both");
    reqParams.put("renditionFilter", "*");
    publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
    HttpResponse resp = publicApiClient.get(Binding.atom, CMIS_VERSION_11, "id", reqParams);
    String xml = resp.getResponse();
    // Response hasn't full info at error - writer just stops at incorrect character.
    // Therefore we can check end tag of root element
    assertTrue("No end tag was found", xml.endsWith("</atom:entry>"));
}
Also used : HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) 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) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) 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 TestSite

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

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

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

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