Source Code Cross Referenced for MediaHeaderTest.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.StringTokenizer;
008:
009:        import javax.emb.MediaException;
010:        import javax.emb.MediaFormat;
011:        import javax.emb.MediaFormatRegistry;
012:        import javax.emb.MediaHeader;
013:
014:        import junit.framework.Test;
015:        import junit.framework.TestSuite;
016:
017:        import com.ibm.emb.junit.EMBStaticHelper;
018:        import com.ibm.emb.junit.EMBTestCaseBase;
019:
020:        /**
021:         * <pre>
022:         * 
023:         *  
024:         *   
025:         *    Line Item: MFB API 
026:         *    Subcategory 1: javax.emb
027:         *    Subcategory 2: MediaHeader
028:         *    
029:         *   
030:         *  
031:         * </pre>
032:         */
033:        public abstract class MediaHeaderTest extends EMBTestCaseBase {
034:
035:            public MediaHeaderTest(String name) throws MediaException {
036:                super (name);
037:            }
038:
039:            /**
040:             * stdSuite method of this test class instantiates all tests necesssary to
041:             * for the standard compliance tests
042:             * @param String complete class Name of the implementor of the abstract test
043:             */
044:            public static Test stdSuite(String TestCaseImplementor) {
045:                TestSuite suite = new TestSuite(TestCaseImplementor);
046:                try {
047:                    Class implementorClass = Class.forName(TestCaseImplementor);
048:                    java.lang.reflect.Constructor implementorConstructor = implementorClass
049:                            .getDeclaredConstructor(new Class[] { String.class });
050:                    suite.addTest((Test) implementorConstructor
051:                            .newInstance(new String[] { "testEMB037" }));
052:                    suite.addTest((Test) implementorConstructor
053:                            .newInstance(new String[] { "testEMB038" }));
054:                } catch (java.lang.reflect.InvocationTargetException ex) {
055:                    String msg = "error dynamically creating "
056:                            + TestCaseImplementor + " " + ex.toString();
057:                    EMBStaticHelper.testTrace(msg);
058:                    throw new RuntimeException(msg);
059:                } catch (ClassNotFoundException ex) {
060:                    String msg = "Class not found " + TestCaseImplementor + " "
061:                            + ex.toString();
062:                    EMBStaticHelper.testTrace(msg);
063:                    throw new RuntimeException(msg);
064:                } catch (NoSuchMethodException ex) {
065:                    String msg = "No such method in " + TestCaseImplementor
066:                            + " " + ex.toString();
067:                    EMBStaticHelper.testTrace(msg);
068:                    throw new RuntimeException(msg);
069:                } catch (InstantiationException ex) {
070:                    String msg = TestCaseImplementor + " " + ex.toString();
071:                    EMBStaticHelper.testTrace(msg);
072:                    throw new RuntimeException(msg);
073:                } catch (IllegalAccessException ex) {
074:                    String msg = TestCaseImplementor + " " + ex.toString();
075:                    EMBStaticHelper.testTrace(msg);
076:                    throw new RuntimeException(msg);
077:                }
078:                return suite;
079:            }
080:
081:            /**
082:             * abstract method to create an instance of mediaHeader with no parameters
083:             * this method needs to be implemented in the test subclass and will create
084:             * an instance of the concrete implementation of the class under test
085:             */
086:            public abstract MediaHeader createMediaHeader()
087:                    throws MediaException, IOException;
088:
089:            /**
090:             * <pre>
091:             * 
092:             *  
093:             *   
094:             *    Testcase Name: getField(String fieldName)
095:             *    Testcase Number: EMB037
096:             *    
097:             *    setup: access file containing a list of all implemented Media formats and sample files
098:             *    
099:             *    test procedure:
100:             *    1.for each format, call extractHeader().getField(null)
101:             *      expected result: NullPointerException
102:             *    
103:             *    2.for each format, call extractHeader().getField(&quot;%$&amp;//&amp;%?%&amp;&quot;)
104:             *      expected result: null
105:             *    
106:             *    3.for each format, call extractHeader().getFieldNames()
107:             *      for each field, call getField()
108:             *      expected result: not null
109:             *    
110:             *   
111:             *  
112:             * </pre>
113:             */
114:            public void testEMB037() throws MediaException, IOException {
115:
116:                // retrieve Media formats
117:                String allMediaFormats = embTestConfig.getAllMediaFormats();
118:                allMediaFormats = allMediaFormats.trim();
119:
120:                // token individual Media formats
121:                StringTokenizer mediaTokenizer = new StringTokenizer(
122:                        allMediaFormats, ";");
123:                String formatInfo = null;
124:                StringTokenizer formatInfoTokenizer = null;
125:
126:                while (mediaTokenizer.hasMoreTokens()) {
127:                    formatInfo = mediaTokenizer.nextToken();
128:                    formatInfoTokenizer = new StringTokenizer(formatInfo);
129:
130:                    assertEquals(
131:                            "test initialization: allMediaFormats property not properly formatted",
132:                            3, formatInfoTokenizer.countTokens());
133:
134:                    String fullClassName = formatInfoTokenizer.nextToken();
135:                    String fileExtension = formatInfoTokenizer.nextToken();
136:                    String mediaFileName = formatInfoTokenizer.nextToken();
137:
138:                    String mediaFullPath = embTestConfig.getMediaDir()
139:                            + File.separator + mediaFileName;
140:
141:                    try {
142:                        File mediaFile = new File(mediaFullPath);
143:                        InputStream mediaFileInputStream = new FileInputStream(
144:                                mediaFile);
145:                        MediaFormat mediaFormat = (MediaFormat) Class.forName(
146:                                fullClassName).newInstance();
147:                        MediaHeader testInstance = mediaFormat
148:                                .extractHeader(mediaFileInputStream);
149:                        mediaFileInputStream.close();
150:                        MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
151:                        formatRegistry.rebind(fileExtension,
152:                                (MediaFormat) Class.forName(fullClassName)
153:                                        .newInstance());
154:
155:                        //
156:                        // test 1
157:                        //
158:                        try {
159:                            testInstance.getField(null);
160:                            fail("[" + testInstance.getClass().getName()
161:                                    + "] test 1: "
162:                                    + "Should throw a NullPointerException");
163:                        } catch (NullPointerException e) {
164:                            testTrace("[" + testInstance.getClass().getName()
165:                                    + "] test 1 passed");
166:                        } catch (Exception e) {
167:                            fail("["
168:                                    + testInstance.getClass().getName()
169:                                    + "] test 1: "
170:                                    + "Should throw a NullPointerException but threw "
171:                                    + e.toString());
172:                        }
173:                        //
174:                        // test 2
175:                        //
176:                        assertNull("[" + testInstance.getClass().getName()
177:                                + "] test 2: ", testInstance
178:                                .getField("%$&//&%?%&"));
179:                        testTrace("[" + testInstance.getClass().getName()
180:                                + "] test 2 passed");
181:                        //
182:                        // test 3
183:                        //
184:                        String[] fieldNames = testInstance.getFieldNames();
185:                        for (int i = 0; i < fieldNames.length; i++) {
186:                            assertNotNull("["
187:                                    + testInstance.getClass().getName()
188:                                    + "] test 3: ", testInstance
189:                                    .getField(fieldNames[i]));
190:                        }
191:                        testTrace("[" + testInstance.getClass().getName()
192:                                + "] test 3 passed");
193:
194:                    } catch (ClassNotFoundException e) {
195:                        fail("Class not found: " + e.getMessage());
196:                    } catch (IllegalAccessException e) {
197:                        fail("Illegal access: " + e.getMessage());
198:                    } catch (InstantiationException e) {
199:                        fail("Instantiation exception; " + e.getMessage());
200:                    }
201:                }
202:                succeed();
203:            }
204:
205:            /**
206:             * <pre>
207:             * 
208:             *  
209:             *   
210:             *    Testcase Name: getFieldNames()
211:             *    Testcase Number: EMB038
212:             *    
213:             *    setup: access file containing a list of all implemented Media formats and sample files
214:             *    
215:             *    test procedure:
216:             *    1.for each format, call extractHeader.getFieldNames()
217:             *      expected result: not null
218:             *    
219:             *   
220:             *  
221:             * </pre>
222:             */
223:            public void testEMB038() throws MediaException, IOException {
224:                // retrieve Media formats
225:                String allMediaFormats = embTestConfig.getAllMediaFormats();
226:                allMediaFormats = allMediaFormats.trim();
227:
228:                // token individual Media formats
229:                StringTokenizer mediaTokenizer = new StringTokenizer(
230:                        allMediaFormats, ";");
231:                String formatInfo = null;
232:                StringTokenizer formatInfoTokenizer = null;
233:
234:                while (mediaTokenizer.hasMoreTokens()) {
235:                    formatInfo = mediaTokenizer.nextToken();
236:                    formatInfoTokenizer = new StringTokenizer(formatInfo);
237:
238:                    assertEquals("test initialization: ", 3,
239:                            formatInfoTokenizer.countTokens());
240:
241:                    String fullClassName = formatInfoTokenizer.nextToken();
242:                    String fileExtension = formatInfoTokenizer.nextToken();
243:                    String mediaFileName = formatInfoTokenizer.nextToken();
244:
245:                    String mediaFullPath = embTestConfig.getMediaDir()
246:                            + File.separator + mediaFileName;
247:
248:                    try {
249:                        File mediaFile = new File(mediaFullPath);
250:                        InputStream mediaFileInputStream = new FileInputStream(
251:                                mediaFile);
252:                        MediaFormat mediaFormat = (MediaFormat) Class.forName(
253:                                fullClassName).newInstance();
254:                        MediaHeader testInstance = mediaFormat
255:                                .extractHeader(mediaFileInputStream);
256:                        mediaFileInputStream.close();
257:                        MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
258:                        formatRegistry.rebind(fileExtension,
259:                                (MediaFormat) Class.forName(fullClassName)
260:                                        .newInstance());
261:
262:                        //
263:                        // test 1
264:                        //
265:                        assertNotNull("[" + testInstance.getClass().getName()
266:                                + "] test 1: ", testInstance.getFieldNames());
267:                        testTrace("[" + testInstance.getClass().getName()
268:                                + "] test 1 passed");
269:
270:                    } catch (ClassNotFoundException e) {
271:                        fail("Class not found: " + e.getMessage());
272:                    } catch (IllegalAccessException e) {
273:                        fail("Illegal access: " + e.getMessage());
274:                    } catch (InstantiationException e) {
275:                        fail("Instantiation exception; " + e.getMessage());
276:                    }
277:                }
278:
279:                succeed();
280:            }
281:
282:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.