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.IOException;
007: import java.net.MalformedURLException;
008: import java.net.URL;
009: import java.rmi.RemoteException;
010:
011: import javax.emb.LinkTranslationException;
012: import javax.emb.MalformedLocationException;
013: import javax.emb.Media;
014: import javax.emb.MediaException;
015: import javax.emb.MediaFormat;
016: import javax.emb.MediaHeader;
017: import javax.emb.MediaSegment;
018:
019: import org.objectweb.jonas.emb.mfb.formats.playlist.GenericPlaylistFormat;
020:
021: import com.ibm.emb.junit.EMBTestRunner;
022: import com.ibm.emb.test.MediaFormatTest;
023:
024: public class GenericPlayListTest extends MediaFormatTest {
025:
026: /**
027: * constructor
028: */
029: public GenericPlayListTest(String name) throws MediaException {
030: super (name);
031: }
032:
033: /**
034: * main
035: */
036: public static void main(String args[]) {
037: EMBTestRunner.run(GenericPlayListTest.class);
038: }
039:
040: /**
041: * do initialisation here
042: */
043: protected void setUp()
044:
045: {
046: }
047:
048: /**
049: * freeup resources
050: */
051: protected void tearDown() {
052: }
053:
054: /**
055: * creates an instance of GenericPlaylistFormat with the given Parameters
056: * used in super clas of GenericPlaylistFormatTest
057: */
058: public MediaFormat createMediaFormat() {
059: return new GenericPlaylistFormat();
060: }
061:
062: /**
063: * <pre>
064: *
065: *
066: *
067: * Testcase Name: assembleContent(URL, MediaSegment[])
068: * Testcase Number: TEMB0109SBA
069: *
070: * Test 1:
071: * call disassembleContent and pass in the content of testPlaylist1.lst and "file://myip/embtest/test.lst" as URL
072: * call assembleContent and pass in the result from before and "file://myip/embtest/test.lst" as URL
073: * --> check if no exception occurs
074: *
075: * Test 2:
076: * call disassembleContent and pass in the content of test.lst and "file://myip/embtest/test.lst" as URL
077: * call assembleContent and pass in the result from before and null as URL
078: * --> check if no exception occurs
079: * --> check if length of the resulting byte array is larger than the length of the original content
080: *
081: * Test 3:
082: * call assembleContent and pass in an empty segment array and null as URL
083: * --> check if no exception occurs
084: * --> check if length of the resulting byte array is 0.
085: *
086: *
087: *
088: * </pre>
089: */
090: public void testTEMB0109SBA() throws MediaException,
091: MalformedURLException, IOException {
092:
093: // name of the computer where tests are performed
094: String computerName = embTestConfig.getTestClient();
095:
096: // url of test playlist
097: URL playlistURL = new URL("file", computerName, embTestConfig
098: .getMediaDir()
099: + File.separator + embTestConfig.getPlaylistName1());
100:
101: // reads content of test playlist (test.lst) and stores to an array
102: File playlistFile = new File(embTestConfig.getMediaDir()
103: + File.separator + embTestConfig.getPlaylistName1());
104: FileInputStream playlistByteInputStream = new FileInputStream(
105: playlistFile);
106:
107: byte[] testArray = new byte[new Long(playlistFile.length())
108: .intValue()];
109: playlistByteInputStream.read(testArray);
110:
111: // media segment
112: MediaSegment mediaSegment1 = null;
113: MediaSegment[] testMediaSegmentArray = null;
114:
115: // test instance
116: MediaFormat testInstance = createMediaFormat();
117:
118: //
119: // test 1
120: //
121: byte[] testArray1 = null;
122: try {
123: testMediaSegmentArray = testInstance.disassembleContent(
124: playlistURL, testArray);
125: testArray1 = testInstance.assembleContent(playlistURL,
126: testMediaSegmentArray);
127: } catch (Exception e) {
128: fail("No exception should be thrown but this one appears : "
129: + e.toString());
130: }
131: testTrace("test 1 passed");
132:
133: //
134: // test 2
135: //
136: byte[] testArray2 = null;
137: try {
138: testMediaSegmentArray = testInstance.disassembleContent(
139: playlistURL, testArray);
140: testArray2 = testInstance.assembleContent(null,
141: testMediaSegmentArray);
142: } catch (Exception e) {
143: fail("No exception should be thrown but this one appears : "
144: + e.toString());
145: }
146: assertTrue("test 2: ", testArray2.length > testArray.length);
147: testTrace("test 2 passed");
148:
149: //
150: // test 3
151: //
152: byte[] testArray3 = null;
153: try {
154: MediaSegment[] testMediaSegmentArray3 = new MediaSegment[0];
155: testArray3 = testInstance.assembleContent(null,
156: testMediaSegmentArray3);
157: } catch (Exception e) {
158: fail("No exception should be thrown but this one appears : "
159: + e.toString());
160: }
161: assertTrue("test 2: ", testArray3.length == 0);
162: testTrace("test 3 passed");
163:
164: succeed();
165:
166: }
167:
168: /**
169: * <pre>
170: *
171: *
172: *
173: * Testcase Name: disassembleContent(URL, byte[])
174: * Testcase Number: TEMB0108SBA
175: *
176: * Test 1:
177: * call disassembleContent and pass in the content of test.lst and null as URL
178: * --> check for LinkTranslationException
179: *
180: *
181: * Test 2:
182: * call disassembleContent and pass in the content of test.lst and "file://myip/embtest/test.lst" as URL
183: * --> check result for 3 elements
184: * --> check each element for childLink "file://myip/embtest/test.jpg"
185: *
186: *
187: * Test 3:
188: * call disassembleContent and pass in "file://foo".getBytes() as content and "file://myip/embtest/test.lst" as URL
189: * --> check for MalformedLocationException
190: *
191: *
192: *
193: *
194: * </pre>
195: */
196: public void testTEMB0108SBA() throws MediaException,
197: MalformedURLException, IOException {
198:
199: String computerName = embTestConfig.getTestClient();
200:
201: // full path of the jpg sample
202: String mediaJpgFullPath = embTestConfig.getMediaDir()
203: + File.separator + embTestConfig.getJpgPictureName1();
204:
205: // url of test playlist
206: String gplURLlocation = embTestConfig.getMediaDir()
207: + File.separatorChar + embTestConfig.getPlaylistName1();
208: String gplURLlocationPath = gplURLlocation.substring(0,
209: gplURLlocation.lastIndexOf("/"));
210: URL playlistURL = new URL("file", computerName, gplURLlocation);
211:
212: // URL playlistURL = new URL("file", computerName,
213: // embTestConfig.getTestServerMediaDir() + "/" + );
214:
215: // reads content of test playlist (test.lst) and stores to an array
216: File playlistFile = new File(embTestConfig.getMediaDir()
217: + File.separator + embTestConfig.getPlaylistName1());
218:
219: byte[] testArray = getByteArrayFromFile(playlistFile);
220: // playlistByteInputStream.read(testArray);
221:
222: // media segment
223: MediaSegment mediaSegment1 = null;
224: MediaSegment[] testMediaSegmentArray = null;
225:
226: // test instance
227: MediaFormat testInstance = createMediaFormat();
228:
229: //
230: // test 1
231: //
232: byte[] testArray1 = null;
233: try {
234: testMediaSegmentArray = testInstance.disassembleContent(
235: null, testArray);
236: fail("LinkTranslationException should be thrown");
237: } catch (LinkTranslationException e) {
238: testTrace("test 1 passed");
239: } catch (Exception e) {
240: fail("LinkTranslationException should be thrown but this one appears : "
241: + e.toString());
242: }
243:
244: //
245: // test 2
246: //
247: try {
248: boolean pathCheck = true;
249: testMediaSegmentArray = testInstance.disassembleContent(
250: playlistURL, testArray);
251:
252: for (int i = 0; i < testMediaSegmentArray.length - 1; i++) {
253: // path check
254: if (!testMediaSegmentArray[i].getChildLocation()
255: .toString().startsWith(
256: "file://"
257: + embTestConfig.getTestClient()
258: + gplURLlocationPath)) {
259: pathCheck = false;
260: }
261: }
262:
263: assertTrue("test 2: ", testMediaSegmentArray.length == 3
264: && pathCheck);
265:
266: testTrace("test 2 passed");
267:
268: } catch (Exception e) {
269: fail("No exception should be thrown but this one appears : "
270: + e.toString());
271: }
272:
273: //
274: // test 3
275: //
276:
277: byte[] fooArray = new String("file://foo").getBytes();
278:
279: logProductError("reported error PEMB0058RMD");
280:
281: try {
282: testMediaSegmentArray = testInstance.disassembleContent(
283: playlistURL, fooArray);
284: fail("MalformedLocationException should be thrown");
285: } catch (MalformedLocationException e) {
286: testTrace("test 3 passed");
287: } catch (Exception e) {
288: fail("MalformedLocationException should be thrown but this one appears : "
289: + e.toString());
290: }
291:
292: }
293:
294: /**
295: * <pre>
296: *
297: *
298: *
299: * Testcase Name: extractHeader(Media)
300: * Testcase Number: TEMB0113SBA
301: *
302: * Test 1:
303: * call extractHeader passing null
304: * --> check result to be an instance of GenericMediaHeader
305: *
306: *
307: *
308: * </pre>
309: */
310: public void testTEMB0113SBA() throws MediaException {
311: //
312: // test 1
313: //
314:
315: // test instance
316: MediaFormat testInstance = createMediaFormat();
317: MediaHeader mediaHeader = testInstance.extractHeader(null);
318: assertTrue("test1: ", mediaHeader instanceof MediaHeader);
319: testTrace("test 1 passed");
320:
321: succeed();
322:
323: }
324:
325: /**
326: * <pre>
327: *
328: *
329: *
330: * Testcase Name: extractSurrogate(Media)
331: * Testcase Number: TEMB0110SBA
332: *
333: * Test 1:
334: * call extractSurrogate passing null
335: * check result to be an instance of Media
336: * access the content of the resulting media ----> to verify it is accessible
337: *
338: *
339: *
340: * </pre>
341: */
342: public void testTEMB0110SBA() throws MediaException,
343: RemoteException {
344: //
345: // test 1
346: //
347:
348: // test instance
349: MediaFormat testInstance = createMediaFormat();
350: Media media = testInstance.extractProxy(null);
351:
352: // checks if media accessable and testinstance instance of media
353: try {
354: byte[] mediaArray = media.getContent();
355: assertTrue("test1: ", media instanceof Media);
356: } catch (Exception e) {
357: fail("test 1 failed, exception : ");
358: }
359:
360: testTrace("test 1 passed");
361:
362: succeed();
363:
364: }
365:
366: /**
367: * <pre>
368: *
369: *
370: *
371: * Testcase Name: getDefaultMimeType()
372: * Testcase Number: TEMB0112SBA
373: *
374: * Test 1:
375: * call getDefaultMimeType
376: * --->check if result equals "www/unknown"
377: *
378: *
379: *
380: * </pre>
381: */
382: public void testTEMB0112SBA() throws MediaException {
383: //
384: // test 1
385: //
386:
387: // test instance
388: MediaFormat testInstance = createMediaFormat();
389:
390: assertEquals("test1: ", "www/unknown", testInstance
391: .getDefaultMimeType());
392: testTrace("test 1 passed");
393:
394: succeed();
395: }
396:
397: /**
398: * <pre>
399: *
400: *
401: *
402: * Testcase Name: isStreamingDesirable()
403: * Testcase Number: TEMB0111SBA
404: *
405: * call isStreamingDesirable
406: * --->check if result is true
407: *
408: *
409: *
410: * </pre>
411: */
412: public void testTEMB0111SBA() {
413: //
414: // test 1
415: //
416:
417: // test instance
418: MediaFormat testInstance = createMediaFormat();
419:
420: assertTrue("test1: ", testInstance.isStreamingDesirable());
421: testTrace("test 1 passed");
422:
423: succeed();
424: }
425: }
|