1 17 package org.alfresco.repo.content.transform; 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.List ; 22 23 import org.alfresco.repo.content.MimetypeMap; 24 25 32 public class ComplexContentTransformerTest extends AbstractContentTransformerTest 33 { 34 private ComplexContentTransformer transformer; 35 private boolean isAvailable; 36 37 public void onSetUpInTransaction() throws Exception 38 { 39 ContentTransformer unoTransformer = (ContentTransformer) applicationContext.getBean("transformer.OpenOffice"); 40 ContentTransformer pdfBoxTransformer = (ContentTransformer) applicationContext.getBean("transformer.PdfBox"); 41 if (unoTransformer.getReliability(MimetypeMap.MIMETYPE_PPT, MimetypeMap.MIMETYPE_PDF) == 0.0) 43 { 44 isAvailable = false; 45 return; 46 } 47 else if (pdfBoxTransformer.getReliability(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_TEXT_PLAIN) == 0.0) 48 { 49 isAvailable = false; 50 return; 51 } 52 else 53 { 54 isAvailable = true; 55 } 56 57 transformer = new ComplexContentTransformer(); 58 transformer.setMimetypeService(mimetypeMap); 59 List <ContentTransformer> transformers = new ArrayList <ContentTransformer>(2); 61 transformers.add(unoTransformer); 62 transformers.add(pdfBoxTransformer); 63 transformer.setTransformers(transformers); 64 List <String > intermediateMimetypes = Collections.singletonList(MimetypeMap.MIMETYPE_PDF); 66 transformer.setIntermediateMimetypes(intermediateMimetypes); 67 } 68 69 72 protected ContentTransformer getTransformer(String sourceMimetype, String targetMimetype) 73 { 74 return transformer; 75 } 76 77 public void testReliability() throws Exception 78 { 79 if (!isAvailable) 80 { 81 return; 82 } 83 double reliability = 0.0; 84 reliability = transformer.getReliability(MimetypeMap.MIMETYPE_PPT, MimetypeMap.MIMETYPE_PDF); 85 assertEquals("Mimetype should not be supported", 0.0, reliability); 86 reliability = transformer.getReliability(MimetypeMap.MIMETYPE_PPT, MimetypeMap.MIMETYPE_TEXT_PLAIN); 87 assertEquals("Mimetype should be supported", 1.0, reliability); 88 } 89 } 90 | Popular Tags |