KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > transform > ComplexContentTransformerTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content.transform;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.alfresco.repo.content.MimetypeMap;
24
25 /**
26  * Tests a transformation from Powerpoint->PDF->Text.
27  *
28  * @see org.alfresco.repo.content.transform.ComplexContentTransformer
29  *
30  * @author Derek Hulley
31  */

32 public class ComplexContentTransformerTest extends AbstractContentTransformerTest
33 {
34     private ComplexContentTransformer transformer;
35     private boolean isAvailable;
36     
37     public void onSetUpInTransaction() throws Exception JavaDoc
38     {
39         ContentTransformer unoTransformer = (ContentTransformer) applicationContext.getBean("transformer.OpenOffice");
40         ContentTransformer pdfBoxTransformer = (ContentTransformer) applicationContext.getBean("transformer.PdfBox");
41         // make sure that they are working for this test
42
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         // set the transformer list
60
List JavaDoc<ContentTransformer> transformers = new ArrayList JavaDoc<ContentTransformer>(2);
61         transformers.add(unoTransformer);
62         transformers.add(pdfBoxTransformer);
63         transformer.setTransformers(transformers);
64         // set the intermediate mimetypes
65
List JavaDoc<String JavaDoc> intermediateMimetypes = Collections.singletonList(MimetypeMap.MIMETYPE_PDF);
66         transformer.setIntermediateMimetypes(intermediateMimetypes);
67     }
68     
69     /**
70      * @return Returns the same transformer regardless - it is allowed
71      */

72     protected ContentTransformer getTransformer(String JavaDoc sourceMimetype, String JavaDoc targetMimetype)
73     {
74         return transformer;
75     }
76     
77     public void testReliability() throws Exception JavaDoc
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