Search in sources :

Example 1 with ScriptContentData

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());
}
Also used : ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) InputStream(java.io.InputStream) InputStreamContent(org.springframework.extensions.surf.util.InputStreamContent) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Example 2 with ScriptContentData

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Repository(org.alfresco.repo.model.Repository) ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) ContentData(org.alfresco.service.cmr.repository.ContentData) ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Example 3 with ScriptContentData

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());
}
Also used : ScriptContentData(org.alfresco.repo.jscript.ScriptNode.ScriptContentData) InputStream(java.io.InputStream) InputStreamContent(org.springframework.extensions.surf.util.InputStreamContent) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) Test(org.junit.Test)

Aggregations

ScriptContentData (org.alfresco.repo.jscript.ScriptNode.ScriptContentData)3 ActivitiScriptNode (org.alfresco.repo.workflow.activiti.ActivitiScriptNode)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 InputStreamContent (org.springframework.extensions.surf.util.InputStreamContent)2 Repository (org.alfresco.repo.model.Repository)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1