001: package com.ibm.emb.test;
002:
003: import java.util.Iterator;
004:
005: import javax.emb.FormatAlreadyBoundException;
006: import javax.emb.FormatNotFoundException;
007: import javax.emb.GenericMediaFormat;
008: import javax.emb.MediaException;
009: import javax.emb.MediaFormat;
010: import javax.emb.MediaFormatRegistry;
011:
012: import org.objectweb.jonas.emb.mfb.formats.image.BmpFormat;
013: import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
014:
015: import com.ibm.emb.junit.EMBStaticHelper;
016: import com.ibm.emb.junit.EMBTestCaseBase;
017: import com.ibm.emb.junit.EMBTestRunner;
018:
019: /**
020: * <pre>
021: *
022: *
023: *
024: * Line Item: MFB API
025: * Subcategory 1: javax.emb
026: * Subcategory 2: MediaFormatRegistry
027: *
028: *
029: *
030: * </pre>
031: */
032: public class MediaFormatRegistryTest extends EMBTestCaseBase {
033:
034: public MediaFormatRegistryTest(String name) throws MediaException {
035: super (name);
036: }
037:
038: public static void main(String args[]) {
039: EMBTestRunner.run(MediaFormatRegistryTest.class);
040: }
041:
042: /**
043: * <pre>
044: *
045: *
046: *
047: * Testcase Name: MediaFormatRegistry.SINGLETON
048: * Testcase Number: EMB027
049: *
050: * setup:
051: *
052: * test procedure:
053: * 1.access MediaFormatRegistry.SINGLETON
054: * expected result: not null
055: *
056: *
057: *
058: * </pre>
059: */
060: public void testEMB027() throws MediaException {
061: //
062: // test 1
063: //
064: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
065: assertNotNull("test 1: ", testInstance);
066: testTrace("test 1 passed");
067: succeed();
068: }
069:
070: /**
071: * <pre>
072: *
073: *
074: *
075: * Testcase Name: bind(String fileExtension, MediaFormat mediaFormat)
076: * Testcase Number: EMB028
077: *
078: * setup:
079: *
080: * test procedure:
081: * 1.access MediaFormatRegistry.SINGLETON
082: * call bind passing null as fileExtension and GenericMediaFormat instance as format
083: * expected resul: NullPointerException
084: *
085: * 2.access MediaFormatRegistry.SINGLETON
086: * call bind passing random string as fileExtension and null as format
087: * expected result: NullPointerException
088: *
089: * 3.access MediaFormatRegistry.SINGLETON
090: * call bind passing "TEST1" as fileExtension and GenericMediaFormat instance as format
091: * call bind passing "TEST1" as fileExtension and other GenericMediaFormat instance as format
092: * expected result: FormatAlreadyBoundException on second call
093: *
094: * 4.bind passing valid file extension and GenericMediaFormat
095: * call lookup on file extenstion
096: * expected result: instance of GenericMediaFormat
097: *
098: * 5.bind empty string with GenericMediaFormat
099: * expected result: no exception and lookup("") returns instance of GenericMediaFormat
100: *
101: *
102: *
103: * </pre>
104: */
105: public void testEMB028() throws MediaException {
106: //
107: // test 1
108: //
109: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
110: try {
111: testInstance.bind(null, new GenericMediaFormat());
112: fail("test 1: Should throw a NullPointerException");
113: } catch (NullPointerException e) {
114: testTrace("test 1 passed");
115: } catch (Exception e) {
116: fail("test 1: Should throw a NullPointerException but threw "
117: + e.toString());
118: }
119: //
120: // test 2
121: //
122: try {
123: testInstance.bind(
124: EMBStaticHelper.createRandomString(EMBStaticHelper
125: .randomInt(1, 3)), null);
126: fail("test 2: Should throw a NullPointerException");
127: } catch (NullPointerException e) {
128: testTrace("test 2 passed");
129: } catch (Exception e) {
130: fail("test 2: Should throw a NullPointerException but threw "
131: + e.toString());
132: }
133: //
134: // test 3
135: //
136: try {
137: testInstance.bind("TEST1", new GenericMediaFormat());
138: testInstance.bind("TEST1", new GenericMediaFormat());
139: fail("test 3: Should throw FormatAlreadyBoundException");
140: } catch (FormatAlreadyBoundException e) {
141: testTrace("test 3 passed");
142: } catch (Exception e) {
143: fail("test 3: Should throw a FormatAlreadyBoundException but threw"
144: + e.toString());
145: }
146: //
147: // test 4
148: //
149: try {
150: testInstance.unbind("TEST2");
151: } catch (FormatNotFoundException e) {
152: }
153: testInstance.bind("TEST2", new GenericMediaFormat());
154: assertTrue("test 4: format does not match", testInstance
155: .lookup("TEST2") instanceof GenericMediaFormat);
156: testTrace("test 4 passed");
157: //
158: // test 5
159: //
160: try {
161: testInstance.unbind("");
162: } catch (FormatNotFoundException e) {
163: }
164: testInstance.bind("", new GenericMediaFormat());
165: assertTrue("test 5: format does not match", testInstance
166: .lookup("") instanceof GenericMediaFormat);
167: testTrace("test 5 passed");
168:
169: succeed();
170: }
171:
172: /**
173: * <pre>
174: *
175: *
176: *
177: * Testcase Name: getFileExtensions()
178: * Testcase Number: EMB029
179: *
180: * setup:
181: *
182: * test procedure:
183: * 1.access MediaFormatRegistry.SINGLETON
184: * bind fileExtensions "test1", "test2", and "test3" to GenericMediaFormat
185: * call getFileExtensions
186: * expected result: list contains test1, test2, test3
187: *
188: *
189: *
190: * </pre>
191: */
192: public void testEMB029() throws MediaException {
193: //
194: // test 1
195: //
196: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
197: testInstance.rebind("test1", new GenericMediaFormat());
198: testInstance.rebind("test2", new GenericMediaFormat());
199: testInstance.rebind("test3", new GenericMediaFormat());
200:
201: Iterator fileExtensions = testInstance.getFileExtensions();
202: boolean test1 = false;
203: boolean test2 = false;
204: boolean test3 = false;
205: while (fileExtensions.hasNext()) {
206: Object ext = fileExtensions.next();
207: if (ext.toString().equals("test1")) {
208: test1 = true;
209: } else if (ext.toString().equals("test2")) {
210: test2 = true;
211: } else if (ext.toString().equals("test3")) {
212: test3 = true;
213: }
214: }
215: assertTrue(test1);
216: assertTrue(test2);
217: assertTrue(test3);
218: testTrace("test 1 passed");
219:
220: succeed();
221: }
222:
223: /**
224: * <pre>
225: *
226: *
227: *
228: * Testcase Name: lookup(String fileExtension)
229: * Testcase Number: EMB030
230: *
231: * setup:
232: *
233: * test procedure:
234: * 1.access MediaFormatRegistry.SINGLETON, call lookup(null)
235: * expected result: NullPointerException
236: *
237: * 2.access MediaFormatRegistry.SINGLETON
238: * call unbind("test1") (catch FormatNotFoundException)
239: * call lookup passing "test1"
240: * expected result: FormatNotFoundException
241: *
242: * 3.access MediaFormatRegistry.SINGLETON
243: * call rebind("test2", new GenericMediaFormat())
244: * call lookup("test2")
245: * expected result: instance of GenericMediaFormat()
246: *
247: *
248: *
249: * </pre>
250: */
251: public void testEMB030() throws MediaException {
252: //
253: // test 1
254: //
255: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
256: try {
257: testInstance.lookup(null);
258: fail("test 1: Should throw a NullPointerException");
259: } catch (NullPointerException e) {
260: testTrace("test 1 passed");
261: } catch (Exception e) {
262: fail("test 1: Should throw a NullPointerExceptin but threw "
263: + e.toString());
264: }
265: //
266: // test 2
267: //
268: try {
269: testInstance.unbind("test1");
270: } catch (FormatNotFoundException e) {
271: }
272:
273: try {
274: MediaFormat testFormat = testInstance.lookup("test1");
275: fail("test 2: Should throw a FormatNotFoundException");
276: } catch (FormatNotFoundException e) {
277: testTrace("test 2 passed");
278: } catch (Exception e) {
279: fail("test 2: Should throw A FormatNotFoundException but threw "
280: + e.toString());
281: }
282: //
283: // test 3
284: //
285: testInstance = MediaFormatRegistry.SINGLETON;
286: testInstance.rebind("test1", new GenericMediaFormat());
287: MediaFormat testFormat = testInstance.lookup("test1");
288: assertEquals("test 3: ", testFormat.getClass(),
289: new GenericMediaFormat().getClass());
290: testTrace("test 3 passed");
291:
292: succeed();
293: }
294:
295: /**
296: * <pre>
297: *
298: *
299: *
300: * Testcase Name: rebind(String fileExtension, MediaFormat mediaFormat)
301: * Testcase Number: EMB031
302: *
303: * setup:
304: *
305: * test procedure:
306: * 1.call rebind with null fileExtension and instance of GenericMediaFormat
307: * expected result: NullPointerException
308: *
309: * 2.call rebind with random string and null format
310: * expected result: NullPointerException
311: *
312: * 3.call bind with fileExtension "test" and JpegFormat
313: * call rebind with fileExtension "test" and BmpFormat
314: * call lookup("test")
315: * expected result: instance of BmpFormat
316: *
317: * 4.call unbind with random fileExtension
318: * call rebind with random fileExtension and GenericMediaFormat
319: * call lookup with fileExtension
320: * expected result: instance of GenericMediaFormat
321: *
322: *
323: *
324: * </pre>
325: */
326: public void testEMB031() throws MediaException {
327: //
328: // test 1
329: //
330: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
331: try {
332: testInstance.rebind(null, new GenericMediaFormat());
333: fail("test 1: Should throw a NullPointerException");
334: } catch (NullPointerException e) {
335: testTrace("test 1 passed");
336: } catch (Exception e) {
337: fail("test 1: Should throw a NullPointerException but threw "
338: + e.toString());
339: }
340: //
341: // test 2
342: //
343: try {
344: testInstance.rebind(
345: EMBStaticHelper.createRandomString(EMBStaticHelper
346: .randomInt(1, 3)), null);
347: fail("test 2: Should throw a NullPointerException");
348: } catch (NullPointerException e) {
349: testTrace("test 2 passed");
350: } catch (Exception e) {
351: fail("test 2: Should throw a NullPointerException but threw "
352: + e.toString());
353: }
354: //
355: // test 3
356: //
357: testInstance = MediaFormatRegistry.SINGLETON;
358: testInstance.rebind("test", new JpegFormat());
359: testInstance.rebind("test", new BmpFormat());
360:
361: MediaFormat testFormat = testInstance.lookup("test");
362: assertTrue("test 3: ", testFormat instanceof BmpFormat);
363: testTrace("test 3 passed");
364: //
365: // test 4
366: //
367: String fileExt = EMBStaticHelper
368: .createRandomString(EMBStaticHelper.randomInt(1, 3));
369: testInstance = MediaFormatRegistry.SINGLETON;
370: try {
371: testInstance.unbind(fileExt);
372: } catch (FormatNotFoundException e) {
373: }
374:
375: testInstance.rebind(fileExt, new GenericMediaFormat());
376: testFormat = testInstance.lookup(fileExt);
377: assertTrue("test 4: ", testFormat instanceof GenericMediaFormat);
378: testTrace("test 4 passed");
379:
380: succeed();
381: }
382:
383: /**
384: * <pre>
385: *
386: *
387: *
388: * Testcase Name: unbind(String fileExtension)
389: * Testcase Number: EMB032
390: *
391: * setup:
392: *
393: * test procedure:
394: * 1.access MediaFormatRegistry.SINGLETON
395: * call unbind passing null
396: * expected result: NullPointerException
397: *
398: * 2.access MediaFormatRegistry.SINGLETON
399: * call unbind("test"), catch FormatNotFoundExceptin
400: * call unbind("test")
401: * expected result: FormatNotFoundException
402: *
403: * 3.access MediaFormatRegistry.SINGLETON
404: * call bind passing "test1" and GenericMediaFormat
405: * call bind passing "test2" and GenericMediaFormat
406: * call unbind passing "test1"
407: * call unbind passing "test2"
408: * expected result: no exception
409: *
410: *
411: *
412: * </pre>
413: */
414: public void testEMB032() throws MediaException {
415: //
416: // test 1
417: //
418: MediaFormatRegistry testInstance = MediaFormatRegistry.SINGLETON;
419: try {
420: testInstance.unbind(null);
421: fail("test 1: Should throw a NullPointerException");
422: } catch (NullPointerException e) {
423: testTrace("test 1 passed");
424: } catch (Exception e) {
425: fail("test 1: Should throw a NullPointerException but threw "
426: + e.toString());
427: }
428: //
429: // test 2
430: //
431: try {
432: testInstance.unbind("test");
433: } catch (FormatNotFoundException e) {
434: }
435:
436: try {
437: testInstance.unbind("test");
438: fail("test 2: Should throw a FormatNotFoundException");
439: } catch (FormatNotFoundException e) {
440: testTrace("test 2 passed");
441: } catch (Exception e) {
442: fail("test 2: Should throw a FormatNotFoundException but threw "
443: + e.toString());
444: }
445: //
446: // test 3
447: //
448: testInstance = MediaFormatRegistry.SINGLETON;
449: testInstance.rebind("test1", new GenericMediaFormat());
450: testInstance.rebind("test2", new GenericMediaFormat());
451: testInstance.unbind("test1");
452: testInstance.unbind("test2");
453: testTrace("test 3 passed");
454:
455: succeed("");
456: }
457: }
|