Source Code Cross Referenced for ImageConverterTest.java in  » J2EE » JOnAS-4.8.6 » com » ibm » emb » test » mfb » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » com.ibm.emb.test.mfb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibm.emb.test.mfb;
002:
003:        // java stuff
004:        import java.io.File;
005:        import java.io.FileInputStream;
006:        import java.io.FileOutputStream;
007:        import java.io.IOException;
008:
009:        import javax.emb.MediaBean;
010:        import javax.emb.MediaConverter;
011:        import javax.emb.MediaConverterSpec;
012:        import javax.emb.MediaException;
013:        import javax.emb.MediaFormatRegistry;
014:
015:        import mfb.converters.BmpToJpegConverterSpec;
016:        import mfb.converters.JpegToBmpConverterSpec;
017:
018:        import org.objectweb.jonas.emb.mfb.converter.image.ImageConverter;
019:        import org.objectweb.jonas.emb.mfb.converter.image.ImageResizeConverterSpec;
020:        import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
021:
022:        import com.ibm.emb.junit.EMBTestRunner;
023:        import com.ibm.emb.test.MediaConverterTest;
024:
025:        public class ImageConverterTest extends MediaConverterTest {
026:
027:            /**
028:             * constructor
029:             */
030:            public ImageConverterTest(String name) throws MediaException {
031:                super (name);
032:            }
033:
034:            /**
035:             * main method
036:             */
037:            public static void main(String args[]) {
038:                EMBTestRunner.run(ImageConverterTest.class);
039:            }
040:
041:            /**
042:             * do initialisation here
043:             */
044:            protected void setUp() {
045:            }
046:
047:            /**
048:             * freeup resources
049:             */
050:            protected void tearDown() {
051:            }
052:
053:            /**
054:             * creates an instance of ImageConverter with the given Parameters used in
055:             * super class of ImageConverterTest
056:             */
057:            public MediaConverter createMediaConverter() throws MediaException {
058:
059:                // creates BmpToJpegConverterSpec
060:                MediaConverterSpec converterSpec = new BmpToJpegConverterSpec();
061:                // returns an ImageConverter
062:                return converterSpec.getConverter();
063:            }
064:
065:            /**
066:             * <pre>
067:             * 
068:             *  
069:             *   
070:             *        Testcase Name: convert(InputStream)
071:             *        Testcase Number: TEMB0100SBA  
072:             *        
073:             *        Test 1:
074:             *        
075:             *        create BmpToJpegConverterSpec
076:             *        query converter instance from converter spec using getConverter()
077:             *        call convert(InputStream) of converter passing FileInputStream on a bmp media
078:             *        create MediaBean with conversion result
079:             *        close FileInputStream and result stream
080:             *        --&gt; check for no exceptions
081:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
082:             *        
083:             *        
084:             *        Test 2:
085:             *        iterate over possible BMP color depths: 32, 24, 16, 8, 4, 1	{
086:             *        create JpegToBmpConverterSpec, specify color depth
087:             *        query converter instance from converter spec using getConverter()
088:             *        call convert(InputStream) of converter passing FileInputStream on a jpg media file
089:             *        create MediaBean with conversion result
090:             *        close FileInputStream and result stream
091:             *        --&gt; check for no exceptions
092:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
093:             *        
094:             *        Test 3:
095:             *        iterate over crop factors (0.4, 1.0, 2.5) and input files ( test.bmp , test.jpg ) {
096:             *        
097:             *        create ImageResizeConverterSpec, pass crop factor
098:             *        query converter instance from converter spec using getConverter()
099:             *        call convert(InputStream) of converter passing FileInputStream on input file
100:             *        create MediaBean with conversion result
101:             *        close FileInputStream and result stream
102:             *        --&gt; check for no exceptions
103:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
104:             *        
105:             *        Test 4:
106:             *        iterate over crop factor pairs (0.4/2.5, 1.0/1.0, 2.5/0.4) and input files (test.bmp, test.jpg ) {
107:             *        
108:             *        create ImageResizeConverterSpec, pass crop factor pair (horizontal/vertical)
109:             *        query converter instance from converter spec using getConverter()
110:             *        call convert(InputStream) of converter passing FileInputStream on input file
111:             *        create MediaBean with conversion result
112:             *        close FileInputStream and result stream
113:             *        --&gt; check for no exceptions
114:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
115:             *        }
116:             *        
117:             *        
118:             *        }
119:             *        
120:             *        
121:             *   
122:             *  
123:             * </pre>
124:             */
125:            public void testTEMB0100SBA() throws MediaException, IOException {
126:                // register media format
127:                MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
128:                formatRegistry.rebind("jpg", new JpegFormat());
129:
130:                // testinstance
131:                ImageConverter testInstance;
132:
133:                // converter specs
134:                JpegToBmpConverterSpec converterSpec;
135:                ImageResizeConverterSpec resizeConverterSpec;
136:
137:                // full path of the bmp sample
138:                String mediaBmpFullPath = embTestConfig.getMediaDir()
139:                        + File.separator + embTestConfig.getBmpPictureName1();
140:
141:                // full path of the jpg sample
142:                String mediaJpegFullPath = embTestConfig.getMediaDir()
143:                        + File.separator + embTestConfig.getJpgPictureName1();
144:
145:                // bmp input stream
146:                FileInputStream bmpInputStream;
147:
148:                // jpeg input stream
149:                FileInputStream jpegInputStream;
150:
151:                // test media
152:                MediaBean testMedia;
153:
154:                //
155:                // test 1
156:                //
157:
158:                /*
159:                 * try { // stream bmpInputStream = new
160:                 * FileInputStream(mediaBmpFullPath); // creates image converter
161:                 * testInstance = (ImageConverter) createMediaConverter(); // creates
162:                 * media bean with the result of conversion testMedia = new
163:                 * MediaBean(testInstance.process(bmpInputStream), "jpg", "testJpg");
164:                 * bmpInputStream.close(); JpegHeader testJpegHeader = (JpegHeader)
165:                 * testMedia.getHeader(); testTrace("test 1 passed"); succeed(); } catch
166:                 * (Exception e) { fail("test 1 : no exception expected, this is thrown : " +
167:                 * e.toString()); }
168:                 */
169:                //
170:                // test 2
171:                //
172:                byte[] colorDepth = { 32, 24, 16, 8, 4, 1 };
173:
174:                try {
175:                    for (int i = 0; i < colorDepth.length; i++) {
176:
177:                        // creates image converter
178:                        converterSpec = new JpegToBmpConverterSpec(
179:                                colorDepth[i]);
180:                        testInstance = (ImageConverter) converterSpec
181:                                .getConverter();
182:
183:                        // creates stream
184:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
185:
186:                        // creates media bean with the result of conversion
187:                        testMedia = new MediaBean(testInstance
188:                                .process(jpegInputStream), "bmp", "testBmp");
189:
190:                        // close stream stream
191:                        jpegInputStream.close();
192:                    }
193:                    testTrace("test 2 passed");
194:                    succeed();
195:                } catch (IllegalArgumentException e) {
196:                    fail("test 2 , thrown exception : " + e.toString());
197:                }
198:
199:                //
200:                // test 3
201:                //
202:
203:                double[] cropFactor = { 0.4, 1.0, 2.5 };
204:
205:                try {
206:                    for (int i = 0; i < cropFactor.length; i++) {
207:
208:                        // creates image converter
209:                        resizeConverterSpec = new ImageResizeConverterSpec(
210:                                cropFactor[i]);
211:                        testInstance = (ImageConverter) resizeConverterSpec
212:                                .getConverter();
213:
214:                        // create input streams
215:                        bmpInputStream = new FileInputStream(mediaBmpFullPath);
216:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
217:
218:                        // creates media bean with the result of conversion - BMP
219:                        testMedia = new MediaBean(testInstance
220:                                .process(jpegInputStream), "bmp", "testBmp");
221:
222:                        // error report
223:                        logProductError("consequence of a reported error PEMB0052RMD");
224:
225:                        // creates media bean with the result of conversion - JPEG
226:                        testMedia = new MediaBean(testInstance
227:                                .process(bmpInputStream), "jpg", "testJpeg");
228:
229:                        // close stream
230:                        jpegInputStream.close();
231:                        bmpInputStream.close();
232:                    }
233:                    testTrace("test 3 passed");
234:                    succeed();
235:                } catch (IllegalArgumentException e) {
236:                    fail("test 3 , thrown exception : " + e.toString());
237:                }
238:
239:                //
240:                // test 4
241:                //
242:
243:                double[][] cropFactor2 = { { 0.4, 2.5 }, { 1.0, 1.0 },
244:                        { 2.5, 0.4 } };
245:
246:                try {
247:                    for (int i = 0; i < cropFactor.length; i++) {
248:
249:                        // creates image converter
250:                        resizeConverterSpec = new ImageResizeConverterSpec(
251:                                cropFactor2[i][0], cropFactor2[i][1]);
252:                        testInstance = (ImageConverter) resizeConverterSpec
253:                                .getConverter();
254:
255:                        // create input streams
256:                        bmpInputStream = new FileInputStream(mediaBmpFullPath);
257:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
258:
259:                        // creates media bean with the result of conversion - BMP
260:                        testMedia = new MediaBean(testInstance
261:                                .process(jpegInputStream), "bmp", "testBmp");
262:
263:                        // creates media bean with the result of conversion - JPEG
264:                        testMedia = new MediaBean(testInstance
265:                                .process(bmpInputStream), "jpg", "testJpeg");
266:
267:                        // close stream
268:                        jpegInputStream.close();
269:                        bmpInputStream.close();
270:                    }
271:                    testTrace("test 3 passed");
272:                    succeed();
273:                } catch (IllegalArgumentException e) {
274:                    fail("test 3 , thrown exception : " + e.toString());
275:                }
276:
277:            }
278:
279:            /**
280:             * <pre>
281:             * 
282:             *  
283:             *   
284:             *        Testcase Name: convert(InputStream, OutputStream)
285:             *        Testcase Number: TEMB0101SBA  
286:             *        
287:             *        Test 1:
288:             *        
289:             *        create BmpToJpegConverterSpec
290:             *        query converter instance from converter spec using getConverter()
291:             *        call convert(InputStream) of converter passing FileInputStream on test.bmp, FileOutputStream on temporary file
292:             *        close FileInputStream and FileOutputStream
293:             *        create MediaBean with temporary file
294:             *        --&gt; check for no exceptions
295:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
296:             *        
297:             *        
298:             *        Test 2:
299:             *        iterate over possible BMP color depths: 32, 24, 16, 8, 4, 1	{
300:             *        create JpegToBmpConverterSpec, specify color depth
301:             *        query converter instance from converter spec using getConverter()
302:             *        call convert(InputStream) of converter passing FileInputStream on test.jpg, OutputStream on temporary file
303:             *        close FileInputStream and FileOutputStream
304:             *        create MediaBean with temporary file
305:             *        --&gt; check for no exceptions
306:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
307:             *        }
308:             *        
309:             *        
310:             *        Test 3:
311:             *        iterate over crop factors (0.4, 1.0, 2.5) and input files (test.bmp, test.jpg) {
312:             *        
313:             *        create ImageResizeConverterSpec, pass crop factor
314:             *        query converter instance from converter spec using getConverter()
315:             *        call convert(InputStream) of converter passing FileInputStream on input file, OutputStream on temporary file
316:             *        close FileInputStream and FileOutputStream
317:             *        create MediaBean with temporary file
318:             *        --&gt; check for no exceptions
319:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
320:             *        }
321:             *        
322:             *        
323:             *        Test 4:
324:             *        iterate over crop factor pairs (0.4/2.5, 1.0/1.0, 2.5/0.4) and input files (test.bmp,test.jpg) {
325:             *        
326:             *        create ImageResizeConverterSpec, pass crop factor pair (horizontal/vertical)
327:             *        query converter instance from converter spec using getConverter()
328:             *        call convert(InputStream) of converter passing FileInputStream on input file, OutputStream on temporary file
329:             *        close FileInputStream and FileOutputStream
330:             *        create MediaBean with temporary file
331:             *        --&gt; check for no exceptions
332:             *        --&gt; call getHeader() on media bean and check for no exceptions to verify format
333:             *        }
334:             *        
335:             *        
336:             *   
337:             *  
338:             * </pre>
339:             */
340:            public void testTEMB0101SBA() throws MediaException, IOException {
341:
342:                // register media format
343:                MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
344:                formatRegistry.rebind("jpg", new JpegFormat());
345:
346:                // testinstance
347:                ImageConverter testInstance;
348:
349:                // converter specs
350:                JpegToBmpConverterSpec converterSpec;
351:                ImageResizeConverterSpec resizeConverterSpec;
352:
353:                // full path of the bmp sample
354:                String mediaBmpFullPath = embTestConfig.getMediaDir()
355:                        + File.separator + embTestConfig.getBmpPictureName1();
356:
357:                // full path of the jpg sample
358:                String mediaJpegFullPath = embTestConfig.getMediaDir()
359:                        + File.separator + embTestConfig.getJpgPictureName1();
360:
361:                // temporary file
362:                File tempFile;
363:                File tempFile1;
364:
365:                // bmp input stream
366:                FileInputStream bmpInputStream;
367:
368:                // jpeg input stream
369:                FileInputStream jpegInputStream;
370:
371:                // temp output stream
372:                FileOutputStream tempOutputStream;
373:                FileOutputStream tempOutputStream1;
374:
375:                // test media
376:                MediaBean testMedia;
377:
378:                //
379:                // test 1
380:                //
381:
382:                // error report
383:                logProductError("consequence of a reported error PEMB0052RMD");
384:
385:                try {
386:                    // input stream
387:                    bmpInputStream = new FileInputStream(mediaBmpFullPath);
388:
389:                    // creates temp file
390:                    tempFile = File.createTempFile("test", "tmp");
391:
392:                    // creates output stream
393:                    tempOutputStream = new FileOutputStream(tempFile);
394:
395:                    // creates image converter
396:                    testInstance = (ImageConverter) createMediaConverter();
397:
398:                    // process conversion
399:                    testInstance.process(bmpInputStream, tempOutputStream);
400:
401:                    // close streams
402:                    tempOutputStream.close();
403:                    bmpInputStream.close();
404:
405:                    // creates media bean with the result of conversion
406:                    testMedia = new MediaBean(tempFile, "jpg");
407:
408:                    // JpegHeader testJpegHeader = (JpegHeader) testMedia.getHeader();
409:
410:                    // deletes temp file
411:                    tempFile.delete();
412:
413:                    testTrace("test 1 passed");
414:                    succeed();
415:                } catch (Exception e) {
416:                    fail("test 1 : no exception expected, this is thrown : "
417:                            + e.toString());
418:                }
419:
420:                //
421:                // test 2
422:                //
423:
424:                byte[] colorDepth = { 32, 24, 16, 8, 4, 1 };
425:
426:                try {
427:                    for (int i = 0; i < colorDepth.length; i++) {
428:
429:                        // creates image converter
430:                        converterSpec = new JpegToBmpConverterSpec(
431:                                colorDepth[i]);
432:                        testInstance = (ImageConverter) converterSpec
433:                                .getConverter();
434:
435:                        // creates temp file
436:                        tempFile = File.createTempFile("test", "tmp");
437:
438:                        // creates input stream
439:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
440:
441:                        // creates output stream
442:                        tempOutputStream = new FileOutputStream(tempFile);
443:
444:                        // process conversion
445:                        testInstance.process(jpegInputStream, tempOutputStream);
446:
447:                        // close streams
448:                        tempOutputStream.close();
449:                        jpegInputStream.close();
450:
451:                        // creates media bean with the result of conversion
452:                        testMedia = new MediaBean(tempFile, "bmp");
453:
454:                        // deletes temp file
455:                        tempFile.delete();
456:                    }
457:
458:                    testTrace("test 2 passed");
459:                    succeed();
460:                } catch (IllegalArgumentException e) {
461:                    fail("test 2 , thrown exception : " + e.toString());
462:                }
463:
464:                //
465:                // test 3
466:                //
467:
468:                double[] cropFactor = { 0.4, 1.0, 2.5 };
469:
470:                try {
471:                    for (int i = 0; i < cropFactor.length; i++) {
472:
473:                        // creates image converter
474:                        resizeConverterSpec = new ImageResizeConverterSpec(
475:                                cropFactor[i]);
476:                        testInstance = (ImageConverter) resizeConverterSpec
477:                                .getConverter();
478:
479:                        // creates temp files
480:                        tempFile = File.createTempFile("test", "tmp");
481:                        tempFile1 = File.createTempFile("test", "tmp");
482:
483:                        // create input streams
484:                        bmpInputStream = new FileInputStream(mediaBmpFullPath);
485:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
486:
487:                        // creates output streams
488:                        tempOutputStream = new FileOutputStream(tempFile);
489:                        tempOutputStream1 = new FileOutputStream(tempFile1);
490:
491:                        // makes conversion and creates media bean with the result of
492:                        // conversion - bmp temp file
493:                        testInstance.process(jpegInputStream, tempOutputStream);
494:
495:                        tempOutputStream.close();
496:                        jpegInputStream.close();
497:
498:                        testMedia = new MediaBean(tempFile, "bmp");
499:                        tempFile.delete();
500:
501:                        // makes conversion and creates media bean with the result of
502:                        // conversion - jpeg temp file
503:                        testInstance.process(bmpInputStream, tempOutputStream1);
504:
505:                        tempOutputStream1.close();
506:                        bmpInputStream.close();
507:
508:                        testMedia = new MediaBean(tempFile1, "jpg");
509:                        tempFile1.delete();
510:                    }
511:
512:                    testTrace("test 3 passed");
513:                    succeed();
514:                } catch (IllegalArgumentException e) {
515:                    fail("test 3 , thrown exception : " + e.toString());
516:                }
517:
518:                //
519:                // test 4
520:                //
521:
522:                double[][] cropFactor2 = { { 0.4, 2.5 }, { 1.0, 1.0 },
523:                        { 2.5, 0.4 } };
524:
525:                try {
526:                    for (int i = 0; i < cropFactor.length; i++) {
527:
528:                        // creates image converter
529:                        resizeConverterSpec = new ImageResizeConverterSpec(
530:                                cropFactor2[i][0], cropFactor2[i][1]);
531:                        testInstance = (ImageConverter) resizeConverterSpec
532:                                .getConverter();
533:
534:                        // creates temp files
535:                        tempFile = File.createTempFile("test", "tmp");
536:                        tempFile1 = File.createTempFile("test", "tmp");
537:
538:                        // create input streams
539:                        bmpInputStream = new FileInputStream(mediaBmpFullPath);
540:                        jpegInputStream = new FileInputStream(mediaJpegFullPath);
541:
542:                        // creates output streams
543:                        tempOutputStream = new FileOutputStream(tempFile);
544:                        tempOutputStream1 = new FileOutputStream(tempFile1);
545:
546:                        // makes conversion and creates media bean with the result of
547:                        // conversion - bmp temp file
548:                        testInstance.process(jpegInputStream, tempOutputStream);
549:
550:                        tempOutputStream.close();
551:                        jpegInputStream.close();
552:
553:                        testMedia = new MediaBean(tempFile, "bmp");
554:                        tempFile.delete();
555:
556:                        // makes conversion and creates media bean with the result of
557:                        // conversion - jpeg temp file
558:                        testInstance.process(bmpInputStream, tempOutputStream1);
559:
560:                        tempOutputStream1.close();
561:                        bmpInputStream.close();
562:
563:                        testMedia = new MediaBean(tempFile1, "jpg");
564:                        tempFile1.delete();
565:                    }
566:
567:                    testTrace("test 4 passed");
568:                    succeed();
569:                } catch (IllegalArgumentException e) {
570:                    fail("test 4 , thrown exception : " + e.toString());
571:                }
572:
573:            }
574:
575:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.