001: package com.ibm.emb.test;
002:
003: // java stuff
004: import java.net.MalformedURLException;
005: import java.net.URL;
006:
007: import javax.emb.MediaException;
008: import javax.emb.MediaSegment;
009:
010: import com.ibm.emb.junit.EMBStaticHelper;
011: import com.ibm.emb.junit.EMBTestCaseBase;
012: import com.ibm.emb.junit.EMBTestRunner;
013:
014: /**
015: * <pre>
016: *
017: * Line Item: MFB API
018: * Subcategory 1: javax.emb
019: * Subcategory 2: MediaSegment
020: *
021: * </pre>
022: */
023: public class MediaSegmentTest extends EMBTestCaseBase {
024:
025: public MediaSegmentTest(String name) throws MediaException {
026: super (name);
027: }
028:
029: public static void main(String args[]) {
030: EMBTestRunner.run(MediaSegmentTest.class);
031: }
032:
033: /**
034: * <pre>
035: *
036: * Testcase Name: getContent()
037: * Testcase Number: EMB033
038: *
039: * setup:
040: *
041: * test procedure:
042: * 1.create random content byte array and pass into setContent()
043: * call getContent()
044: * expected result: content should match original byte array
045: *
046: * 2.create new media segment and call getContent
047: * expected result: empty byte array
048: *
049: * </pre>
050: */
051: public void testEMB033() {
052: //
053: // test 1
054: //
055: MediaSegment testInstance = new MediaSegment();
056: byte[] testArray = EMBStaticHelper
057: .createRandomByteArray(EMBStaticHelper
058: .randomInt(0, 255));
059: testInstance.setContent(testArray);
060: assertSame("test 1: ", testArray, testInstance.getContent());
061: testTrace("test 1 passed");
062: //
063: // test 2
064: //
065: testInstance = new MediaSegment();
066: assertEquals("test 2: content is not empty", 0, testInstance
067: .getContent().length);
068: testTrace("test 2 passed");
069:
070: succeed();
071: }
072:
073: /**
074: * <pre>
075: *
076: * Testcase Name: getChildLocation()
077: * Testcase Number: EMB034
078: *
079: * setup:
080: *
081: * test procedure:
082: * 1.call setChildLoation(null), call getChildLocation()
083: * expected result: null
084: *
085: * 2.create random URL with "file" protocol, call setChildLocation with random URL
086: * call getChildLocation()
087: * expected result: return same URL
088: *
089: * </pre>
090: */
091: public void testEMB034() throws MediaException,
092: MalformedURLException {
093: //
094: // test 1
095: //
096: MediaSegment testInstance = new MediaSegment();
097: testInstance.setChildLocation(null);
098: assertNull("test 1: ", testInstance.getChildLocation());
099: testTrace("test 1 passed");
100: //
101: // test 2
102: //
103: testInstance = new MediaSegment();
104: URL testURL = new URL("file", "localhost", "/testfile");
105: testInstance.setChildLocation(testURL);
106: assertTrue("test 2: ", testURL.equals(testInstance
107: .getChildLocation()));
108: testTrace("test 2 passed");
109:
110: succeed();
111:
112: }
113:
114: /**
115: * <pre>
116: *
117: * Testcase Name: setContent(content)
118: * Testcase Number: EMB035
119: *
120: * setup:
121: *
122: * test procedure
123: * 1.call setContent with null
124: * expected result: NullPointerException
125: *
126: * 2.call setContent with random byte array
127: * call getContent()
128: * expected result: content equal to the random one passed in
129: *
130: * </pre>
131: */
132: public void testEMB035() throws MediaException {
133: //
134: // test 1
135: //
136: MediaSegment testInstance = new MediaSegment();
137: try {
138: testInstance.setContent(null);
139: fail("test 1: Should throw a NullPointerException");
140: } catch (NullPointerException e) {
141: testTrace("test 1 passed");
142: } catch (Exception e) {
143: fail("test 1: Should throw a NullPointerException but threw "
144: + e.toString());
145: }
146: //
147: // test 2
148: //
149: testInstance = new MediaSegment();
150: byte[] randomArray = EMBStaticHelper
151: .createRandomByteArray(EMBStaticHelper
152: .randomInt(0, 255));
153: testInstance.setContent(randomArray);
154: assertSame("test 2: ", randomArray, testInstance.getContent());
155: testTrace("test 2 passed");
156:
157: succeed();
158: }
159:
160: /**
161: * <pre>
162: *
163: * Testcase Name: setChildLocation(URL childLocation)
164: * Testcase Number: EMB036
165: *
166: * setup:
167: *
168: * test procedure:
169: * 1.call setChildLocation with null
170: * expected result: NullPointerException
171: *
172: * 2.call setChildLocation with URL pointing to local machine and protocol type "file"
173: * call getChildLocation()
174: * expected result: content equal to the URL passed before
175: *
176: * </pre>
177: */
178: public void testEMB038() throws MediaException,
179: MalformedURLException {
180: //
181: // test 1
182: //
183: MediaSegment testInstance = new MediaSegment();
184: try {
185: testInstance.setChildLocation(null);
186: testTrace("test 1 passed");
187: } catch (NullPointerException e) {
188: fail("test 1: Should not throw a NullPointerException");
189: } catch (Exception e) {
190: fail("test 1: Should not throw any exception");
191: }
192: //
193: // test 2
194: //
195: testInstance = new MediaSegment();
196: URL testURL = new URL("file", "localhost", "/testfile");
197: testInstance.setChildLocation(testURL);
198: assertEquals("test 1: ", testURL.toString(), testInstance
199: .getChildLocation().toString());
200: testTrace("test 2 passed");
201:
202: succeed();
203: }
204: }
|