1 17 package org.alfresco.repo.content.transform; 18 19 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.alfresco.repo.content.MimetypeMap; 26 import org.alfresco.repo.content.filestore.FileContentWriter; 27 import org.alfresco.repo.content.transform.ContentTransformerRegistry.TransformationKey; 28 import org.alfresco.service.cmr.repository.ContentReader; 29 import org.alfresco.service.cmr.repository.ContentWriter; 30 import org.alfresco.util.BaseAlfrescoTestCase; 31 import org.alfresco.util.TempFileProvider; 32 import org.alfresco.util.exec.RuntimeExec; 33 import org.apache.xml.security.transforms.TransformationException; 34 35 40 public class RuntimeExecutableContentTransformerTest extends BaseAlfrescoTestCase 41 { 42 private RuntimeExecutableContentTransformer transformer; 43 44 @Override 45 protected void setUp() throws Exception 46 { 47 super.setUp(); 48 49 transformer = new RuntimeExecutableContentTransformer(); 50 RuntimeExec transformCommand = new RuntimeExec(); 52 Map <String , String > commandMap = new HashMap <String , String >(5); 53 commandMap.put("Linux", "mv -f ${source} ${target}"); 54 commandMap.put(".*", "cmd /c copy /Y \"${source}\" \"${target}\""); 55 transformCommand.setCommandMap(commandMap); 56 transformCommand.setErrorCodes("1, 2"); 57 transformer.setTransformCommand(transformCommand); 58 transformer.setMimetypeService(serviceRegistry.getMimetypeService()); 59 List <TransformationKey> explicitTranformations = new ArrayList <TransformationKey>(1); 61 explicitTranformations.add( 62 new TransformationKey(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_XML)); 63 transformer.setExplicitTransformations(explicitTranformations); 64 65 transformer.register(); 67 } 68 69 public void testCopyCommand() throws Exception 70 { 71 String content = "<A><B></B></A>"; 72 File sourceFile = TempFileProvider.createTempFile(getName() + "_", ".txt"); 74 ContentWriter tempWriter = new FileContentWriter(sourceFile); 75 tempWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); 76 tempWriter.putContent(content); 77 ContentReader reader = tempWriter.getReader(); 78 File targetFile = TempFileProvider.createTempFile(getName() + "_", ".xml"); 80 ContentWriter writer = new FileContentWriter(targetFile); 81 writer.setMimetype(MimetypeMap.MIMETYPE_XML); 82 83 transformer.transform(reader, writer); 86 ContentReader checkReader = writer.getReader(); 88 String checkContent = checkReader.getContentString(); 89 assertEquals("Content not copied", content, checkContent); 90 } 91 } 92 | Popular Tags |