use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestCMIS method getTestSite.
private TestSite getTestSite() throws Exception {
if (testSite == null) {
getTestNetwork();
getTestPersonId();
String siteName = "site" + System.currentTimeMillis();
testSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
return testNetwork.createSite(siteInfo);
}
}, testPersonId, testNetwork.getId());
}
return testSite;
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation in project alfresco-remote-api by Alfresco.
the class TestCMIS method testMNT_13057.
@Test
public void testMNT_13057() 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();
String guid = GUID.generate();
String name = guid + "_KRUIS_LOGO_100%_PMS.txt";
String urlFileName = guid + "_KRUIS_LOGO_100%25_PMS.txt";
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");
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);
String id = doc.getId();
assertNotNull(id);
Map<String, String> params = new HashMap<String, String>();
params.put("id", URLEncoder.encode(id));
urlFileName += "?id=" + URLEncoder.encode(id);
HttpResponse response = publicApiClient.get(network1.getId() + "/public/cmis/versions/1.1/atom/content/" + urlFileName, null);
assertEquals(200, response.getStatusCode());
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation 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);
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation 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>"));
}
use of org.alfresco.rest.api.tests.RepoService.SiteInformation 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());
}
Aggregations