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.io.InputStream;
008:
009: import javax.emb.MediaBean;
010: import javax.emb.MediaException;
011: import javax.emb.MediaFormat;
012: import javax.emb.MediaFormatRegistry;
013:
014: import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
015: import org.objectweb.jonas.emb.mfb.formats.image.JpegHeader;
016:
017: import com.ibm.emb.junit.EMBTestRunner;
018:
019: public class JpegFormatTest extends EmbeddedMediaFormatTest {
020:
021: /**
022: * constructor
023: */
024: public JpegFormatTest(String name) throws MediaException {
025: super (name);
026: }
027:
028: /**
029: * main method
030: */
031: public static void main(String args[]) {
032: EMBTestRunner.run(JpegFormatTest.class);
033: }
034:
035: /**
036: * do initialisation here
037: */
038: protected void setUp() {
039: }
040:
041: /**
042: * freeup resources
043: */
044: protected void tearDown() {
045: }
046:
047: /**
048: * creates an instance of JpegFormat with the given Parameters used in super
049: * class of JpegFormatTest
050: */
051: public MediaFormat createMediaFormat() {
052: return new JpegFormat();
053: }
054:
055: /**
056: * <pre>
057: *
058: * Testcase Name: extractHeader(Media)
059: * Testcase Number: TEMB0065SBA
060: *
061: * Test 1:
062: * call extractHeader passing
063: * --> check result to be an instance of com.ibm.emb.meb.JpegHeader
064: *
065: * </pre>
066: */
067: public void testTEMB0065SBA() throws MediaException, IOException {
068: //
069: // test 1
070: //
071:
072: // register media format
073: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
074: formatRegistry.rebind("jpg", new JpegFormat());
075:
076: // full path of the jpeg sample
077: String mediaJpegFullPath = embTestConfig.getMediaDir()
078: + File.separator + embTestConfig.getJpgPictureName1();
079:
080: // creates media bean
081: File mediaJpegFile = new File(mediaJpegFullPath);
082: MediaBean mediaBean = new MediaBean(mediaJpegFile, "jpg");
083:
084: // creates jpeg format
085: JpegFormat jpegFormat = new JpegFormat();
086:
087: // creates jpegHeader
088: InputStream mediaJpegInputStream = new FileInputStream(
089: mediaJpegFile);
090: JpegHeader jpegHeader = (JpegHeader) jpegFormat
091: .extractHeader(mediaJpegInputStream);
092: mediaJpegInputStream.close();
093:
094: // test
095: assertTrue("test 1", jpegHeader instanceof JpegHeader);
096:
097: testTrace("test 1 passed");
098:
099: succeed();
100:
101: }
102:
103: /**
104: * <pre>
105: *
106: * Testcase Name: extractSurrogate(Media)
107: * Testcase Number: TEMB0066SBA
108: *
109: * Test 1:
110: * call extractSurrogate passing
111: * check result to be an instance of Media
112: * access the content of the resulting media ----> to verify it is accessible
113: * check if format of result is an instance of com.ibm.emb.meb.JpegFormat
114: *
115: * </pre>
116: */
117: public void testTEMB0066SBA() throws MediaException, IOException {
118: //
119: // test 1
120: //
121:
122: // register media format
123: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
124: formatRegistry.rebind("jpg", new JpegFormat());
125:
126: // full path of the jpg sample
127: String mediaJpegFullPath = embTestConfig.getMediaDir()
128: + File.separator + embTestConfig.getJpgPictureName1();
129:
130: // creates media bean
131: File mediaJpegFile = new File(mediaJpegFullPath);
132: MediaBean mediaBean = new MediaBean(mediaJpegFile, "jpg");
133:
134: // creates jpg format
135: InputStream mediaJpegInputStream = new FileInputStream(
136: mediaJpegFile);
137: JpegFormat jpegFormat = new JpegFormat();
138: // gets surrogate
139: MediaBean mediaBeanSurrogate = (MediaBean) jpegFormat
140: .extractProxy(mediaJpegInputStream);
141: mediaJpegInputStream.close();
142:
143: // check access to content and check format
144: byte[] content = mediaBeanSurrogate.getContent();
145: byte[] content_ = new byte[content.length];
146: System.arraycopy(content, 0, content_, 0, content.length);
147:
148: JpegFormat jpegFormat1 = (JpegFormat) mediaBeanSurrogate
149: .getFormat();
150:
151: assertTrue("test 1", jpegFormat1 instanceof JpegFormat
152: && mediaBeanSurrogate.getMimeType().equals("jpg"));
153: testTrace("test 1 passed");
154:
155: succeed();
156: }
157:
158: /**
159: * <pre>
160: *
161: * Testcase Name: getDefaultMimeType()
162: * Testcase Number: TEMB0067SBA
163: *
164: * Test 1:
165: * call getDefaultMimeType
166: * --->check if result equals "image/jpeg"
167: *
168: *
169: * </pre>
170: */
171: public void testTEMB0067SBA() throws MediaException {
172: //
173: // test 1
174: //
175:
176: // creates jpg format
177: JpegFormat jpegFormat = new JpegFormat();
178:
179: assertEquals("test1: ", "image/jpeg", jpegFormat
180: .getDefaultMimeType());
181: testTrace("test 1 passed");
182:
183: succeed();
184: }
185:
186: /**
187: * <pre>
188: *
189: * Testcase Name: isStreamingDesirable()
190: * Testcase Number: TEMB0069SBA
191: *
192: * Test 1:
193: * call isStreamingDesirable
194: * --->check if result is false
195: *
196: *
197: * </pre>
198: */
199: public void testTEMB0069SBA() throws MediaException {
200: //
201: // test 1
202: //
203:
204: // creates jpg format
205: JpegFormat jpegFormat = new JpegFormat();
206:
207: assertTrue("test1: ", !jpegFormat.isStreamingDesirable());
208: testTrace("test 1 passed");
209:
210: succeed();
211: }
212:
213: }
|