Source Code Cross Referenced for MediaBeanTest.java in  » J2EE » JOnAS-4.8.6 » com » ibm » emb » test » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibm.emb.test;
002:
003:        import java.io.File;
004:        import java.io.FileInputStream;
005:        import java.io.IOException;
006:        import java.io.InputStream;
007:        import java.util.zip.GZIPInputStream;
008:
009:        import javax.emb.ContentAccessException;
010:        import javax.emb.GenericMediaFormat;
011:        import javax.emb.Media;
012:        import javax.emb.MediaBean;
013:        import javax.emb.MediaException;
014:        import javax.emb.MediaFormatRegistry;
015:
016:        import org.objectweb.jonas.emb.mfb.formats.video.MpegVideoFormat;
017:
018:        import com.ibm.emb.junit.EMBTestRunner;
019:
020:        /**
021:         * <pre>
022:         *
023:         *
024:         *
025:         *     Line Item: MFB API
026:         *     Subcategory 1: javax.emb
027:         *     Subcategory 2: MediaBean
028:         *
029:         *     This is the test class for javax.emb.MediaBean.  Many of the tests
030:         *     are implemented in the super class MediaTest and only a few initialization
031:         *     methods are provided here.
032:         *
033:         *
034:         *
035:         * </pre>
036:         */
037:        public class MediaBeanTest extends MediaTest {
038:
039:            public MediaBeanTest(String name) throws MediaException {
040:                super (name);
041:            }
042:
043:            public static void main(String args[]) {
044:                EMBTestRunner.run(MediaBeanTest.class);
045:            }
046:
047:            /**
048:             * creates an instance of MediaBean with the given parameters used in super
049:             * class of MediaTest
050:             */
051:            public Media createMedia(File inputFile, String mimeType)
052:                    throws MediaException {
053:                return new MediaBean(inputFile, mimeType);
054:            }
055:
056:            /**
057:             * creates an instance of MediaBean with the given parameters used in super
058:             * class of MediaTest
059:             */
060:            public Media createMedia(InputStream in, String mimeType,
061:                    String name) throws MediaException {
062:                return new MediaBean(in, mimeType, name);
063:            }
064:
065:            /**
066:             * <pre>
067:             *
068:             *
069:             *
070:             *    Testcase Name: MediaBean(File mediaFile, String mimeType)
071:             *    Testcase Number: EMB011
072:             *
073:             *    setup: media has to be provided in local file system
074:             *
075:             *    test procedure:
076:             *    I.
077:             *    a) java.io.file pointing to media file is provided in the constructor call.
078:             *    	-&gt;1.instance is created
079:             *     -&gt;2.mimetype is queried and verified
080:             *    	-&gt;3.media file content size is checked by comparing byte array size and file size.
081:             *     -&gt;4.Media.getName is not null and name contains exactly 1 dot.
082:             *    b) provide null as mime-type  -&gt;  same as getFormat().getDefaultMimeType()
083:             *    c) provide &quot;test&quot; as mime-type -&gt; &quot;test&quot;
084:             *
085:             *    II. call MediaBean(null, null) -&gt; NullPointerException
086:             *
087:             *    III. call MediaBean with nonexistent file and null mimetype -&gt; ContentAccessException
088:             *
089:             *
090:             *
091:             * </pre>
092:             */
093:            public void testEMB011() throws IOException, MediaException {
094:                File mpegTestFile = new File(embTestConfig.getMediaDir()
095:                        + File.separatorChar
096:                        + embTestConfig.getMpegMovieName1());
097:
098:                // register media format
099:                javax.emb.MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
100:                formatRegistry.rebind("mpeg", new MpegVideoFormat());
101:                formatRegistry.rebind("test", new GenericMediaFormat());
102:
103:                MediaBean testInstance = new MediaBean(mpegTestFile,
104:                        "video/mpeg");
105:                //
106:                // test I a1
107:                //
108:                assertNotNull("test I a1: ", testInstance);
109:                testTrace("test I a1 passed");
110:                //
111:                // test I a2
112:                //
113:                assertEquals("test I a2: ", "video/mpeg", testInstance
114:                        .getMimeType());
115:                testTrace("test I a2 passed");
116:                //
117:                // test I a3
118:                //
119:                assertEquals("test I a3: ", mpegTestFile.length(), testInstance
120:                        .getSize());
121:                testTrace("test I a3 passed");
122:                //
123:                // test I a4
124:                //
125:                int index = testInstance.getName().indexOf(".");
126:                int postIndex = testInstance.getName().indexOf(".", index + 1);
127:                assertTrue("test I a4 :", (testInstance.getName() != null)
128:                        && ((index != -1) && (postIndex == -1)));
129:                testTrace("test I a4 passed");
130:                //
131:                // test I b
132:                //
133:                //
134:                testInstance = new MediaBean(mpegTestFile, null);
135:                assertEquals("test I b: ", testInstance.getFormat()
136:                        .getDefaultMimeType(), testInstance.getMimeType());
137:                testTrace("test I b passed");
138:                //
139:                // test I c
140:                //
141:                testInstance = new MediaBean(mpegTestFile, "test");
142:                assertEquals("test I c: ", "test", testInstance.getMimeType());
143:                testTrace("test I c passed");
144:                //
145:                // test II
146:                //
147:                try {
148:                    testInstance = new MediaBean(null, "test");
149:                    fail("test II : Should throw a NullPointerException");
150:                } catch (NullPointerException e) {
151:                    testTrace("test II passed");
152:                } catch (Exception e) {
153:                    fail("test II: Should throw a NullPointerException but threw "
154:                            + e.toString());
155:                }
156:                //
157:                // test III
158:                //
159:                try {
160:                    testInstance = new MediaBean(new File(
161:                            "nonexistingFile.mpeg"), "mpeg");
162:                    fail("test III: Should throw an ContentAccessException");
163:                } catch (javax.emb.ContentAccessException e) {
164:                    testTrace("test III passed");
165:                } catch (Exception e) {
166:                    fail("test III: Should throw a ContentAccessException but threw "
167:                            + e.toString());
168:                }
169:
170:                succeed();
171:            }
172:
173:            /**
174:             * <pre>
175:             *
176:             *
177:             *
178:             *    Testcase Name: MediaBean(InputStream contentStream, String mimeType, String name)
179:             *    Testcase Number: EMB012
180:             *
181:             *    setup: input stream has to be provided by using a file input stream
182:             *
183:             *    test procedure:
184:             *    I.
185:             *    a)mimetype is null
186:             *    	  -&gt;1.mimetype = getFormat().getDefaultMimeType()
187:             *    	  -&gt;2.stream content size is checked by comparing byte array size of Media.getContent() and stream size
188:             *    b)mimetype is &quot;test&quot; (parameter &quot;name&quot; has to be != null) -&gt; mimetype = &quot;test&quot;
189:             *
190:             *    II. contentStream is null -&gt; NullPointerException
191:             *
192:             *    III. name is null -&gt; NullPointerException
193:             *
194:             *    IV. create MediaBean using input stream from corrupt GZIP file (can open but not read)
195:             *     	-&gt; ContentAccessException
196:             *
197:             *
198:             *
199:             * </pre>
200:             */
201:            public void testEMB012() throws IOException, MediaException {
202:
203:                MediaBean testInstance = null;
204:                // file input stream
205:                FileInputStream fileInputStream = new FileInputStream(
206:                        embTestConfig.getMediaDir() + File.separatorChar
207:                                + embTestConfig.getMpegMovieName1());
208:
209:                // register media format
210:                javax.emb.MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
211:                formatRegistry.rebind("test",
212:                        new javax.emb.GenericMediaFormat());
213:                formatRegistry.rebind("mpeg", new MpegVideoFormat());
214:
215:                //
216:                // test 1 a
217:                //
218:                int streamSize = 0;
219:                while (fileInputStream.read() != -1) {
220:                    streamSize++;
221:                }
222:                fileInputStream.close();
223:                fileInputStream = new FileInputStream(embTestConfig
224:                        .getMediaDir()
225:                        + File.separatorChar
226:                        + embTestConfig.getMpegMovieName1());
227:                testInstance = new MediaBean(fileInputStream, null, "test.mpeg");
228:                assertEquals("test I a1: ", testInstance.getFormat()
229:                        .getDefaultMimeType(), testInstance.getMimeType());
230:                assertEquals("test I a2: ", streamSize, testInstance.getSize());
231:                testTrace("test I a passed");
232:                //
233:                // test 1 b
234:                //
235:                fileInputStream = new FileInputStream(embTestConfig
236:                        .getMediaDir()
237:                        + File.separatorChar
238:                        + embTestConfig.getMpegMovieName1());
239:                testInstance = new MediaBean(fileInputStream, "test",
240:                        "test.mpeg");
241:                assertEquals("test I b: ", "test", testInstance.getMimeType());
242:                testTrace("test I b passed");
243:                //
244:                // test 2
245:                //
246:                try {
247:                    testInstance = new MediaBean(null, "test", "test.mpeg");
248:                    fail(" test II: Should throw a NullPointerException");
249:                } catch (NullPointerException e) {
250:                    testTrace("test II passed");
251:                } catch (Exception e) {
252:                    fail("test II: should throw a NullPointerException but threw "
253:                            + e.toString());
254:                }
255:                //
256:                // test 3
257:                //
258:                fileInputStream = new FileInputStream(embTestConfig
259:                        .getMediaDir()
260:                        + File.separatorChar
261:                        + embTestConfig.getMpegMovieName1());
262:                try {
263:                    testInstance = new MediaBean(fileInputStream, "test", null);
264:                    fail(" test III: Should throw a NullPointerException");
265:                } catch (NullPointerException e) {
266:                    testTrace("test III passed");
267:                } catch (Exception e) {
268:                    fail("test III: Should throw a NullPointerException but threw "
269:                            + e.toString());
270:                }
271:                fileInputStream.close();
272:                //
273:                // test 4
274:                //
275:                String gzipFile = embTestConfig.getGzipCorruptFileName();
276:                String gzipFileFullPath = embTestConfig.getMediaDir()
277:                        + File.separatorChar + gzipFile;
278:                GZIPInputStream inputStream = new GZIPInputStream(
279:                        new FileInputStream(gzipFileFullPath));
280:                try {
281:                    testInstance = new MediaBean(inputStream, "video/mpeg",
282:                            "testMpeg.mpeg");
283:                    fail("test IV: Should throw a ContentAccessException");
284:                } catch (ContentAccessException e) {
285:                    testTrace("test IV passed");
286:                } catch (Exception e) {
287:                    fail("test IV: Should throw a ContentAccessException but threw "
288:                            + e.toString());
289:                }
290:                inputStream.close();
291:
292:                succeed();
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.