1 64 65 package com.jcorporate.expresso.services.dbobj.tests; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 69 import com.jcorporate.expresso.services.dbobj.MimeTypes; 70 import com.jcorporate.expresso.services.test.ControllerTestSuite; 71 import com.jcorporate.expresso.services.test.ExpressoTestCase; 72 import com.jcorporate.expresso.services.test.TestSystemInitializer; 73 74 import javax.activation.MimetypesFileTypeMap ; 75 76 77 84 public class MimeTypesTests 85 extends ExpressoTestCase { 86 public MimeTypesTests(String testName) 87 throws Exception { 88 super(testName); 89 } 90 91 public static void main(String [] args) 92 throws Exception { 93 junit.textui.TestRunner.run(suite()); 94 } 95 96 public static junit.framework.Test suite() 97 throws Exception { 98 ControllerTestSuite cts = new ControllerTestSuite(); 99 cts.addTestSuite(MimeTypesTests.class); 100 cts.addReadOnlySchemaDependency("com.jcorporate.expresso.core.ExpressoSchema"); 101 102 return cts; 103 } 104 105 109 public void testPopulatedTables() { 110 try { 111 MimeTypes mt = new MimeTypes(SecuredDBObject.SYSTEM_ACCOUNT); 112 mt.setDataContext(TestSystemInitializer.getTestContext()); 113 int number = mt.count(); 114 assertTrue( 115 "Should have " + mt.getExpectedDefaultPopulation() + " entries in the MIMETYPES table. Got:" + number + " instead", 116 number == mt.getExpectedDefaultPopulation()); 117 } catch (DBException dbe) { 118 super.getLog().error("Unable to execute count on MIMETYPES Table", 119 dbe); 120 fail("Unable to count mime type entries: " + dbe.getDBMessage()); 121 } 122 } 123 124 128 public void testJAFFileMapper() { 129 MimetypesFileTypeMap mftm = new MimetypesFileTypeMap (); 130 mftm.addMimeTypes("application/msword doc DOC rtf RTF"); 131 mftm.addMimeTypes("audio/mpeg3 mp3"); 132 String contentType = mftm.getContentType("test.doc"); 133 assertTrue("Must have appropriate content type", "application/msword".equals(contentType)); 134 contentType = mftm.getContentType("test.mp3"); 135 assertTrue("Must have appropriate content type", "audio/mpeg3".equals(contentType)); 136 137 } 138 139 143 public void testFileMapper() { 144 MimetypesFileTypeMap m = MimeTypes.getFileMap(TestSystemInitializer.getTestContext()); 145 assertTrue("Must receive a null MimetypesFileTypeMap", m != null); 146 147 String content = m.getContentType("test.mp3"); 148 assertTrue("Content type must be: audio/mpeg3. Got: " + content 149 + " instead.", "audio/mpeg3".equals(content)); 150 151 content = m.getContentType("test.pdf"); 152 assertTrue("Content type must be: application/pdf. Got: " + content 153 + " instead.", "application/pdf".equals(content)); 154 155 } 156 157 161 public void testFactoryMethod() { 162 try { 163 MimeTypes mt = MimeTypes.getMimeType("test.pdf", TestSystemInitializer.getTestContext()); 164 mt = MimeTypes.getMimeType("test.XLS", TestSystemInitializer.getTestContext()); 165 String content = mt.getField(MimeTypes.FLD_MIMETYPE); 166 assertTrue("Content type must be: application/vnd.ms-excel. Got: " + content 167 + " instead.", "application/vnd.ms-excel".equals(content)); 168 } catch (DBException ex) { 169 ex.printStackTrace(); 170 fail("Error constructing mimetypes object: " + ex.getMessage()); 171 } 172 173 } 174 } | Popular Tags |