use of org.alfresco.repo.jscript.ScriptNode.ScriptContentData in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testWriteContentWithMimetypeAndWithoutFilename.
/**
* https://issues.alfresco.com/jira/browse/MNT-19682
* Test that mimetype is correctly set according to the content
*/
@Test
public void testWriteContentWithMimetypeAndWithoutFilename() {
createTestContent(true);
ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
scriptNode.setScope(getScope());
ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");
scd.write(inputStreamContent, true, false);
assertEquals(MimetypeMap.MIMETYPE_APPLICATION_PS, scriptNode.getMimetype());
}
use of org.alfresco.repo.jscript.ScriptNode.ScriptContentData in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testContentDataCreation.
/**
* MNT-15798 - Content Data should be created only when it has a binary, not as a side effect of getters on ScriptNode.
*/
@Test
public void testContentDataCreation() {
Repository repositoryHelper = (Repository) APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
NodeRef companyHome = repositoryHelper.getCompanyHome();
NodeRef newNode1 = testNodes.createNode(companyHome, "theTestContent1", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
// test on content data
ScriptNode sn = new ScriptNode(newNode1, SERVICE_REGISTRY);
sn.setScope(getScope());
ContentData contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
assertNull(contentData);
sn.setMimetype(MimetypeMap.MIMETYPE_PDF);
sn.save();
contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
assertNull(contentData);
sn.setContent("Marks to prove it.");
sn.save();
contentData = (ContentData) NODE_SERVICE.getProperty(newNode1, ContentModel.PROP_CONTENT);
assertNotNull(contentData);
assertEquals(true, ContentData.hasContent(contentData));
// test on ScriptContentData
NodeRef newNode2 = testNodes.createNode(companyHome, "theTestContent2.txt", ContentModel.TYPE_CONTENT, AuthenticationUtil.getFullyAuthenticatedUser());
ScriptNode sn2 = new ScriptNode(newNode2, SERVICE_REGISTRY);
sn2.setScope(getScope());
ScriptContentData scd = sn2.new ScriptContentData(null, ContentModel.PROP_CONTENT);
// set the "mocked" script content data on the script node
sn2.getProperties().put(ContentModel.PROP_CONTENT.toString(), scd);
assertEquals(false, scd.isDirty());
scd.guessMimetype("theTestContent2.pdf");
assertEquals(false, scd.isDirty());
scd.setMimetype("text/plain");
assertEquals(false, scd.isDirty());
scd.setEncoding("UTF-8");
assertEquals(false, scd.isDirty());
sn2.save();
contentData = (ContentData) NODE_SERVICE.getProperty(newNode2, ContentModel.PROP_CONTENT);
assertNull(contentData);
scd.setContent("Marks to prove it.");
assertEquals(true, scd.isDirty());
scd.setEncoding("ISO-8859-1");
assertEquals(true, scd.isDirty());
sn2.save();
contentData = (ContentData) NODE_SERVICE.getProperty(newNode2, ContentModel.PROP_CONTENT);
assertNotNull(contentData);
NODE_SERVICE.removeProperty(newNode1, ContentModel.PROP_CONTENT);
NODE_SERVICE.removeProperty(newNode2, ContentModel.PROP_CONTENT);
}
use of org.alfresco.repo.jscript.ScriptNode.ScriptContentData in project alfresco-repository by Alfresco.
the class ScriptNodeTest method testWriteContentWithMimetypeAndFilename.
/**
* https://issues.alfresco.com/jira/browse/MNT-19682
* Test that mimetype is correctly set according to the filename
*/
@Test
public void testWriteContentWithMimetypeAndFilename() {
createTestContent(true);
ScriptNode scriptNode = new ScriptNode(testNode, SERVICE_REGISTRY);
scriptNode.setScope(getScope());
ScriptContentData scd = scriptNode.new ScriptContentData(null, ContentModel.PROP_CONTENT);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TEST_CONTENT_MODEL);
InputStreamContent inputStreamContent = new InputStreamContent(inputStream, MimetypeMap.MIMETYPE_APPLICATION_PS, "UTF-8");
scd.write(inputStreamContent, true, false, "test.ai");
assertEquals(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR, scriptNode.getMimetype());
}
Aggregations