1   package de.fu_berlin.ties.io;
2   
3   import junit.framework.TestCase;
4   // JUnitDoclet begin import
5   import java.io.File;
6   import java.net.URL;
7   
8   import de.fu_berlin.ties.TiesConfiguration;
9   // JUnitDoclet end import
10  
11  /***
12  * Generated by JUnitDoclet, a tool provided by
13  * ObjectFab GmbH under LGPL.
14  * Please see www.junitdoclet.org, www.gnu.org
15  * and www.objectfab.de for informations about
16  * the tool, the licence and the authors.
17  */
18  
19  
20  public class ContentTypeTest
21  // JUnitDoclet begin extends_implements
22  extends TestCase
23  // JUnitDoclet end extends_implements
24  {
25    // JUnitDoclet begin class
26    de.fu_berlin.ties.io.ContentType contenttype = null;
27    // JUnitDoclet end class
28    
29    public ContentTypeTest(String name) {
30      // JUnitDoclet begin method ContentTypeTest
31      super(name);
32      // JUnitDoclet end method ContentTypeTest
33    }
34    
35    public de.fu_berlin.ties.io.ContentType createInstance() throws Exception {
36      // JUnitDoclet begin method testcase.createInstance
37      return null;
38      // JUnitDoclet end method testcase.createInstance
39    }
40    
41    protected void setUp() throws Exception {
42      // JUnitDoclet begin method testcase.setUp
43      super.setUp();
44      contenttype = createInstance();
45      // JUnitDoclet end method testcase.setUp
46    }
47    
48    protected void tearDown() throws Exception {
49      // JUnitDoclet begin method testcase.tearDown
50      contenttype = null;
51      super.tearDown();
52      // JUnitDoclet end method testcase.tearDown
53    }
54    
55    public void testDetermineContentType() throws Exception {
56      // JUnitDoclet begin method determineContentType
57      String[][] urlInput = {
58          {"application/PDF", ""},
59          {"application/rtf", null},
60          {"application/xhtml+xml", ""},
61          {"application/xml", ""},
62          {"model/vrml", null},
63          {"text/css; charset=iso8859-4", ""},
64          {"text/html; param1=bla; CharSet=UTF-8; param2=\"blub\"", "xml"},
65          {"text/plain; param1=\"bla\"; Charset=\"ISO8859-1\"; par2=\"xy\"",
66              ""},
67          {"txt/rtf", ""},
68          {"Text/URI-list;charset = utf-8", ""},
69          {null, "URIs"},
70          {"text/xml;charset= ENC-7 ;param2=blub", ""},
71          {"text/xml; charset= \"UTF-8\"", "html"},
72          {"text/xml", "pdf"},
73          {"text/bla", "PDF"},
74          {"", "xml"},
75          {"", "HTML"},
76          {null, "htm"},
77          {null, null}
78      };
79      String[][] urlOutput = {
80          {"application/pdf", null},
81          {"text/rtf", null},
82          {"text/html", null},
83          {"text/xml", null},
84          {"model/vrml", null},
85          {"text/css", "iso8859-4"},
86          {"text/html", "UTF-8"},
87          {"text/plain", "ISO8859-1"},
88          {"txt/rtf", null},
89          {"text/uri-list", "utf-8"},
90          {"text/uri-list", null},
91          {"text/xml", "ENC-7"},
92          {"text/xml", "UTF-8"},
93          {"text/xml", null},
94          {"text/bla", null},
95          {"text/xml", null},
96          {"text/html", null},
97          {"text/html", null},
98          {null, null},
99      };
100 
101     String[] fileInput = {
102         "bla.xHtml",
103         "tmp/file.txt",
104         "Source.java",
105         "/path/to/dir/text.converted.rtf",
106         "/path/to/dir/README",
107         null,
108     };
109     String[] fileOutput = {
110         "text/html",
111         "text/plain",
112         null,
113         "text/rtf",
114         null,
115         null,
116     };
117 
118     URL url;
119     ContentType type;
120 
121     for (int i = 0; i < urlInput.length; i++) {
122         url = (urlInput[i][1] == null) ? null
123                 : new URL("http://test.com/dir/file." + urlInput[i][1]);
124         type = ContentType.determineContentType(url,
125                 urlInput[i][0], TiesConfiguration.CONF);
126 
127         assertEquals(urlOutput[i][0], type.getMimeType());
128         assertEquals(urlOutput[i][1], type.getCharset());
129 /*        if (!StringUtils.equals(urlOutput[i][0], type.getMimeType())) {
130             System.out.println("URL " + i + ": " + urlOutput[i][0] + " != "
131                     + type.getMimeType());
132         }
133         if (!StringUtils.equals(urlOutput[i][1], type.getCharset())) {
134             System.out.println("URL " + i + ": " + urlOutput[i][1] + " != "
135                     + type.getCharset());
136         } */
137     }
138 
139     File file;
140 
141     for (int i = 0; i < fileInput.length; i++) {
142         file = (fileInput[i] == null) ? null : new File(fileInput[i]);
143         type = ContentType.determineContentType(file,
144                 TiesConfiguration.CONF);
145 
146         assertEquals(fileOutput[i], type.getMimeType());
147         assertNull(type.getCharset());
148 /*        if (!StringUtils.equals(fileOutput[i], type.getMimeType())) {
149             System.out.println("File " + i + ": " + fileOutput[i] + " != "
150                     + type.getMimeType());
151         }
152         if (type.getCharset() != null) {
153             System.out.println("File " + i + ": " + type.getCharset()
154                     + " is not null");
155         } */
156     }
157     // JUnitDoclet end method determineContentType
158   }
159   
160   public void testGetCharset() throws Exception {
161     // JUnitDoclet begin method getCharset
162     // JUnitDoclet end method getCharset
163   }
164   
165   public void testGetMimeType() throws Exception {
166     // JUnitDoclet begin method getMimeType
167     // JUnitDoclet end method getMimeType
168   }
169   
170   public void testToString() throws Exception {
171     // JUnitDoclet begin method toString
172     // JUnitDoclet end method toString
173   }
174   
175   
176   
177   /***
178   * JUnitDoclet moves marker to this method, if there is not match
179   * for them in the regenerated code and if the marker is not empty.
180   * This way, no test gets lost when regenerating after renaming.
181   * Method testVault is supposed to be empty.
182   */
183   public void testVault() throws Exception {
184     // JUnitDoclet begin method testcase.testVault
185     // JUnitDoclet end method testcase.testVault
186   }
187   
188   public static void main(String[] args) {
189     // JUnitDoclet begin method testcase.main
190     junit.textui.TestRunner.run(ContentTypeTest.class);
191     // JUnitDoclet end method testcase.main
192   }
193 }