Source Code Cross Referenced for MediaEntityLocalTest.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) 


0001:        package com.ibm.emb.test;
0002:
0003:        import java.io.File;
0004:        import java.io.FileInputStream;
0005:        import java.io.FileOutputStream;
0006:        import java.io.IOException;
0007:        import java.io.InputStream;
0008:        import java.net.MalformedURLException;
0009:        import java.net.URL;
0010:        import java.rmi.RemoteException;
0011:        import java.util.Arrays;
0012:        import java.util.Date;
0013:
0014:        import javax.ejb.CreateException;
0015:        import javax.ejb.FinderException;
0016:        import javax.ejb.RemoveException;
0017:        import javax.emb.GenericMediaFormat;
0018:        import javax.emb.ListenerVetoException;
0019:        import javax.emb.Media;
0020:        import javax.emb.MediaBean;
0021:        import javax.emb.MediaConverterSpec;
0022:        import javax.emb.MediaException;
0023:        import javax.emb.MediaHeader;
0024:        import javax.emb.MediaListener;
0025:        import javax.naming.InitialContext;
0026:        import javax.naming.NamingException;
0027:        import javax.rmi.PortableRemoteObject;
0028:
0029:        import mfb.converters.BmpToJpegConverterSpec;
0030:        import mfb.converters.JpegToBmpConverterSpec;
0031:
0032:        import org.objectweb.jonas.emb.mfb.formats.image.BmpFormat;
0033:        import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
0034:        import org.objectweb.jonas.emb.mfb.formats.playlist.GenericPlaylistFormat;
0035:
0036:        import com.ibm.emb.junit.ComplexMediaLocationInfo;
0037:        import com.ibm.emb.junit.EMBStaticHelper;
0038:        import com.ibm.emb.junit.EMBTestCaseBase;
0039:        import com.ibm.emb.junit.EmbeddedMediaLocationInfo;
0040:        import com.ibm.emb.meb.listener.GenericMediaListener;
0041:        import com.ibm.emb.meb.test.ejb.MediaEntityLocalTestDriver;
0042:        import com.ibm.emb.meb.test.ejb.MediaEntityLocalTestDriverHome;
0043:
0044:        /**
0045:         * <pre>
0046:         *
0047:         *  Line Item: MEB API
0048:         *  Subcategory 1: javax.emb
0049:         *  Subcategory 2: MediaEntityLocal
0050:         *
0051:         * </pre>
0052:         */
0053:        public class MediaEntityLocalTest extends EMBTestCaseBase {
0054:
0055:            public MediaEntityLocalTest(String name) throws MediaException {
0056:                super (name);
0057:            }
0058:
0059:            private static String MEBTESTER_JNDI = "java:comp/env/ejb/MediaEntityLocalTestDriverHome";
0060:
0061:            private InitialContext ic;
0062:
0063:            private MediaEntityLocalTestDriverHome mebHome = null;
0064:
0065:            private MediaEntityLocalTestDriver mebTester = null;
0066:
0067:            /**
0068:             * initialization of test case (called before each test method)
0069:             */
0070:            protected void setUp() throws RemoteException, CreateException {
0071:                if (mebHome == null) {
0072:                    try {
0073:                        ic = new InitialContext();
0074:                        Object ojb = ic.lookup(MEBTESTER_JNDI);
0075:                        mebHome = (MediaEntityLocalTestDriverHome) PortableRemoteObject
0076:                                .narrow(ojb,
0077:                                        MediaEntityLocalTestDriverHome.class);
0078:                    } catch (NamingException ne) {
0079:                        System.out
0080:                                .println("NamingException thrown during setup. Msg: "
0081:                                        + ne.getMessage());
0082:                    }
0083:                }
0084:                // create new instance of MediaEntityLocalTestDriver
0085:                mebTester = mebHome.create();
0086:                return;
0087:            }
0088:
0089:            /**
0090:             * <pre>
0091:             *
0092:             *  Testcase Name: addListener(MediaListener)
0093:             *  Testcase Number: EMB100
0094:             *
0095:             *  setup:
0096:             *
0097:             *  test procedure:
0098:             *  1.create new media entity me1, call addListener(null)
0099:             *    expected result: NullPointerException
0100:             *
0101:             *  2.create new MediaListener listener1, call addListener(listener1)
0102:             *    expected result: no exception, call getListeners and check if there is only one element
0103:             *
0104:             *  3.create MediaListener listener2, call addListener(listener2)
0105:             *    expected result: no exception, call getListeners and check for two elements
0106:             *
0107:             *  4.call addListener(listener1)
0108:             *    expected result: no exception, call getListeners and check there is still two elements
0109:             *
0110:             * </pre>
0111:             */
0112:            public void testEMB100() throws MediaException, IOException,
0113:                    InterruptedException, Throwable {
0114:
0115:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0116:                        embTestConfig.getJpgPictureName1());
0117:                String me1 = mebTester.createMediaEntityBean();
0118:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0119:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0120:
0121:                GenericMediaListener listener1 = new GenericMediaListener(
0122:                        "listener1");
0123:                GenericMediaListener listener2 = new GenericMediaListener(
0124:                        "listener2");
0125:                MediaListener[] listeners = null;
0126:
0127:                int exception = -1;
0128:                //
0129:                // test 1
0130:                //
0131:                try {
0132:                    exception = mebTester.addListenerExceptions(me1, null);
0133:                } catch (Throwable e) {
0134:                    fail("test 2 threw " + e.toString());
0135:                }
0136:                assertEquals("test 1: Should throw a NullPointerException: "
0137:                        + exception, MediaEntityLocalTestDriver.NULLPOINTER,
0138:                        exception);
0139:                testTrace("test 1 passed");
0140:                //
0141:                // test 2
0142:                //
0143:                try {
0144:                    mebTester.addMediaEntityListener(me1, listener1);
0145:                } catch (Throwable e) {
0146:                    fail("test 2 threw " + e.toString());
0147:                }
0148:                listeners = mebTester.getMediaEntityListeners(me1);
0149:                assertEquals("test 2: listener not added", 1, listeners.length);
0150:                assertTrue("test 2: ", listener1.equals(listeners[0]));
0151:                testTrace("test 2 passed");
0152:                //
0153:                // test 3
0154:                //
0155:
0156:                try {
0157:                    mebTester.addMediaEntityListener(me1, listener2);
0158:                } catch (Throwable e) {
0159:                    fail("test 3 threw " + e.toString());
0160:                }
0161:                listeners = mebTester.getMediaEntityListeners(me1);
0162:                assertEquals("test 3: ", 2, listeners.length);
0163:                assertTrue("test 3: ", listener2.equals(listeners[1]));
0164:                testTrace("test 3 passed");
0165:                //
0166:                // test 4
0167:                //
0168:                try {
0169:                    mebTester.addMediaEntityListener(me1, listener1);
0170:                } catch (Throwable e) {
0171:                    fail("test 4 threw " + e.toString());
0172:                }
0173:                listeners = mebTester.getMediaEntityListeners(me1);
0174:                assertEquals("test 4: ", 2, listeners.length);
0175:                testTrace("test 4 passed");
0176:
0177:                // remove test MEBs
0178:                mebTester.removeMEBByPK(me1);
0179:
0180:                succeed();
0181:            }
0182:
0183:            /**
0184:             * <pre>
0185:             *
0186:             *  Testcase Name: addMetaData(MetaDataEntityLocal)
0187:             *  Testcase Number: EMB101
0188:             *
0189:             *  setup: create Media entities me1 and me2
0190:             *         create meta data entities md1 and md2
0191:             *
0192:             *  test procedure:
0193:             *  1.call me1.addMetaData(null)
0194:             *    expected result: NullPointerException
0195:             *
0196:             *  2.call me1.addMetaData(md1)
0197:             *    expected result: no exception, call me1.getMetaData and check for one element
0198:             *
0199:             *  3.call me1.addMetaData(md2)
0200:             *    expected result: no exception, call me1.getMetaData and check for two elements
0201:             *
0202:             *  4.call me2.addMetaData(md1)
0203:             *    expected result: no exception, call me1.getMetaData and verify there are two elements
0204:             *  	 call me2.getMetaData and verify there is one element
0205:             *
0206:             * </pre>
0207:             */
0208:            public void testEMB101() throws MediaException, CreateException,
0209:                    NamingException, IOException, FinderException, Throwable {
0210:
0211:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0212:                        embTestConfig.getJpgPictureName1());
0213:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
0214:                        embTestConfig.getJpgPictureName2());
0215:
0216:                String me1 = mebTester.createMediaEntityBean();
0217:                String me2 = mebTester.createMediaEntityBean();
0218:
0219:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0220:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
0221:
0222:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0223:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
0224:
0225:                String md1 = mebTester.createMetaDataEntityBean();
0226:                String md2 = mebTester.createMetaDataEntityBean();
0227:                String[] metaDataPKs = null;
0228:
0229:                int exception = -1;
0230:                //
0231:                // test 1
0232:                //
0233:                try {
0234:                    exception = mebTester.addMetaDataExceptions(me1, null);
0235:                } catch (Throwable e) {
0236:                    fail("test 1 threw " + e.toString());
0237:                }
0238:                assertEquals("test 1: Should throw a NullPointerException: "
0239:                        + exception, MediaEntityLocalTestDriver.NULLPOINTER,
0240:                        exception);
0241:                testTrace("test 1 passed");
0242:                //
0243:                // test 2
0244:                //
0245:                mebTester.addMediaEntityMetaData(me1, md1);
0246:                metaDataPKs = mebTester.getMediaEntityMetaData(me1);
0247:                assertEquals("test 2: meta data not added", 1,
0248:                        metaDataPKs.length);
0249:                assertEquals("test 2: meta data does not match", md1,
0250:                        metaDataPKs[0]);
0251:                testTrace("test 2 passed");
0252:                //
0253:                // test 3
0254:                //
0255:                mebTester.addMediaEntityMetaData(me1, md2);
0256:                metaDataPKs = mebTester.getMediaEntityMetaData(me1);
0257:                assertEquals("test 3: meta data not added", 2,
0258:                        metaDataPKs.length);
0259:                boolean match = false;
0260:                if ((md1.equals(metaDataPKs[0]) && md2.equals(metaDataPKs[1]))
0261:                        || (md1.equals(metaDataPKs[1]) && md2
0262:                                .equals(metaDataPKs[0]))) {
0263:                    match = true;
0264:                }
0265:                assertTrue("test 3: meta data does not match", match);
0266:                testTrace("test 3 passed");
0267:                //
0268:                // test 4
0269:                //
0270:                mebTester.addMediaEntityMetaData(me2, md1);
0271:                metaDataPKs = mebTester.getMediaEntityMetaData(me2);
0272:                assertEquals("test 4: meta data not added", 1,
0273:                        metaDataPKs.length);
0274:                assertEquals("test 4: meta data does not match", md1,
0275:                        metaDataPKs[0]);
0276:                assertEquals("test 4: meta data removed", 2, mebTester
0277:                        .getMediaEntityMetaData(me1).length);
0278:                testTrace("test 4 passed");
0279:
0280:                // remove test MEBs and MDEBs
0281:                mebTester.removeMEBByPK(me1);
0282:                mebTester.removeMEBByPK(me2);
0283:                mebTester.removeMDEBByPK(md1);
0284:                mebTester.removeMDEBByPK(md2);
0285:
0286:                succeed();
0287:            }
0288:
0289:            /**
0290:             * <pre>
0291:             *
0292:             *  Testcase Name: convert(MediaConverterSpec[])
0293:             *  Testcase Number: EMB102
0294:             *
0295:             *  setup:
0296:             *
0297:             *  test procedure:
0298:             *  1.call convert(null)
0299:             *    expected result: NullPointerException
0300:             *
0301:             *  2.call convert(new MediaConverterSpec[0])
0302:             *    expected result: content unchanged
0303:             *
0304:             *  3.create Media entity from bmp image file and store getLastModified()
0305:             *    create 2 element array of converter specs:
0306:             *  		(1) BmpToJpegConverterSpec
0307:             *  		(2) JpegToBmpConverterSpec
0308:             *    call convert
0309:             *    expected result: media entity is a bmp image that is roughly the same size as original
0310:             *  					  getLastModified() should have changed
0311:             *
0312:             *  4.create Media entity from bmp image file
0313:             *    create 2 element array of converter specs with both being BmpToJpegConverterSpec
0314:             *    call convert
0315:             *    expected result: FormatSyntaxException
0316:             *
0317:             *  5.create Media entity from random content
0318:             *    create 1 element array of converter specs with element being BmpToJpegConverterSpec
0319:             *   call convert
0320:             *    expected result:FormatSyntaxException
0321:             *
0322:             *  6.create Media entity from nonexistent file and create 1 element array of
0323:             *    converter specs with BmpToJpegConverterSpec, call convert
0324:             *    expected result: ContentAccessException
0325:             *
0326:             *  7.create Media entity from jpeg file and create 1 element array of converter specs
0327:             *    with nonexistent converter (i.e. JpegToMpegConverterSpec)
0328:             *    expected result: ConversionException
0329:             *
0330:             *  8.create Media entity from jpeg file
0331:             *    call convert(new MediaConverterSpec[]{null, null})
0332:             *    expected result: ConversionException
0333:             *
0334:             *  9.create Media entity from jpeg file
0335:             *    call convert(new MediaConverterSpec[]{JpegToBmpConverterSpec})
0336:             *    expected result: entity is converted to bmp, check format and file extension changed
0337:             *  					  getLastModified updated
0338:             *
0339:             *  10.create Media entity from bmp file and create instance of Media listener
0340:             *     call me1.addListener(listener)
0341:             *     call convert(new MediaConverterSpec[]{BmpToJpegConverterSPec})
0342:             *     expected result: ListenerVetoException
0343:             *
0344:             *  11.create Media entity and setLocation
0345:             *     call me.convert(new MediaConverterSpec[]{JpegToBmpConverterSpec})
0346:             *     expected result: ContentUnmutableException
0347:             *
0348:             * </pre>
0349:             */
0350:            public void testEMB102() throws MediaException, NamingException,
0351:                    IOException, InterruptedException, Throwable {
0352:
0353:                mebTester.bindMediaFormat("jpg", new JpegFormat());
0354:                mebTester.bindMediaFormat("bmp", new BmpFormat());
0355:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
0356:
0357:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0358:                        embTestConfig.getJpgPictureName1());
0359:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
0360:                        embTestConfig.getBmpPictureName1());
0361:                String me1 = mebTester.createMediaEntityBean();
0362:                String me2 = mebTester.createMediaEntityBean();
0363:
0364:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0365:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
0366:
0367:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0368:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
0369:
0370:                MediaConverterSpec[] mediaConverterSpecArray = null;
0371:
0372:                int exception = -1;
0373:                //
0374:                // test 1
0375:                //
0376:                String me8 = mebTester.createMediaEntityBean();
0377:                EmbeddedMediaLocationInfo me8LocInfo = new EmbeddedMediaLocationInfo(
0378:                        embTestConfig.getJpgPictureName1());
0379:                mebTester.setMediaEntityName(me8, me8LocInfo.getMediaName());
0380:                mebTester.setMediaEntityContent(me8, me8LocInfo.getMediaFile());
0381:                try {
0382:                    exception = mebTester.convertExceptions(me8, null);
0383:                } catch (Throwable e) {
0384:                    fail("test 1 threw " + e.toString());
0385:                }
0386:                assertEquals("test 1: Should throw a NullPointerException: "
0387:                        + exception, MediaEntityLocalTestDriver.NULLPOINTER,
0388:                        exception);
0389:                testTrace("test 1 passed");
0390:                //
0391:                // test 2
0392:                //
0393:                // FIX : EMB 102 : no format, no content for me1 ?
0394:                mebTester.convertMediaEntity(me1, new MediaConverterSpec[0]);
0395:                assertTrue("test 2: not instance of JpegFormat", mebTester
0396:                        .getMediaEntityFormat(me1) instanceof  JpegFormat);
0397:                assertTrue("test 2: content modified", java.util.Arrays.equals(
0398:                        mebTester.getMediaEntityContent(me1),
0399:                        getByteArrayFromFile(me1LocInfo.getMediaFile())));
0400:                testTrace("test 2 passed");
0401:                //
0402:                // test 3
0403:                //
0404:                Date beforeStamp = new Date(mebTester
0405:                        .getMediaEntityLastModified(me2));
0406:                mediaConverterSpecArray = new MediaConverterSpec[] {
0407:                        new BmpToJpegConverterSpec(),
0408:                        new JpegToBmpConverterSpec() };
0409:                int oldSize = (int) mebTester.getMediaEntitySize(me2);
0410:                mebTester.convertMediaEntity(me2, mediaConverterSpecArray);
0411:                Thread.sleep(1000);
0412:                Date afterStamp = new Date(mebTester
0413:                        .getMediaEntityLastModified(me2));
0414:                assertTrue("test 3: Modification date", afterStamp
0415:                        .after(beforeStamp));
0416:                assertTrue(
0417:                        "test 3: Media entity is not in bmp format",
0418:                        mebTester.getMediaEntityFormat(me2) instanceof  BmpFormat);
0419:                assertEquals("test 3: wrong file extension",
0420:                        mebTester.getMediaEntityName(me2)
0421:                                .substring(
0422:                                        mebTester.getMediaEntityName(me2)
0423:                                                .indexOf('.') + 1), "bmp");
0424:                // TODO: EMB 102 : Bmp to JPG then JPG to BMP no size change is not mandatory
0425:                //assertEquals("test 3: new media is not same size as original", oldSize, mebTester.getMediaEntitySize(me2));
0426:                testTrace("test 3 passed");
0427:                //
0428:                // test 4
0429:                //
0430:                mediaConverterSpecArray = new MediaConverterSpec[] {
0431:                        new BmpToJpegConverterSpec(),
0432:                        new BmpToJpegConverterSpec() };
0433:                try {
0434:                    exception = mebTester.convertExceptions(me2,
0435:                            mediaConverterSpecArray);
0436:                } catch (Throwable e) {
0437:                    fail("test 4 threw " + e.toString());
0438:                }
0439:                assertEquals("test 4: Should throw a MediaFormatException: "
0440:                        + exception, MediaEntityLocalTestDriver.MEDIAFORMAT,
0441:                        exception);
0442:                testTrace("test 4 passed");
0443:                //
0444:                // test 5
0445:                //
0446:                String mediaBmpFullPath = embTestConfig.getMediaDir()
0447:                        + File.separatorChar + "Generated" + File.separatorChar
0448:                        + "test.bmp";
0449:                FileOutputStream mediaBmpOutputStream = new FileOutputStream(
0450:                        mediaBmpFullPath);
0451:                mediaBmpOutputStream.write(EMBStaticHelper
0452:                        .createRandomByteArray(1024));
0453:                mediaBmpOutputStream.close();
0454:                String me3 = mebTester.createMediaEntityBean();
0455:                mebTester.setMediaEntityName(me3, "test.test");
0456:                mebTester
0457:                        .setMediaEntityContent(me3, new File(mediaBmpFullPath));
0458:                mebTester.setMediaEntityName(me3, "test.bmp");
0459:                mediaConverterSpecArray = new MediaConverterSpec[] { new BmpToJpegConverterSpec() };
0460:                try {
0461:                    exception = mebTester.convertExceptions(me3,
0462:                            mediaConverterSpecArray);
0463:                } catch (Throwable e) {
0464:                    fail("test 5 threw " + e.toString());
0465:                }
0466:                assertEquals("test 5: Should throw a MediaFormatException: "
0467:                        + exception, MediaEntityLocalTestDriver.MEDIAFORMAT,
0468:                        exception);
0469:                testTrace("test 5 passed");
0470:                //
0471:                // test 6
0472:                //
0473:                String me4 = mebTester.createMediaEntityBean();
0474:                mebTester.setMediaEntityName(me4, "nonexistentBean.test");
0475:                try {
0476:                    exception = mebTester.convertExceptions(me4,
0477:                            mediaConverterSpecArray);
0478:                } catch (Throwable e) {
0479:                    fail("test 6 threw " + e.toString());
0480:                }
0481:                assertEquals("test 6: Should throw a ContentAccessException: "
0482:                        + exception, MediaEntityLocalTestDriver.CONTENTACCESS,
0483:                        exception);
0484:                testTrace("test 6 passed");
0485:                //
0486:                // test 7
0487:                //
0488:                String me7 = mebTester.createMediaEntityBean();
0489:                //TODO : EMB 102 : JpegToMpegConverterSpec does not exist any more
0490:                //        EmbeddedMediaLocationInfo me7LocInfo = new EmbeddedMediaLocationInfo(embTestConfig.getJpgPictureName1());
0491:                //        mebTester.setMediaEntityName(me7, me7LocInfo.getMediaName());
0492:                //        mebTester.setMediaEntityContent(me7, me7LocInfo.getMediaFile());
0493:                //
0494:                //        mediaConverterSpecArray = new MediaConverterSpec[] {new JpegToMpegConverterSpec()};
0495:                //        try {
0496:                //            exception = mebTester.convertExceptions(me7, mediaConverterSpecArray);
0497:                //        } catch (Throwable e) {
0498:                //            fail("test 7 threw " + e.toString());
0499:                //        }
0500:                //        assertEquals("test 7: Should throw a ConversionException: " + exception, MediaEntityLocalTestDriver.CONVERSION,
0501:                //                exception);
0502:                //        testTrace("test 7 passed");
0503:
0504:                //
0505:                // test 8
0506:                //
0507:                mediaConverterSpecArray = new MediaConverterSpec[] { null, null };
0508:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0509:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0510:                try {
0511:                    exception = mebTester.convertExceptions(me1,
0512:                            mediaConverterSpecArray);
0513:                } catch (Throwable e) {
0514:                    fail("test 8 threw " + e.toString());
0515:                }
0516:                assertEquals("test 8: Should throw a ConversionException: "
0517:                        + exception, MediaEntityLocalTestDriver.CONVERSION,
0518:                        exception);
0519:                testTrace("test 8 passed");
0520:                //
0521:                // test 9
0522:                //
0523:                mediaConverterSpecArray = new MediaConverterSpec[] { new JpegToBmpConverterSpec() };
0524:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0525:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0526:                beforeStamp = new Date(mebTester
0527:                        .getMediaEntityLastModified(me1));
0528:                mebTester.convertMediaEntity(me1, mediaConverterSpecArray);
0529:                Thread.sleep(1000);
0530:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
0531:                assertTrue("test 9: Modification date", afterStamp
0532:                        .after(beforeStamp));
0533:                assertTrue("test 9: media format did not change", mebTester
0534:                        .getMediaEntityFormat(me1) instanceof  BmpFormat);
0535:                assertEquals("test 9: wrong file extension",
0536:                        mebTester.getMediaEntityName(me1)
0537:                                .substring(
0538:                                        mebTester.getMediaEntityName(me1)
0539:                                                .indexOf('.') + 1), "bmp");
0540:                testTrace("test 9 passed");
0541:                //
0542:                // test 10
0543:                //
0544:                mediaConverterSpecArray = new MediaConverterSpec[] { new JpegToBmpConverterSpec() };
0545:                EmbeddedMediaLocationInfo me5LocInfo = new EmbeddedMediaLocationInfo(
0546:                        embTestConfig.getJpgPictureName2());
0547:                String me5 = mebTester.createMediaEntityBean();
0548:                mebTester.setMediaEntityName(me5, me5LocInfo.getMediaName());
0549:                mebTester.setMediaEntityContent(me5, me5LocInfo.getMediaFile());
0550:                // add new listener to me5
0551:                GenericMediaListener testListener = new GenericMediaListener();
0552:                mebTester.addMediaEntityListener(me5, testListener);
0553:                try {
0554:                    exception = mebTester.convertExceptions(me5,
0555:                            mediaConverterSpecArray);
0556:                } catch (Throwable e) {
0557:                    fail("test 10 threw " + e.toString());
0558:                }
0559:                assertEquals("test 10: Should throw a ListenerVetoException",
0560:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
0561:                testTrace("test 10 passed");
0562:                //
0563:                // test 11
0564:                //
0565:                String me6 = mebTester.createMediaEntityBean();
0566:                mebTester.setMediaEntityName(me6, me5LocInfo.getMediaName());
0567:                mebTester.setMediaEntityLocation(me6, me5LocInfo.getMediaURL());
0568:                try {
0569:                    exception = mebTester.convertExceptions(me6,
0570:                            mediaConverterSpecArray);
0571:                } catch (Throwable e) {
0572:                    fail("test 11 threw " + e.toString());
0573:                }
0574:                assertEquals(
0575:                        "test 11: Should throw a ContentUnmutableException",
0576:                        MediaEntityLocalTestDriver.CONTENTUNMUTABLE, exception);
0577:                testTrace("test 11 passed");
0578:
0579:                // remove test MEBs
0580:                mebTester.removeMEBByPK(me1);
0581:                mebTester.removeMEBByPK(me2);
0582:                mebTester.removeMEBByPK(me3);
0583:                mebTester.removeMEBByPK(me4);
0584:                mebTester.removeMEBByPK(me5);
0585:                mebTester.removeMEBByPK(me7);
0586:                mebTester.removeMEBByPK(me8);
0587:
0588:                succeed();
0589:            }
0590:
0591:            /**
0592:             * <pre>
0593:             *
0594:             *  Testcase Name: exportMedia(URL)
0595:             *  Testcase Number: EMB103
0596:             *
0597:             *  setup:
0598:             *
0599:             *  test procedure:
0600:             *  1.call exportMedia(null)
0601:             *    expected result: media exported to default location which is not null
0602:             *
0603:             *  2.create Media entity from nonexistent file and call exportMedia to valid location
0604:             *    expected result: ContentAccessException
0605:             *
0606:             *  3.call rebind(&quot;jpg&quot;, new JpegFormat())
0607:             *    create Media entity from jpeg file and call exportMedia with valid location
0608:             *    expected result: no exception, access file at new location and verify instance of JpegFormat
0609:             *
0610:             *  4.call rebind(&quot;gpl&quot;, new GenericPlaylistFormat())
0611:             *    create Media entity from playlist and call exportMedia with valid location
0612:             *    expected result: no exception, access file at new location and verify instance of GenericPlaylistFormat
0613:             *
0614:             * </pre>
0615:             */
0616:            public void testEMB103() throws MediaException, IOException,
0617:                    CreateException, RemoteException, NamingException,
0618:                    FinderException, RemoveException {
0619:
0620:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0621:                        embTestConfig.getJpgPictureName1());
0622:                String me1 = mebTester.createMediaEntityBean();
0623:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0624:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0625:
0626:                mebTester.bindMediaFormat("jpg", new JpegFormat());
0627:                mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
0628:                mebTester.bindMediaFormat("tmp", new GenericMediaFormat());
0629:                int exception = -1;
0630:                URL returnedLoc = null;
0631:                //
0632:                // test 1
0633:                //
0634:                returnedLoc = mebTester.exportMediaEntity(me1, null);
0635:                assertNotNull("test 1: location is null", returnedLoc);
0636:                testTrace("test 1 passed");
0637:                //
0638:                // test 2
0639:                //
0640:                String me2 = mebTester.createMediaEntityBean();
0641:                mebTester.setMediaEntityName(me2, "nonexistentBean.tmp");
0642:                String targetDirectory = embTestConfig.getMediaDir()
0643:                        + File.separatorChar + "export";
0644:
0645:                // remove C:
0646:                //URL targetLocation = new URL("file", embTestConfig.getTestClientIPAddress(), "/C:" + targetDirectory);
0647:                URL targetLocation = new URL("file", embTestConfig
0648:                        .getTestClientIPAddress(), targetDirectory);
0649:                try {
0650:                    exception = mebTester.exportMediaExceptions(me2,
0651:                            targetLocation);
0652:                } catch (Throwable e) {
0653:                    testTrace("test 2 threw " + e.toString());
0654:                }
0655:                assertEquals("test 2: Should throw a ContentAccessException",
0656:                        MediaEntityLocalTestDriver.CONTENTACCESS, exception);
0657:                testTrace("test 2 passed");
0658:                //
0659:                // test 3
0660:                //
0661:                returnedLoc = mebTester.exportMediaEntity(me1, targetLocation);
0662:                String exportedMedia = mebTester.createMediaEntityBean();
0663:                mebTester.setMediaEntityName(exportedMedia,
0664:                        "exportedJpgPicture.jpg");
0665:                mebTester.importMediaEntityContent(exportedMedia, returnedLoc,
0666:                        "testPicture.jpg");
0667:                assertTrue(
0668:                        "test 3: format of exported media is incorrect",
0669:                        mebTester.getMediaEntityFormat(exportedMedia) instanceof  JpegFormat);
0670:                assertTrue("test 3: content does not match", java.util.Arrays
0671:                        .equals(mebTester.getMediaEntityContent(me1), mebTester
0672:                                .getMediaEntityContent(exportedMedia)));
0673:                testTrace("test 3 passed");
0674:                mebTester.removeMEBByPK(exportedMedia);
0675:                //
0676:                // test 4
0677:                //
0678:                ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(
0679:                        ComplexMediaLocationInfo.MEDIAGPL1);
0680:                String me1NE = mebTester.createMediaEntityBean();
0681:                mebTester.setMediaEntityName(me1NE, me1NELocInfo.getRootFile()
0682:                        .getName());
0683:                mebTester.importMediaEntityContent(me1NE, me1NELocInfo
0684:                        .getRootURL(), me1NELocInfo.getRootFile().getName());
0685:
0686:                returnedLoc = mebTester
0687:                        .exportMediaEntity(me1NE, targetLocation);
0688:
0689:                exportedMedia = mebTester.createMediaEntityBean();
0690:                mebTester.setMediaEntityName(exportedMedia,
0691:                        "exportedPlaylist.gpl");
0692:                mebTester.importMediaEntityContent(exportedMedia, returnedLoc,
0693:                        "testPlaylist.gpl");
0694:                String[] children = mebTester
0695:                        .getMediaEntityChildren(exportedMedia);
0696:                assertTrue(
0697:                        "test 4: format of exported media is incorrect",
0698:                        mebTester.getMediaEntityFormat(exportedMedia) instanceof  GenericPlaylistFormat);
0699:                assertTrue("test 4: nonembedded media has no children",
0700:                        children.length > 0);
0701:                testTrace("test 4 passed");
0702:
0703:                // remove test MEBs
0704:                mebTester.removeMEBByPK(me1);
0705:                mebTester.removeMEBByPK(me2);
0706:                children = mebTester.getMediaEntityChildren(me1NE);
0707:                mebTester.removeMEBByPK(me1NE);
0708:                for (int i = 0; i < children.length; i++) {
0709:                    mebTester.removeMEBByPK(children[i]);
0710:                }
0711:                children = mebTester.getMediaEntityChildren(exportedMedia);
0712:                mebTester.removeMEBByPK(exportedMedia);
0713:                for (int i = 0; i < children.length; i++) {
0714:                    mebTester.removeMEBByPK(children[i]);
0715:                }
0716:
0717:                succeed();
0718:            }
0719:
0720:            /**
0721:             * <pre>
0722:             *
0723:             *  Testcase Name: getChildren()
0724:             *  Testcase Number: EMB104
0725:             *
0726:             *  setup: create Media entity from embedded media file, call me1
0727:             *    	  create Media entity from nonembedded media file, call me2
0728:             *
0729:             *  test procedure:
0730:             *  1.call me1.getChildren()
0731:             *  	 expected result: empty array
0732:             *
0733:             *  2.call me2.getChildren()
0734:             *    expected result: array containing all the MediaEntities which are referenced within me2
0735:             *
0736:             * </pre>
0737:             */
0738:            public void testEMB104() throws MediaException,
0739:                    MalformedURLException, IOException, CreateException,
0740:                    NamingException, FinderException, Throwable {
0741:
0742:                mebTester.bindMediaFormat("jpg", new JpegFormat());
0743:                mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
0744:                //
0745:                // test 1
0746:                //
0747:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0748:                        embTestConfig.getJpgPictureName1());
0749:                String me1 = mebTester.createMediaEntityBean();
0750:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0751:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0752:                String[] meChildren = mebTester.getMediaEntityChildren(me1);
0753:                assertTrue("test 1: Children array is not empty",
0754:                        meChildren.length == 0);
0755:                testTrace("test 1 passed");
0756:                //
0757:                // test 2
0758:                //
0759:                ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(
0760:                        ComplexMediaLocationInfo.MEDIAGPL1);
0761:                ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(
0762:                        ComplexMediaLocationInfo.MEDIAGPL1);
0763:                String me2NE = mebTester.createMediaEntityBean();
0764:                mebTester.setMediaEntityName(me2NE, me2NELocInfo.getRootFile()
0765:                        .getName());
0766:                mebTester.setMediaEntityContent(me2NE, me1NELocInfo
0767:                        .getRootFile());
0768:                meChildren = mebTester.getMediaEntityChildren(me2NE);
0769:                URL[] childURLs = new URL[meChildren.length];
0770:                for (int i = 0; i < meChildren.length; i++) {
0771:                    childURLs[i] = mebTester
0772:                            .getMediaEntityLocation(meChildren[i]);
0773:                }
0774:                URL[] me2NEChildURLs = me2NELocInfo.getChildURLs();
0775:                boolean childURLExists = false;
0776:                for (int j = 0; j < me2NEChildURLs.length; j++) {
0777:                    for (int k = 0; k < childURLs.length; k++) {
0778:                        if (me2NEChildURLs[j].equals(childURLs[k])) {
0779:                            childURLExists = true;
0780:                            break;
0781:                        }
0782:                        if (!childURLExists)
0783:                            fail("test 2: child location is missing");
0784:                    }
0785:                }
0786:                testTrace("test 2 passed");
0787:
0788:                // remove test MEBs
0789:                mebTester.removeMEBByPK(me1);
0790:                mebTester.removeMEBByPK(me2NE);
0791:                for (int i = 0; i < meChildren.length; i++) {
0792:                    mebTester.removeMEBByPK(meChildren[i]);
0793:                }
0794:
0795:                succeed();
0796:            }
0797:
0798:            /**
0799:             * <pre>
0800:             *
0801:             *  Testcase Name: getContent()
0802:             *  Testcase Number: EMB105
0803:             *
0804:             *  setup:
0805:             *
0806:             *  test procedure:
0807:             *  1.rebind(&quot;test&quot;, new GenericMediaFormat), create media entity and set content to random content with size of maxMediaSize
0808:             *    call getContent()
0809:             *    expected result: ContentTooLargeException
0810:             *
0811:             *  2.create small media entity, call getContent(), compare content with file content
0812:             *    expected result: content and file content are equal
0813:             *
0814:             *  3.create testInstance from nonexistent file and call getContent()
0815:             *    expected result: ContentAccessException
0816:             *
0817:             * </pre>
0818:             */
0819:            public void testEMB105() throws IOException, MediaException,
0820:                    Exception {
0821:
0822:                String testInstance = mebTester.createMediaEntityBean();
0823:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
0824:                int exception = -1;
0825:                // check if longRunningTest
0826:                if (embTestConfig.getIncludeLongRunningTest()) {
0827:                    int maxSize = Integer.parseInt(embTestConfig
0828:                            .getMaxMediaSize());
0829:                    if ((maxSize == -1) || (maxSize > Integer.MAX_VALUE)) {
0830:                        String largeFilePath = embTestConfig.getMediaDir()
0831:                                + File.separatorChar + "Generated"
0832:                                + File.separatorChar
0833:                                + "largeFileMediaBean.test";
0834:                        File largeFile = new File(largeFilePath);
0835:                        largeFile.createNewFile();
0836:                        FileOutputStream largeFileOutputStream = new FileOutputStream(
0837:                                largeFile);
0838:
0839:                        // create byte array 1 byte larger than maxMediaSize
0840:                        byte[] testArray = EMBStaticHelper
0841:                                .createRandomByteArray(Integer
0842:                                        .parseInt(embTestConfig
0843:                                                .getMaxMediaSize()) + 1);
0844:                        largeFileOutputStream.write(testArray);
0845:                        largeFileOutputStream.close();
0846:                        System.out.println("finished creating byte array");
0847:                        //
0848:                        // test 1
0849:                        //
0850:                        mebTester.setMediaEntityName(testInstance,
0851:                                "mediaBean.test");
0852:                        mebTester.importMediaEntityContent(testInstance,
0853:                                new URL("file", embTestConfig
0854:                                        .getTestClientIPAddress(), "/"
0855:                                        + largeFilePath), null);
0856:                        System.out.println("imported content");
0857:                        try {
0858:                            exception = mebTester
0859:                                    .getContentExceptions(testInstance);
0860:                        } catch (Throwable e) {
0861:                            fail("test 1 threw " + e.toString());
0862:                        }
0863:                        assertEquals(
0864:                                "test 1: Should throw a ContentTooLargeException",
0865:                                exception,
0866:                                MediaEntityLocalTestDriver.CONTENTTOOLARGE);
0867:                        testTrace("test 1 passed");
0868:                        largeFile.delete();
0869:                        mebTester.removeMEBByPK(testInstance);
0870:                    }
0871:                }
0872:                //
0873:                // test2
0874:                //
0875:                // random test file
0876:                File file1024Byte = new File(embTestConfig.getMediaDir()
0877:                        + File.separatorChar + "Generated" + File.separatorChar
0878:                        + "testMediaBeanFile.test");
0879:                file1024Byte.createNewFile();
0880:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
0881:                        file1024Byte);
0882:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
0883:                file1024ByteOutputStream.write(testArray);
0884:                file1024ByteOutputStream.close();
0885:                testInstance = mebTester.createMediaEntityBean();
0886:                mebTester
0887:                        .setMediaEntityName(testInstance, "testMediaBean.test");
0888:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
0889:                byte[] contentArray = mebTester
0890:                        .getMediaEntityContent(testInstance);
0891:                assertTrue("test 2: ", java.util.Arrays.equals(testArray,
0892:                        contentArray));
0893:                testTrace("test 2 passed");
0894:                mebTester.removeMEBByPK(testInstance);
0895:
0896:                //
0897:                // test 3
0898:                //
0899:                testInstance = mebTester.createMediaEntityBean();
0900:                mebTester.setMediaEntityName(testInstance, "mediaBean.test");
0901:                try {
0902:                    exception = mebTester.getContentExceptions(testInstance);
0903:                } catch (Throwable e) {
0904:                    fail("test 3 threw " + e.toString());
0905:                }
0906:                assertEquals("test 3: Should throw a ContentAccessException",
0907:                        exception, MediaEntityLocalTestDriver.CONTENTACCESS);
0908:                testTrace("test 3 passed");
0909:                mebTester.removeMEBByPK(testInstance);
0910:                succeed();
0911:            }
0912:
0913:            /**
0914:             * <pre>
0915:             *
0916:             *  Testcase Name: getDescription()
0917:             *  Testcase Number: EMB106
0918:             *
0919:             *  setup: create Media entity from media file
0920:             *
0921:             *  test procedure:
0922:             *  1.call setDescription with random string
0923:             *    call getDescription
0924:             *    expected result: returned string matches original
0925:             *
0926:             * </pre>
0927:             */
0928:            public void testEMB106() throws IOException, MediaException,
0929:                    CreateException, NamingException, FinderException,
0930:                    RemoveException {
0931:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
0932:                        embTestConfig.getJpgPictureName1());
0933:                String me1 = mebTester.createMediaEntityBean();
0934:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
0935:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
0936:                //
0937:                // test 1
0938:                //
0939:                String desc = EMBStaticHelper
0940:                        .createRandomString(EMBStaticHelper.randomInt(0, 10));
0941:                mebTester.setMediaEntityDescription(me1, desc);
0942:                assertEquals("test 1: description does not match", mebTester
0943:                        .getMediaEntityDescription(me1), desc);
0944:                testTrace("test 1 passed");
0945:                mebTester.removeMEBByPK(me1);
0946:                succeed();
0947:            }
0948:
0949:            /**
0950:             * <pre>
0951:             *
0952:             *      Testcase Name: getFormat()
0953:             *      Testcase Number: EMB107
0954:             *
0955:             *      setup:
0956:             *
0957:             *      test procedure:
0958:             *      1.rebind(&quot;jpg&quot;, new JpegFormat()), create random content file with name test.jpg
0959:             *      create MediaBean from file, run getFormat()
0960:             *      expected result: not null and instance of JpegFormat
0961:             *
0962:             *      2.unbind(&quot;xxx&quot;) catch FormatNotFoundException
0963:             *      create random content file with name test.xxx, create MediaBean from file, run getFormat()
0964:             *      expected result: FormatNotFoundException
0965:             *
0966:             * </pre>
0967:             */
0968:            public void testEMB107() throws IOException, MediaException,
0969:                    Exception {
0970:
0971:                String testInstance = mebTester.createMediaEntityBean();
0972:                // register media format
0973:                mebTester.bindMediaFormat("jpg", new JpegFormat());
0974:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
0975:                mebTester.bindMediaFormat("xxx", new GenericMediaFormat());
0976:                //
0977:                // test1
0978:                //
0979:                EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(
0980:                        embTestConfig.getJpgPictureName1());
0981:                mebTester.setMediaEntityName(testInstance, mediaLocInfo
0982:                        .getMediaName());
0983:                mebTester.setMediaEntityContent(testInstance, mediaLocInfo
0984:                        .getMediaFile());
0985:                assertNotNull("test 1", mebTester
0986:                        .getMediaEntityFormat(testInstance));
0987:                assertTrue(
0988:                        "test 1",
0989:                        mebTester.getMediaEntityFormat(testInstance) instanceof  JpegFormat);
0990:                testTrace("test 1 passed");
0991:                mebTester.removeMEBByPK(testInstance);
0992:                //
0993:                // test2
0994:                //
0995:                File file1024Byte = new File(embTestConfig.getMediaDir()
0996:                        + File.separatorChar + "Generated" + File.separatorChar
0997:                        + "test.test");
0998:                file1024Byte.createNewFile();
0999:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
1000:                        file1024Byte);
1001:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
1002:                file1024ByteOutputStream.write(testArray);
1003:                file1024ByteOutputStream.close();
1004:                testInstance = mebTester.createMediaEntityBean();
1005:                mebTester.setMediaEntityName(testInstance, "test.test");
1006:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
1007:                mebTester.setMediaEntityName(testInstance, "test.xxx");
1008:                mebTester.unbindMediaFormat("xxx");
1009:                int exception = -1;
1010:                try {
1011:                    exception = mebTester.getFormatExceptions(testInstance);
1012:                } catch (Throwable e) {
1013:                    fail("test 2 threw " + e.toString());
1014:                }
1015:                assertEquals("test 2 : Should throw a FormatNotFoundException",
1016:                        exception, MediaEntityLocalTestDriver.FORMATNOTFOUND);
1017:                testTrace("test 2 passed");
1018:                mebTester.removeMEBByPK(testInstance);
1019:
1020:                succeed();
1021:            }
1022:
1023:            /**
1024:             * <pre>
1025:             *
1026:             *      Testcase Name: getHeader()
1027:             *      Testcase Number: EMB108
1028:             *
1029:             *      setup:
1030:             *
1031:             *      test procedure:
1032:             *      1.rebind(&quot;jpg&quot;,new JpegFormat()), create media entity with name test.jpg
1033:             *      set content with jpg file and call getHeader
1034:             *      expected result: return value not null and equals getFormat().extractHeader()
1035:             *
1036:             *      2.unbind(&quot;xxx&quot;) catch FormatNotFoundException
1037:             *      create media entity, set name to &quot;test.xxx&quot; and set content to random content, run getHeader()
1038:             *      expected result: FormatNotFoundException is thrown
1039:             *
1040:             *      3.create file from random content, run getHeader()
1041:             *      expected result: FormatSyntaxException
1042:             *
1043:             *      4.use static byte array to create BMP file (contains unsupported version) and run getHeader()
1044:             *      expected result: FormatFeatureException
1045:             *
1046:             * </pre>
1047:             */
1048:            public void testEMB108() throws IOException, MediaException,
1049:                    Exception {
1050:                // register media format
1051:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1052:                mebTester.bindMediaFormat("bmp", new BmpFormat());
1053:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
1054:                mebTester.bindMediaFormat("xxx", new GenericMediaFormat());
1055:
1056:                File file1024Byte = new File(embTestConfig.getMediaDir()
1057:                        + File.separatorChar + "Generated" + File.separatorChar
1058:                        + "test.xxx");
1059:                file1024Byte.createNewFile();
1060:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
1061:                        file1024Byte);
1062:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
1063:                file1024ByteOutputStream.write(testArray);
1064:                file1024ByteOutputStream.close();
1065:                int exception = -1;
1066:                //
1067:                // test1
1068:                //
1069:                EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(
1070:                        embTestConfig.getJpgPictureName2());
1071:                String testInstance = mebTester.createMediaEntityBean();
1072:                mebTester.setMediaEntityName(testInstance, mediaLocInfo
1073:                        .getMediaName());
1074:                mebTester.setMediaEntityContent(testInstance, mediaLocInfo
1075:                        .getMediaFile());
1076:                InputStream in = new FileInputStream(mediaLocInfo
1077:                        .getMediaFile());
1078:                MediaHeader testHeader = mebTester
1079:                        .getMediaEntityHeader(testInstance);
1080:                assertTrue("test 1: ", testHeader.equals(mebTester
1081:                        .getMediaEntityFormat(testInstance).extractHeader(in)));
1082:                testTrace("test 1 passed");
1083:                in.close();
1084:                mebTester.removeMEBByPK(testInstance);
1085:                //
1086:                // test2
1087:                //
1088:                testInstance = mebTester.createMediaEntityBean();
1089:                mebTester.setMediaEntityName(testInstance, "test.test");
1090:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
1091:                mebTester.setMediaEntityName(testInstance, "test.xxx");
1092:                mebTester.unbindMediaFormat("xxx");
1093:                try {
1094:                    exception = mebTester.getHeaderExceptions(testInstance);
1095:                } catch (Throwable e) {
1096:                    fail("test 2 threw " + e.toString());
1097:                }
1098:                assertEquals("test 2: Should throw a FormatNotFoundException",
1099:                        exception, MediaEntityLocalTestDriver.FORMATNOTFOUND);
1100:                testTrace("test 2 passed");
1101:                mebTester.removeMEBByPK(testInstance);
1102:                //
1103:                // test 3
1104:                //
1105:                File file512Byte = new File(embTestConfig.getMediaDir()
1106:                        + File.separatorChar + "Generated" + File.separatorChar
1107:                        + "test.jpg");
1108:                file512Byte.createNewFile();
1109:                FileOutputStream file512ByteOutputStream = new FileOutputStream(
1110:                        file512Byte);
1111:                byte[] randomArray = EMBStaticHelper.createRandomByteArray(512);
1112:                file512ByteOutputStream.write(randomArray);
1113:                file512ByteOutputStream.close();
1114:                testInstance = mebTester.createMediaEntityBean();
1115:                mebTester.setMediaEntityName(testInstance, "test.test");
1116:                mebTester.setMediaEntityContent(testInstance, file512Byte);
1117:                mebTester.setMediaEntityName(testInstance, "test.jpg");
1118:                try {
1119:                    exception = mebTester.getHeaderExceptions(testInstance);
1120:                } catch (Throwable e) {
1121:                    fail("test 3 threw " + e.toString());
1122:                }
1123:                assertEquals("test 3: Should throw a FormatSyntaxException",
1124:                        MediaEntityLocalTestDriver.FORMATSYNTAX, exception);
1125:                testTrace("test 3 passed");
1126:                mebTester.removeMEBByPK(testInstance);
1127:                //
1128:                // test 4
1129:                //
1130:                byte[] corruptedBmpByteArray = { 76, 86, 70, 43, 0, 0, 0, 0, 0,
1131:                        0, 54, 4, 0, 0, 40, 0, 0, 0, 100, 0, 0, 0, 100, 0, 0,
1132:                        0, 1, 0, 8, 0, 0, 0, 0, 0, 16, 39, 0, 0, 0, 0, 0, 0, 0,
1133:                        0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1134:                        1, 0, 2, 2, 2, 0, 3, 3, 3, 0, 4, 4, 4, 0, 5, 5, 5, 0,
1135:                        6, 6, 6, 7, 7, 7, 0, 8, 8, 8, 0, 9, 9, 9, 0, 1, 10, 10,
1136:                        0, 11, 11 };
1137:                mebTester.bindMediaFormat("bmp", new BmpFormat());
1138:                testInstance = mebTester.createMediaEntityBean();
1139:                mebTester.setMediaEntityName(testInstance, "test.test");
1140:                mebTester.setMediaEntityContent(testInstance,
1141:                        corruptedBmpByteArray);
1142:                mebTester.setMediaEntityName(testInstance, "test.bmp");
1143:                try {
1144:                    exception = mebTester.getHeaderExceptions(testInstance);
1145:                } catch (Throwable e) {
1146:                    fail("test 4 threw " + e.toString());
1147:                }
1148:                assertEquals("test 4: Should throw a FormatSyntaxException",
1149:                        exception, MediaEntityLocalTestDriver.FORMATSYNTAX);
1150:                testTrace("test 4 passed");
1151:                mebTester.removeMEBByPK(testInstance);
1152:
1153:                succeed();
1154:            }
1155:
1156:            /**
1157:             * <pre>
1158:             *
1159:             *  Testcase Name: getLastModified()
1160:             *  Testcase Number: EMB109
1161:             *
1162:             *  setup: create Media entity from media file
1163:             *
1164:             *  test procedure:
1165:             *  1.call getLastModified()
1166:             *    expected result: no exception
1167:             *
1168:             *  2.call getLastModified and remember timestamp
1169:             *    call setDescription(&quot;abc&quot;) and wait 2 seconds
1170:             *    call getLastModified and verify it changed
1171:             *    expected result: timestamp updated
1172:             *
1173:             * </pre>
1174:             */
1175:            public void testEMB109() throws IOException, MediaException,
1176:                    InterruptedException, CreateException, RemoteException,
1177:                    NamingException, FinderException, RemoveException {
1178:
1179:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1180:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1181:                        embTestConfig.getJpgPictureName1());
1182:                String me1 = mebTester.createMediaEntityBean();
1183:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1184:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1185:                //
1186:                // test 1
1187:                //
1188:                try {
1189:                    mebTester.getMediaEntityLastModified(me1);
1190:                    testTrace("test 1 passed");
1191:                } catch (Throwable e) {
1192:                    fail("test 1 threw " + e.toString());
1193:                } //
1194:                // test 2
1195:                //
1196:                Date beforeStamp = new Date(mebTester
1197:                        .getMediaEntityLastModified(me1));
1198:                mebTester.setMediaEntityDescription(me1, "abc");
1199:                Thread.sleep(1000);
1200:                Date afterStamp = new Date(mebTester
1201:                        .getMediaEntityLastModified(me1));
1202:                assertTrue("test 2: Modification date", afterStamp
1203:                        .after(beforeStamp));
1204:                testTrace("test 2 passed");
1205:                mebTester.removeMEBByPK(me1);
1206:                succeed();
1207:            }
1208:
1209:            /**
1210:             * <pre>
1211:             *
1212:             *  Testcase Name: getListeners()
1213:             *  Testcase Number: EMB110
1214:             *
1215:             *  setup: create Media entity from media file
1216:             *  		  create Media listeners listener1, listener2, and listener3
1217:             *
1218:             *  test procedure:
1219:             *  1.call addListener(listener1), call addListener(listener2), call addListener(listener3)
1220:             *    call getListeners()
1221:             *    expected result: verify that listener1, listener2, and listener 3 are in array
1222:             *
1223:             * </pre>
1224:             */
1225:            public void testEMB110() throws IOException, MediaException,
1226:                    CreateException, RemoteException, NamingException,
1227:                    FinderException, RemoveException {
1228:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1229:
1230:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1231:                        embTestConfig.getJpgPictureName1());
1232:                String me1 = mebTester.createMediaEntityBean();
1233:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1234:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1235:
1236:                GenericMediaListener listener1 = new GenericMediaListener();
1237:                GenericMediaListener listener2 = new GenericMediaListener();
1238:                GenericMediaListener listener3 = new GenericMediaListener();
1239:                MediaListener[] mediaListenerArray = null;
1240:                //
1241:                // test 1
1242:                //
1243:                mebTester.addMediaEntityListener(me1, listener1);
1244:
1245:                try {
1246:                    mebTester.setMediaEntityName(me1, "newName1.jpg");
1247:                } catch (ListenerVetoException e) {
1248:                }
1249:                mebTester.addMediaEntityListener(me1, listener2);
1250:
1251:                try {
1252:                    mebTester.setMediaEntityName(me1, "newName2.jpg");
1253:                } catch (ListenerVetoException e) {
1254:                }
1255:                mebTester.addMediaEntityListener(me1, listener3);
1256:                try {
1257:                    mediaListenerArray = mebTester.getMediaEntityListeners(me1);
1258:                } catch (Throwable e) {
1259:                    fail("test 1 threw " + e.toString());
1260:                }
1261:                boolean ml1 = false;
1262:                boolean ml2 = false;
1263:                boolean ml3 = false;
1264:                assertEquals("test 1: does not contain 3 elements", 3,
1265:                        mediaListenerArray.length);
1266:                testTrace("test 1 passed");
1267:
1268:                mebTester.removeMEBByPK(me1);
1269:                succeed();
1270:            }
1271:
1272:            /**
1273:             * <pre>
1274:             *
1275:             *  Testcase Name: getLocation()
1276:             *  Testcase Number: EMB111
1277:             *
1278:             *  setup: create Media entity
1279:             *
1280:             *  test procedure:
1281:             *  1.call getLocation()
1282:             *    expected result: null
1283:             *
1284:             *  2.call setLocation()
1285:             *    call getLocation()
1286:             *    expected result: URL matches original random URL
1287:             *
1288:             * </pre>
1289:             */
1290:            public void testEMB111() throws IOException, MediaException,
1291:                    CreateException, RemoteException, NamingException,
1292:                    FinderException, RemoveException {
1293:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1294:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1295:                        embTestConfig.getJpgPictureName1());
1296:                String me1 = mebTester.createMediaEntityBean();
1297:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1298:                //
1299:                // test 1
1300:                //
1301:                assertNull("test 1: location not null", mebTester
1302:                        .getMediaEntityLocation(me1));
1303:                testTrace("test 1 passed");
1304:                //
1305:                // test 2
1306:                //
1307:                URL location = me1LocInfo.getMediaURL();
1308:                try {
1309:                    mebTester.setMediaEntityLocation(me1, location);
1310:                } catch (Throwable e) {
1311:                    fail("test 2 threw " + e.toString());
1312:                }
1313:                assertTrue("test 2: location URL does is incorrect", mebTester
1314:                        .getMediaEntityLocation(me1).equals(location));
1315:                testTrace("test 2 passed");
1316:                mebTester.removeMEBByPK(me1);
1317:                succeed();
1318:            }
1319:
1320:            /**
1321:             * <pre>
1322:             *
1323:             *  Testcase Name: getMetaData()
1324:             *  Testcase Number: EMB112
1325:             *
1326:             *  setup: create Media entity me1 and meta data entities md1 and md2
1327:             *
1328:             *  test procedure:
1329:             *  1.call me1.addMetaData(md1)
1330:             *    call me1.getMetaData()
1331:             *    expected result: 1 element array consisting of md1
1332:             *
1333:             *  2.call me1.addMetaData(md2)
1334:             *    call me1.getMetaData()
1335:             *    expected result: 2 element array consisting of md1 and md2
1336:             *
1337:             * </pre>
1338:             */
1339:            public void testEMB112() throws IOException, MediaException,
1340:                    CreateException, RemoteException, NamingException,
1341:                    FinderException, RemoveException {
1342:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1343:
1344:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1345:                        embTestConfig.getJpgPictureName1());
1346:                String me1 = mebTester.createMediaEntityBean();
1347:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1348:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1349:                String md1 = mebTester.createMetaDataEntityBean();
1350:                String md2 = mebTester.createMetaDataEntityBean();
1351:                //
1352:                // test 1
1353:                //
1354:                try {
1355:                    mebTester.addMediaEntityMetaData(me1, md1);
1356:                } catch (Throwable e) {
1357:                    fail("test 1 threw " + e.toString());
1358:                }
1359:                assertEquals("test 1: md1 not added", 1, mebTester
1360:                        .getMediaEntityMetaData(me1).length);
1361:                assertEquals("test 1: incorrect meta data", md1, mebTester
1362:                        .getMediaEntityMetaData(me1)[0]);
1363:                testTrace("test 1 passed");
1364:                //
1365:                // test 2
1366:                //
1367:                try {
1368:                    mebTester.addMediaEntityMetaData(me1, md2);
1369:                } catch (Throwable e) {
1370:                    fail("test 1 threw " + e.toString());
1371:                }
1372:                assertEquals("test 2: md2 not added", 2, mebTester
1373:                        .getMediaEntityMetaData(me1).length);
1374:                boolean match = false;
1375:                if (((md1.equals(mebTester.getMediaEntityMetaData(me1)[0])) && (md2
1376:                        .equals(mebTester.getMediaEntityMetaData(me1)[1])))
1377:                        || ((md1
1378:                                .equals(mebTester.getMediaEntityMetaData(me1)[1])) && (md2
1379:                                .equals(mebTester.getMediaEntityMetaData(me1)[0])))) {
1380:                    match = true;
1381:                }
1382:                assertTrue("test 2: meta data does not match", match);
1383:                testTrace("test 2 passed");
1384:
1385:                mebTester.removeMEBByPK(me1);
1386:                mebTester.removeMDEBByPK(md1);
1387:                mebTester.removeMDEBByPK(md2);
1388:
1389:                succeed();
1390:            }
1391:
1392:            /**
1393:             * <pre>
1394:             *
1395:             *  Testcase Name: getMimeType()
1396:             *  Testcase Number: EMB113
1397:             *
1398:             *  setup:
1399:             *
1400:             *  test procedure:
1401:             *  1.rebind(&quot;jpg&quot;, new JpegFormat())
1402:             *    create media entity from jpg file, run getMimeType()
1403:             *    expected result: result equals getFormat().getDefaultMimeType()
1404:             *
1405:             *  2.create random content file with name test.test, create media entity from file with mimetype &quot;test&quot;, run getMimeType()
1406:             *    expected result: result is &quot;test&quot;
1407:             *
1408:             *  3.create media entity from jpg file
1409:             *    then call unbind(&quot;jpg&quot;)
1410:             *    call getMimeType
1411:             *    expected result: FormatNotFound
1412:             *
1413:             * </pre>
1414:             */
1415:            public void testEMB113() throws IOException, MediaException,
1416:                    Exception {
1417:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1418:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
1419:
1420:                File file1024Byte = new File(embTestConfig.getMediaDir()
1421:                        + File.separatorChar + "Generated" + File.separatorChar
1422:                        + "test.test");
1423:                file1024Byte.createNewFile();
1424:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
1425:                        file1024Byte);
1426:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
1427:                file1024ByteOutputStream.write(testArray);
1428:                file1024ByteOutputStream.close();
1429:
1430:                EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(
1431:                        embTestConfig.getJpgPictureName1());
1432:                String me1 = mebTester.createMediaEntityBean();
1433:                mebTester.setMediaEntityName(me1, mediaLocInfo.getMediaName());
1434:                mebTester.setMediaEntityContent(me1, mediaLocInfo
1435:                        .getMediaFile());
1436:
1437:                String me2 = mebTester.createMediaEntityBean();
1438:                mebTester.setMediaEntityName(me2, "test.test");
1439:                mebTester.setMediaEntityContent(me2, file1024Byte);
1440:                //
1441:                // test1
1442:                //
1443:                assertEquals("test1: ", mebTester.getMediaEntityMimeType(me1),
1444:                        mebTester.getMediaEntityFormat(me1)
1445:                                .getDefaultMimeType());
1446:                testTrace("test 1 passed");
1447:                //
1448:                // test2
1449:                //
1450:                mebTester.setMediaEntityMimeType(me2, "test");
1451:                assertEquals("test 2: ", "test", mebTester
1452:                        .getMediaEntityMimeType(me2));
1453:                testTrace("test 2 passed");
1454:                //
1455:                // test 3
1456:                //
1457:                mebTester.unbindMediaFormat("jpg");
1458:                int exception = -1;
1459:                try {
1460:                    exception = mebTester.getMimeTypeExceptions(me1);
1461:                } catch (Throwable e) {
1462:                    fail("test 3 threw " + e.toString());
1463:                }
1464:                assertEquals("test 3: Should throw a FormatNotFoundException",
1465:                        MediaEntityLocalTestDriver.FORMATNOTFOUND, exception);
1466:                testTrace("test 3 passed");
1467:
1468:                mebTester.removeMEBByPK(me1);
1469:                mebTester.removeMEBByPK(me2);
1470:
1471:                succeed();
1472:            }
1473:
1474:            /**
1475:             * <pre>
1476:             *
1477:             *  Testcase Name: getName()
1478:             *  Testcase Number: EMB114
1479:             *
1480:             *  setup:
1481:             *
1482:             *  test procedure:
1483:             *  1.rebind(&quot;jpg&quot;, new JpegFormat()), create random content file with name test.jpg, create MediaBean from file with mimetype null, run getName()
1484:             *    expected result: result is not null and contains a '.'
1485:             *
1486:             * </pre>
1487:             */
1488:            public void testEMB114() throws IOException, RemoveException,
1489:                    CreateException, RemoteException, NamingException,
1490:                    FinderException, MediaException {
1491:                // random file
1492:                EmbeddedMediaLocationInfo mediaLocInfo = new EmbeddedMediaLocationInfo(
1493:                        embTestConfig.getJpgPictureName1());
1494:                // register media format
1495:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1496:                String testInstance = mebTester.createMediaEntityBean();
1497:                mebTester.setMediaEntityName(testInstance, mediaLocInfo
1498:                        .getMediaName());
1499:                mebTester.setMediaEntityContent(testInstance, mediaLocInfo
1500:                        .getMediaFile());
1501:                //
1502:                // test1
1503:                //
1504:                assertNotNull(mebTester.getMediaEntityName(testInstance));
1505:                assertTrue("test 1: ", mebTester.getMediaEntityName(
1506:                        testInstance).indexOf(".") != -1);
1507:                testTrace("test 1 passed");
1508:                mebTester.removeMEBByPK(testInstance);
1509:                succeed();
1510:            }
1511:
1512:            /**
1513:             * <pre>
1514:             *
1515:             *  Testcase Name: getNextVersion()
1516:             *  Testcase Number: EMB115
1517:             *
1518:             *  setup: create Media entities me1 and me2
1519:             *
1520:             *  test procedure:
1521:             *  1.call me2.setPreviousVersion(me1)
1522:             *    call me1.getNextVersion()
1523:             *    expected result: return me2
1524:             *
1525:             *  2.call me2.getNextVersion()
1526:             *    expected result: null
1527:             *
1528:             * </pre>
1529:             */
1530:            public void testEMB115() throws IOException, MediaException,
1531:                    CreateException, RemoteException, NamingException,
1532:                    FinderException, RemoveException {
1533:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1534:                        embTestConfig.getJpgPictureName1());
1535:                String me1 = mebTester.createMediaEntityBean();
1536:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1537:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1538:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
1539:                        embTestConfig.getJpgPictureName2());
1540:                String me2 = mebTester.createMediaEntityBean();
1541:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
1542:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
1543:                //
1544:                // test 1
1545:                //
1546:                try {
1547:                    mebTester.setMediaEntityPreviousVersion(me2, me1);
1548:                } catch (Throwable e) {
1549:                    fail("test 1 threw " + e.toString());
1550:                }
1551:                assertEquals("test 1: next version is not me2", me2, mebTester
1552:                        .getMediaEntityNextVersion(me1));
1553:                testTrace("test 1 passed");
1554:                //
1555:                // test 2
1556:                //
1557:                assertNull("test 2: next version is not null", mebTester
1558:                        .getMediaEntityNextVersion(me2));
1559:                testTrace("test 2 passed");
1560:
1561:                mebTester.removeMEBByPK(me1);
1562:                mebTester.removeMEBByPK(me2);
1563:                succeed();
1564:            }
1565:
1566:            /**
1567:             * <pre>
1568:             *
1569:             *  Testcase Name: getParents()
1570:             *  Testcase Number: EMB116()
1571:             *
1572:             *  setup: create Media entity from embedded media file, call me1
1573:             *  		  create Media entity from nonembedded media file, call me2
1574:             *
1575:             *  test procedure:
1576:             *  1.call me1.getParent()
1577:             *  	 expected result: empty array
1578:             *
1579:             *  2.call me2.getChildren()
1580:             *    for all children, call getParents()
1581:             *    expected result: me2
1582:             *
1583:             * </pre>
1584:             */
1585:            public void testEMB116() throws MediaException, IOException,
1586:                    CreateException, RemoteException, NamingException,
1587:                    FinderException, RemoveException {
1588:                //
1589:                // test 1
1590:                //
1591:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1592:                        embTestConfig.getJpgPictureName1());
1593:                String me1 = mebTester.createMediaEntityBean();
1594:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1595:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1596:                String[] meParents = mebTester.getMediaEntityParents(me1);
1597:                assertTrue("test 1: parent array is not empty",
1598:                        meParents.length == 0);
1599:                testTrace("test 1 passed");
1600:                //
1601:                // test 2
1602:                //
1603:                ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(
1604:                        ComplexMediaLocationInfo.MEDIAGPL1);
1605:                String me2NE = mebTester.createMediaEntityBean();
1606:                mebTester.setMediaEntityName(me2NE, me2NELocInfo.getRootFile()
1607:                        .getName());
1608:                mebTester.setMediaEntityContent(me2NE, me2NELocInfo
1609:                        .getRootFile());
1610:                String[] meChildren = mebTester.getMediaEntityChildren(me2NE);
1611:                for (int i = 0; i < meChildren.length; i++) {
1612:                    meParents = mebTester.getMediaEntityParents(meChildren[i]);
1613:                    assertEquals("test 2: does not contain 1 element",
1614:                            meParents.length, 1);
1615:                    assertEquals("test 2: parent is not me2", meParents[0],
1616:                            me2NE);
1617:                }
1618:                testTrace("test 2 passed");
1619:
1620:                mebTester.removeMEBByPK(me1);
1621:                mebTester.removeMEBByPK(me2NE);
1622:                succeed();
1623:            }
1624:
1625:            /**
1626:             * <pre>
1627:             *
1628:             *  Testcase Name: getPreviousVersion()
1629:             *  Testcase Number: EMB117
1630:             *
1631:             *  setup: create Media entities me1 and me2 from media files
1632:             *
1633:             *  test procedure:
1634:             *  1.call me2.setPreviousVersion(me1)
1635:             *    call me2.getPreviousVersion
1636:             *    expected result: me1
1637:             *
1638:             *  2.call me1.getPreviousVersion()
1639:             *    expected result: null
1640:             *
1641:             * </pre>
1642:             */
1643:            public void testEMB117() throws IOException, MediaException,
1644:                    CreateException, RemoteException, NamingException,
1645:                    FinderException, RemoveException {
1646:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1647:                        embTestConfig.getJpgPictureName1());
1648:                String me1 = mebTester.createMediaEntityBean();
1649:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1650:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1651:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
1652:                        embTestConfig.getJpgPictureName2());
1653:                String me2 = mebTester.createMediaEntityBean();
1654:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
1655:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
1656:                //
1657:                // test 1
1658:                //
1659:                mebTester.setMediaEntityPreviousVersion(me2, me1);
1660:                assertEquals("test 1: previous version is not me1", mebTester
1661:                        .getMediaEntityPreviousVersion(me2), me1);
1662:                testTrace("test 1 passed");
1663:                //
1664:                // test 2
1665:                //
1666:                assertNull("test 2: previous version is not null", mebTester
1667:                        .getMediaEntityPreviousVersion(me1));
1668:                testTrace("test 2 passed");
1669:
1670:                mebTester.removeMEBByPK(me1);
1671:                mebTester.removeMEBByPK(me2);
1672:                succeed();
1673:            }
1674:
1675:            /**
1676:             * <pre>
1677:             *
1678:             *  Testcase Name: getProxy()
1679:             *  Testcase Number: EMB118
1680:             *
1681:             *  setup: create Media entities me1 and me2 from media jpeg files
1682:             *
1683:             *  test procedure:
1684:             *  1.call me1.getProxy()
1685:             *    expected result: not null
1686:             *
1687:             *  2.call me1.setProxy(me2)
1688:             *    call me1.getProxy()
1689:             *    expected result: me2
1690:             *
1691:             * </pre>
1692:             */
1693:            public void testEMB118() throws IOException, MediaException,
1694:                    CreateException, RemoteException, NamingException,
1695:                    FinderException, RemoveException {
1696:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1697:                        embTestConfig.getJpgPictureName1());
1698:                String me1 = mebTester.createMediaEntityBean();
1699:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1700:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1701:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
1702:                        embTestConfig.getJpgPictureName2());
1703:                String me2 = mebTester.createMediaEntityBean();
1704:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
1705:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
1706:                MediaBean jpgMediaBean = new MediaBean(me2LocInfo
1707:                        .getMediaFile(), "image/jpeg");
1708:                //
1709:                // test 1
1710:                //
1711:                Media testMedia = mebTester.getMediaEntityProxy(me1);
1712:                assertNotNull("test 1: proxy is null", testMedia);
1713:                testTrace("test 1 passed");
1714:                //
1715:                // test 2
1716:                //
1717:                mebTester.setMediaEntityProxy(me1, me2);
1718:                Media proxy = mebTester.getMediaEntityProxy(me1);
1719:                assertNotNull("test 2: proxy is null", proxy);
1720:                assertTrue("test 2: proxy is not me2", java.util.Arrays.equals(
1721:                        proxy.getContent(), jpgMediaBean.getContent()));
1722:                testTrace("test 2 passed");
1723:
1724:                mebTester.removeMEBByPK(me1);
1725:                mebTester.removeMEBByPK(me2);
1726:                succeed();
1727:            }
1728:
1729:            /**
1730:             * <pre>
1731:             *
1732:             *  Testcase Name: getSize()
1733:             *  Testcase Number: EMB119
1734:             *
1735:             *  setup:
1736:             *
1737:             *  test procedure:
1738:             *  1.create random content file with name test.jpg and content size 1024, create MediaBean from file, run getSize()
1739:             *    expected result: result is 1024
1740:             *
1741:             * </pre>
1742:             */
1743:            public void testEMB119() throws IOException, MediaException,
1744:                    Exception {
1745:                // random file
1746:                File file1024Byte = new File(embTestConfig.getMediaDir()
1747:                        + File.separatorChar + "Generated" + File.separatorChar
1748:                        + "test.jpg");
1749:                file1024Byte.createNewFile();
1750:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
1751:                        file1024Byte);
1752:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
1753:                file1024ByteOutputStream.write(testArray);
1754:                file1024ByteOutputStream.close();
1755:                // register media format
1756:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
1757:                String testInstance = mebTester.createMediaEntityBean();
1758:                mebTester.setMediaEntityName(testInstance, "test.test");
1759:                int exception = -1;
1760:                //
1761:                // test1
1762:                //
1763:                try {
1764:                    exception = mebTester.getSizeExceptions(testInstance);
1765:                } catch (Throwable e) {
1766:                    fail("test 1 threw " + e.toString());
1767:                }
1768:                assertEquals("test 1: Should throw a ContentAccessException",
1769:                        exception, MediaEntityLocalTestDriver.CONTENTACCESS);
1770:                testTrace("test 1 passed");
1771:                //
1772:                // test 2
1773:                //
1774:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
1775:                assertEquals("test 1: ", 1024, mebTester
1776:                        .getMediaEntitySize(testInstance));
1777:                testTrace("test 2 passed");
1778:
1779:                mebTester.removeMEBByPK(testInstance);
1780:                succeed();
1781:            }
1782:
1783:            /**
1784:             * <pre>
1785:             *
1786:             *  Testcase Name: importMedia(URL, String)
1787:             *  Testcase Number: EMB120
1788:             *
1789:             *  setup: create Media entity me1 from jpeg media file
1790:             *  		  rebind &quot;jpg&quot; and &quot;bmp&quot; file extensions to media format registry
1791:             *
1792:             *  test procedure:
1793:             *  1.call me1.importMedia(null, null)
1794:             *    expected result: NullPointerException
1795:             *
1796:             *  2.a.create media entity and call setName
1797:             *      call me1.importMedia(validLocation, null)
1798:             *      expected result: no exception, call me1.getContent and verify media content and format
1799:             *  					    verify name remained the same
1800:             *    b.create media entity and call importMedia(validLocation, null)
1801:             *      expected result: no exception, call getContent and verify content and format
1802:             *  						check that getName is not null
1803:             *
1804:             *  3.create URL from valid jpeg file location
1805:             *    call me1.importMedia(location, randomName) where randomName has the &quot;jpg&quot; file extension
1806:             *    expected result: no exception
1807:             *  					  call me1.getContent and me1.getName to verify new content and name
1808:             *
1809:             *  4.create URL from valid bmp file location
1810:             *    call me1.importMedia(location, randomName) where randomName has the &quot;bmp&quot; file extension
1811:             *    expected result: no exception
1812:             *  					  call me1.getFormat() and verify instance of BmpFormat
1813:             *
1814:             *  5.create URL from nonexistent file location
1815:             *    call me1.importMedia(location, null)
1816:             *    expected result: ContentAccessException
1817:             *
1818:             *  6.create URL pointing to valid playlist location
1819:             *    call me1.importMedia(location, randomName) where randomName has the &quot;gpl&quot; file extension
1820:             *    expected result: no exception
1821:             *  					  verify getChildren is not null
1822:             *
1823:             *  7.create media entity, call setName and setContent
1824:             *    call addListener
1825:             *    call importMedia(validLocation, name)
1826:             *    expected result: ListenerVetoException
1827:             *
1828:             *  8.create media entity and setName
1829:             *    call importMedia with URL pointing to file larger than maxMediaSize
1830:             *    expected result: ContentTooLargeException
1831:             *
1832:             * </pre>
1833:             */
1834:            public void testEMB120() throws IOException, MediaException,
1835:                    InterruptedException, CreateException, RemoteException,
1836:                    NamingException, FinderException, RemoveException {
1837:
1838:                mebTester.bindMediaFormat("jpg", new JpegFormat());
1839:                mebTester.bindMediaFormat("bmp", new BmpFormat());
1840:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
1841:
1842:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
1843:                        embTestConfig.getJpgPictureName1());
1844:                String me1 = mebTester.createMediaEntityBean();
1845:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
1846:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
1847:
1848:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
1849:                        embTestConfig.getJpgPictureName2());
1850:                EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(
1851:                        embTestConfig.getBmpPictureName1());
1852:
1853:                int exception = -1;
1854:                //
1855:                // test 1
1856:                //
1857:                try {
1858:                    exception = mebTester
1859:                            .importMediaExceptions(me1, null, null);
1860:                } catch (Throwable e) {
1861:                    fail("test 1 threw " + e.toString());
1862:                }
1863:                assertEquals("test 1: Should throw a NullPointerException",
1864:                        MediaEntityLocalTestDriver.NULLPOINTER, exception);
1865:                testTrace("test 1 passed");
1866:                //
1867:                // test 2a
1868:                //
1869:                Date beforeStamp = new Date(mebTester
1870:                        .getMediaEntityLastModified(me1));
1871:                mebTester.importMediaEntityContent(me1, me2LocInfo
1872:                        .getMediaURL(), null);
1873:                Thread.sleep(1000);
1874:                Date afterStamp = new Date(mebTester
1875:                        .getMediaEntityLastModified(me1));
1876:                assertTrue("test 2a: Modification date", afterStamp
1877:                        .after(beforeStamp));
1878:                assertTrue("test 2a: media is not in Jpeg format", mebTester
1879:                        .getMediaEntityFormat(me1) instanceof  JpegFormat);
1880:                assertTrue("test 2a: new content does not match",
1881:                        Arrays
1882:                                .equals(mebTester.getMediaEntityContent(me1),
1883:                                        getByteArrayFromFile(me2LocInfo
1884:                                                .getMediaFile())));
1885:                //TODO : EMB 120 : not compliant, import change name only if name is not already set
1886:                //assertEquals("test 2a: name changed", me2LocInfo.getMediaName(), mebTester.getMediaEntityName(me1));
1887:                testTrace("test 2a passed");
1888:                //
1889:                // test 2b
1890:                //
1891:                String me2 = mebTester.createMediaEntityBean();
1892:                mebTester.importMediaEntityContent(me2, me2LocInfo
1893:                        .getMediaURL(), null);
1894:                assertTrue("test 2b: media is not in Jpeg format", mebTester
1895:                        .getMediaEntityFormat(me2) instanceof  JpegFormat);
1896:                assertTrue("test 2b: new content does not match",
1897:                        Arrays
1898:                                .equals(mebTester.getMediaEntityContent(me2),
1899:                                        getByteArrayFromFile(me2LocInfo
1900:                                                .getMediaFile())));
1901:                assertNotNull("test 2b: name is null", mebTester
1902:                        .getMediaEntityName(me2));
1903:                testTrace("test 2b passed");
1904:                //
1905:                // test 3
1906:                //
1907:                beforeStamp = new Date(mebTester
1908:                        .getMediaEntityLastModified(me1));
1909:                mebTester.importMediaEntityContent(me1, me2LocInfo
1910:                        .getMediaURL(), me2LocInfo.getMediaName());
1911:                Thread.sleep(1000);
1912:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
1913:                assertTrue("test 3: Modification date", afterStamp
1914:                        .after(beforeStamp));
1915:                assertTrue("test 3: media is not in Jpeg format", mebTester
1916:                        .getMediaEntityFormat(me1) instanceof  JpegFormat);
1917:                assertTrue("test 3: new content does not match",
1918:                        java.util.Arrays
1919:                                .equals(mebTester.getMediaEntityContent(me1),
1920:                                        getByteArrayFromFile(me2LocInfo
1921:                                                .getMediaFile())));
1922:                assertEquals("test 3: name not changed", mebTester
1923:                        .getMediaEntityName(me1), me2LocInfo.getMediaName());
1924:                testTrace("test 3 passed");
1925:                //
1926:                // test 4
1927:                //
1928:                beforeStamp = new Date(mebTester
1929:                        .getMediaEntityLastModified(me1));
1930:                mebTester.importMediaEntityContent(me1, me3LocInfo
1931:                        .getMediaURL(), me3LocInfo.getMediaName());
1932:                Thread.sleep(1000);
1933:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
1934:                assertTrue("test 4: Modification date", afterStamp
1935:                        .after(beforeStamp));
1936:                assertTrue("test 4: media is not in Bmp format", mebTester
1937:                        .getMediaEntityFormat(me1) instanceof  BmpFormat);
1938:                assertTrue("test 4: new content does not match", Arrays.equals(
1939:                        mebTester.getMediaEntityContent(me1),
1940:                        getByteArrayFromFile(me3LocInfo.getMediaFile())));
1941:                assertEquals("test 4: name not changed", mebTester
1942:                        .getMediaEntityName(me1), me3LocInfo.getMediaName());
1943:                testTrace("test 4 passed");
1944:                //
1945:                // test 5
1946:                //
1947:                String nonexistentFilePath = embTestConfig.getMediaDir()
1948:                        + File.separatorChar + "nonexistentFile.bmp";
1949:                URL srcLocation = new URL("file", embTestConfig
1950:                        .getTestClientIPAddress(), nonexistentFilePath);
1951:                try {
1952:                    exception = mebTester.importMediaExceptions(me1,
1953:                            srcLocation, null);
1954:                } catch (Throwable e) {
1955:                    fail("test 5 threw " + e.toString());
1956:                }
1957:                assertEquals("test 5: Should throw a ContentAccessException",
1958:                        exception, MediaEntityLocalTestDriver.CONTENTACCESS);
1959:                testTrace("test 5 passed");
1960:                //
1961:                // test 6
1962:                //
1963:                ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(
1964:                        ComplexMediaLocationInfo.MEDIAGPL1);
1965:                String me1NE = mebTester.createMediaEntityBean();
1966:                mebTester.setMediaEntityName(me1NE, me1NELocInfo.getRootFile()
1967:                        .getName());
1968:                mebTester.setMediaEntityContent(me1NE, me1NELocInfo
1969:                        .getRootFile());
1970:                beforeStamp = new Date(mebTester
1971:                        .getMediaEntityLastModified(me1));
1972:                mebTester.importMediaEntityContent(me1, me1NELocInfo
1973:                        .getRootURL(), me1NELocInfo.getRootFile().getName());
1974:                Thread.sleep(1000);
1975:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
1976:                assertTrue("test 6: Modification date", afterStamp
1977:                        .after(beforeStamp));
1978:                assertTrue(
1979:                        "test 6: media is not in playlist format",
1980:                        mebTester.getMediaEntityFormat(me1) instanceof  GenericPlaylistFormat);
1981:                assertEquals("test 6: name not changed", mebTester
1982:                        .getMediaEntityName(me1), me1NELocInfo.getRootFile()
1983:                        .getName());
1984:                assertTrue("test 6: nonembedded media has no children",
1985:                        mebTester.getMediaEntityChildren(me1).length > 0);
1986:                testTrace("test 6 passed");
1987:                //
1988:                // test 7
1989:                //
1990:                String me3 = mebTester.createMediaEntityBean();
1991:                mebTester.setMediaEntityName(me3, me3LocInfo.getMediaName());
1992:                mebTester.setMediaEntityContent(me3, me3LocInfo.getMediaFile());
1993:                mebTester.addMediaEntityListener(me3,
1994:                        new GenericMediaListener());
1995:                try {
1996:                    exception = mebTester.importMediaExceptions(me3, me2LocInfo
1997:                            .getMediaURL(), me2LocInfo.getMediaName());
1998:                } catch (Throwable e) {
1999:                    fail("test 7 threw " + e.toString());
2000:                }
2001:                assertEquals("test 7: Should throw a ListenerVetoException",
2002:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
2003:                testTrace("test 7 passed");
2004:                //
2005:                // test 8
2006:                //
2007:                if (embTestConfig.getIncludeLongRunningTest()) {
2008:                    String largeFilePath = embTestConfig.getMediaDir()
2009:                            + File.separatorChar + "Generated"
2010:                            + File.separatorChar + "largeFile.test";
2011:                    File largeFile = new File(largeFilePath);
2012:                    largeFile.createNewFile();
2013:                    FileOutputStream largeFileOutputStream = new FileOutputStream(
2014:                            largeFile);
2015:                    // create byte array 1 byte larger than maxMediaSize
2016:                    byte[] testArray = EMBStaticHelper
2017:                            .createRandomByteArray(Integer
2018:                                    .parseInt(embTestConfig.getMaxMediaSize()) + 1);
2019:                    largeFileOutputStream.write(testArray);
2020:                    largeFileOutputStream.close();
2021:
2022:                    String testInstance = mebTester.createMediaEntityBean();
2023:                    mebTester.setMediaEntityName(testInstance,
2024:                            "largeMedia.test");
2025:                    try {
2026:                        exception = mebTester.importMediaExceptions(
2027:                                testInstance, new URL("file", embTestConfig
2028:                                        .getTestClientIPAddress(),
2029:                                        largeFilePath), null);
2030:                    } catch (Throwable e) {
2031:                        fail("test 8 threw " + e.toString());
2032:                    }
2033:                    assertEquals(
2034:                            "test 8: Should throw a ContentTooLargeException",
2035:                            MediaEntityLocalTestDriver.CONTENTTOOLARGE,
2036:                            exception);
2037:                    testTrace("test 8 passed");
2038:                    largeFile.delete();
2039:                    mebTester.removeMEBByPK(testInstance);
2040:                }
2041:
2042:                mebTester.removeMEBByPK(me1);
2043:                mebTester.removeMEBByPK(me2);
2044:                mebTester.removeMEBByPK(me3);
2045:                mebTester.removeMEBByPK(me1NE);
2046:                succeed();
2047:            }
2048:
2049:            /**
2050:             * <pre>
2051:             *
2052:             *  Testcase Name: readContent(long position, byte[] buffer)
2053:             *  Testcase Number: EMB121
2054:             *
2055:             *  setup: create file (1024 byte), rebind(&quot;test&quot;, new GenericMediaFormat()), create MediaBean
2056:             *  	   	  create byte array buffer of size 1024 bytes
2057:             *
2058:             *  test procedure:
2059:             *  1.call readContent(-1,testBuffer)
2060:             *    expected result: IndexOutOfBoundsException
2061:             *
2062:             *  2.call readContent(1025,testBuffer)
2063:             *    expected result: IndexOutOfBoundsException
2064:             *
2065:             *  3.call readContent(0,null)
2066:             *    expected result: NullPointerException
2067:             *
2068:             *  4.call readContent(10,testBuffer) with buffer size 100 bytes
2069:             *    compare to media content offset 10, length of return value
2070:             *    expected result: same content
2071:             *
2072:             *  5.call readContent(1024,testBuffer)
2073:             *    expected result: -1 returned with empty buffer
2074:             *
2075:             *  6.create testInstance from nonexistent file and call readContent(0,buffer)
2076:             *    expected result: ContentAccessException
2077:             *
2078:             *  7.create testInstance of size 100 bytes and buffer of size 1024 bytes
2079:             *    call readContent(0,testBuffer) and compare content of media and buffer
2080:             *    expected result: buffer partially filled (return value is the length)
2081:             *
2082:             * </pre>
2083:             */
2084:            public void testEMB121() throws IOException, MediaException,
2085:                    Exception {
2086:                //
2087:                // Initialize the testcase
2088:                //
2089:                File file1024Byte = new File(embTestConfig.getMediaDir()
2090:                        + File.separatorChar + "Generated" + File.separatorChar
2091:                        + "testFile1024Byte.test");
2092:                if (file1024Byte.exists())
2093:                    file1024Byte.delete();
2094:                file1024Byte.createNewFile();
2095:                file1024Byte.deleteOnExit();
2096:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
2097:                        file1024Byte);
2098:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
2099:                file1024ByteOutputStream.write(testArray);
2100:                file1024ByteOutputStream.close();
2101:
2102:                // register media format
2103:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
2104:                String testInstance = mebTester.createMediaEntityBean();
2105:                mebTester.setMediaEntityName(testInstance,
2106:                        "testFile1024Byte.test");
2107:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
2108:
2109:                byte[] testBuffer = new byte[1024];
2110:                int exception = -1;
2111:
2112:                //FIXME : EMB 121 : test 1 -> 3 crash the next one(content null)
2113:
2114:                //
2115:                // test 1
2116:                //
2117:                //        try {
2118:                //            exception = mebTester.readContentExceptions(testInstance, -1, testBuffer);
2119:                //        } catch (Throwable e) {
2120:                //            fail("test 1 threw " + e.toString());
2121:                //        }
2122:                //        assertEquals("test 1: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
2123:                //                exception);
2124:                //        testTrace("test 1 passed");
2125:                //
2126:                // test 2
2127:                //
2128:                //        try {
2129:                //            exception = mebTester.readContentExceptions(testInstance, 1025, testBuffer);
2130:                //        } catch (Throwable e) {
2131:                //            fail("test 2 threw " + e.toString());
2132:                //        }
2133:                //        assertEquals("test 2: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
2134:                //                exception);
2135:                //        testTrace("test 2 passed");
2136:                //
2137:                // test 3
2138:                //
2139:                //        try {
2140:                //            exception = mebTester.readContentExceptions(testInstance, 0, null);
2141:                //        } catch (Throwable e) {
2142:                //            fail("test 3 threw " + e.toString());
2143:                //        }
2144:                //        assertEquals("test 3: Should throw an NullPointerException", MediaEntityLocalTestDriver.NULLPOINTER, exception);
2145:                //        testTrace("test 3 passed");
2146:
2147:                //
2148:                // test 4
2149:                //
2150:                byte[] buffer100Byte = new byte[100];
2151:                boolean contentMatch = mebTester.readCompareContent(
2152:                        testInstance, 10, buffer100Byte, file1024Byte);
2153:                assertTrue("test 4: content does not match", contentMatch);
2154:                testTrace("test 4 passed");
2155:                //
2156:                // test 5
2157:                //
2158:                int amountCopied = mebTester.readMediaEntityContent(
2159:                        testInstance, 1024, testBuffer);
2160:                assertEquals("test 5: ", -1, amountCopied);
2161:                testTrace("test 5 passed");
2162:                mebTester.removeMEBByPK(testInstance);
2163:                //
2164:                // test 6
2165:                //
2166:                testInstance = mebTester.createMediaEntityBean();
2167:                mebTester.setMediaEntityName(testInstance, "testMedia.test");
2168:                try {
2169:                    exception = mebTester.readContentExceptions(testInstance,
2170:                            0, testBuffer);
2171:                } catch (Throwable e) {
2172:                    fail("test 6 threw " + e.toString());
2173:                }
2174:                assertEquals("test 6: Should throw a ContentAccessException",
2175:                        MediaEntityLocalTestDriver.CONTENTACCESS, exception);
2176:                testTrace("test 6 passed");
2177:                mebTester.removeMEBByPK(testInstance);
2178:                //
2179:                // test 7
2180:                //
2181:                File file100Byte = new File(embTestConfig.getMediaDir()
2182:                        + File.separatorChar + "Generated" + File.separatorChar
2183:                        + "testFile100Byte.test");
2184:                file100Byte.createNewFile();
2185:                FileOutputStream file100ByteOutputStream = new FileOutputStream(
2186:                        file100Byte);
2187:                byte[] randomTestArray = EMBStaticHelper
2188:                        .createRandomByteArray(100);
2189:                file100ByteOutputStream.write(randomTestArray);
2190:                file100ByteOutputStream.close();
2191:
2192:                testInstance = mebTester.createMediaEntityBean();
2193:                mebTester.setMediaEntityName(testInstance,
2194:                        "testFile100Byte.test");
2195:                mebTester.setMediaEntityContent(testInstance, file100Byte);
2196:                contentMatch = mebTester.readCompareContent(testInstance, 0,
2197:                        testBuffer, file100Byte);
2198:                assertTrue("test 7: ", contentMatch);
2199:                testTrace("test 7 passed");
2200:                mebTester.removeMEBByPK(testInstance);
2201:                succeed();
2202:            }
2203:
2204:            /**
2205:             * <pre>
2206:             *
2207:             *  Testcase Name: readContent(long position, byte[] buffer, int offset, int length)
2208:             *  Testcase Number: EMB122
2209:             *
2210:             *  setup: create file (1024 byte), rebind(&quot;test&quot;, new GenericMediaFormat()), create MediaBean
2211:             *  	      create byte array buffer of size 1024 bytes
2212:             *
2213:             *  test procedure:
2214:             *  1.call readContent(-1,testBuffer,0,1024)
2215:             *    expected result: IndexOutOfBoundsException
2216:             *
2217:             *  2.call readContent(1025,testBuffer,0,1024)
2218:             *    expected result: IndexOutOfBoundsException
2219:             *
2220:             *  3.call readContent(0,testBuffer,-1,1024)
2221:             *    expected result: IndexOutOfBoundsException
2222:             *
2223:             *  4.call readContent(0,testBuffer,1025,1024)
2224:             *    expected result: IndexOutOfBoundsException
2225:             *
2226:             *  5.call readContent(0,testBuffer,0,-1)
2227:             *    expected result: NegativeIndexArrayException
2228:             *
2229:             *  6.call readContent(0,null,0,1024)
2230:             *    expected result: NullPointerException
2231:             *
2232:             *  7.create testInstance from nonexistent file and call readContent(0,testBuffer,0,1024)
2233:             *    expected result: ContentAccessException
2234:             *
2235:             *  8.call readContent(0,testBuffer,0,1024) (loop to fill buffer)
2236:             *    compare with file content
2237:             *    expected result: same content
2238:             *
2239:             *  9.call readContent(512,testBuffer,0,1024)
2240:             *    expected result: buffer partially filled with 512 bytes matching last 512 bytes
2241:             *    of media content (could be less if nonblocking)
2242:             *
2243:             *  10.call readContent(1024,testBuffer,0,1024)
2244:             *     expected result: return -1 with empty buffer
2245:             *
2246:             *  11.call readContent(0,testBuffer,100,924), compare buffer offset 100 with media content
2247:             *     (use return value as length)
2248:             *     expected result: same content
2249:             *
2250:             *  12.call readContent(200,testBuffer,100,100), compare buffer offset 100 with file offset 200
2251:             *     (use return value as length)
2252:             *     expected result: same content
2253:             *
2254:             *  13.call readContent(0,testBuffer,0,1048), compare buffer with file content
2255:             *     expected result: same content and no exceptions
2256:             *
2257:             * </pre>
2258:             */
2259:            public void testEMB122() throws IOException, MediaException,
2260:                    Throwable {
2261:
2262:                //
2263:                // Initialize the testcase
2264:                //
2265:                File file1024Byte = new File(embTestConfig.getMediaDir()
2266:                        + File.separatorChar + "Generated" + File.separatorChar
2267:                        + "testFile1024Byte.test");
2268:                file1024Byte.createNewFile();
2269:                FileOutputStream file1024ByteOutputStream = new FileOutputStream(
2270:                        file1024Byte);
2271:                byte[] testArray = EMBStaticHelper.createRandomByteArray(1024);
2272:                file1024ByteOutputStream.write(testArray);
2273:                file1024ByteOutputStream.close();
2274:                // register media format
2275:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
2276:                String testInstance = mebTester.createMediaEntityBean();
2277:                mebTester.setMediaEntityName(testInstance,
2278:                        "testFile1024Byte.test");
2279:                mebTester.setMediaEntityContent(testInstance, file1024Byte);
2280:                byte[] testBuffer = new byte[1024];
2281:                int exception = -1;
2282:                //
2283:                // test 1
2284:                //
2285:                try {
2286:                    exception = mebTester.readContentExceptions(testInstance,
2287:                            -1, testBuffer, 0, 1024);
2288:                } catch (Throwable e) {
2289:                    fail("test 1 threw " + e.toString());
2290:                }
2291:                assertEquals(
2292:                        "test 1: Should throw an IndexOutOfBoundsException",
2293:                        MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS, exception);
2294:                testTrace("test 1 passed");
2295:
2296:                //
2297:                // test 2
2298:                //
2299:                try {
2300:                    exception = mebTester.readContentExceptions(testInstance,
2301:                            1025, testBuffer, 0, 1024);
2302:                } catch (Throwable e) {
2303:                    fail("test 2 threw " + e.toString());
2304:                }
2305:                assertEquals(
2306:                        "test 2: Should throw an IndexOutOfBoundsException",
2307:                        MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS, exception);
2308:                testTrace("test 2 passed");
2309:
2310:                //
2311:                // test 3
2312:                //
2313:                try {
2314:                    exception = mebTester.readContentExceptions(testInstance,
2315:                            0, testBuffer, -1, 1024);
2316:                } catch (Throwable e) {
2317:                    fail("test 3 threw " + e.toString());
2318:                }
2319:                assertEquals(
2320:                        "test 3: Should throw an IndexOutOfBoundsException",
2321:                        MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS, exception);
2322:                testTrace("test 3 passed");
2323:                //
2324:                // test 4
2325:                //
2326:                /*
2327:                try {
2328:                    exception = mebTester.readContentExceptions(testInstance, 0, testBuffer, 1025, 1024);
2329:                } catch (Throwable e) {
2330:                    fail("test 4 threw " + e.toString());
2331:                }
2332:                assertEquals("test 4: Should throw an IndexOutOfBoundsException", MediaEntityLocalTestDriver.INDEXOUTOFBOUNDS,
2333:                        exception);
2334:                testTrace("test 4 passed");
2335:                //
2336:                // test 5
2337:                //
2338:                try {
2339:                    exception = mebTester.readContentExceptions(testInstance, 0, testBuffer, 0, -1);
2340:                } catch (Throwable e) {
2341:                    fail("test 5 threw " + e.toString());
2342:                }
2343:                assertEquals("test 5: Should throw a NegativeArraySizeExcepton", MediaEntityLocalTestDriver.NEGATIVEARRAYSIZE,
2344:                        exception);
2345:                testTrace("test 5 passed");*/
2346:                //
2347:                // test 6
2348:                //
2349:                try {
2350:                    exception = mebTester.readContentExceptions(testInstance,
2351:                            0, null, 0, 1024);
2352:                } catch (Throwable e) {
2353:                    fail("test 6 threw " + e.toString());
2354:                }
2355:                assertEquals("test 6: Should throw a NullPointerExcepton",
2356:                        MediaEntityLocalTestDriver.NULLPOINTER, exception);
2357:                testTrace("test 6 passed");
2358:                //
2359:                // test 7
2360:                //
2361:                String noContentMedia = mebTester.createMediaEntityBean();
2362:                mebTester.setMediaEntityName(noContentMedia, "testFile.test");
2363:                try {
2364:                    exception = mebTester.readContentExceptions(noContentMedia,
2365:                            0, testBuffer, 0, 1024);
2366:                } catch (Throwable e) {
2367:                    fail("test 7 threw " + e.toString());
2368:                }
2369:                assertEquals("test 7: Should throw a ContentAccessException",
2370:                        MediaEntityLocalTestDriver.CONTENTACCESS, exception);
2371:                testTrace("test 7 passed");
2372:                mebTester.removeMEBByPK(noContentMedia);
2373:                //
2374:                // test 8
2375:                //
2376:                /*
2377:                boolean contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 0, 1024, testArray, true);
2378:                assertTrue("test 8: content does not match ", contentValid);
2379:                testTrace("test 8 passed");
2380:                //
2381:                // test 9
2382:                //
2383:                contentValid = mebTester.readCompareContent(testInstance, 512, testBuffer, 0, 1024, testArray, false);
2384:                assertTrue("test 9: ", contentValid);
2385:                testTrace("test 9 passed");
2386:                //
2387:                // test 10
2388:                //
2389:                int amountCopied = mebTester.readMediaEntityContent(testInstance, 1024, testBuffer, 0, 1024);
2390:                assertEquals("test 10: ", -1, amountCopied);
2391:                testTrace("test 10 passed");
2392:                //
2393:                // test 11
2394:                //
2395:                contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 100, 924, testArray, false);
2396:                assertTrue("test 11: ", contentValid);
2397:                testTrace("test 11 passed");
2398:                //
2399:                // test 12
2400:                //
2401:                contentValid = mebTester.readCompareContent(testInstance, 200, testBuffer, 100, 100, testArray, false);
2402:                assertTrue("test 12: ", contentValid);
2403:                testTrace("test 12 passed");
2404:                //
2405:                // test 13
2406:                //
2407:                contentValid = mebTester.readCompareContent(testInstance, 0, testBuffer, 0, 1048, testArray, false);
2408:                assertTrue("test 13: ", contentValid);
2409:                testTrace("test 13 passed");
2410:                mebTester.removeMEBByPK(testInstance);
2411:                 */
2412:
2413:                succeed();
2414:            }
2415:
2416:            /**
2417:             * <pre>
2418:             *
2419:             *  Testcase Name: removeListener(MediaListener)
2420:             *  Testcase Number: EMB123
2421:             *
2422:             *  setup: create Media entity me1 and media listener listener1
2423:             *
2424:             *  test procedure:
2425:             *  1.call removeListener(null)
2426:             *    expected result: NullPointerException
2427:             *
2428:             *  2.call me1.addListener(listener1), call me1.getListeners() and verify listener is added
2429:             *    call me1.removeListener(listener1), call me1.getListeners() and verify listener is removed
2430:             *    expected result: listener1 is removed
2431:             *
2432:             *  3.create media listener listener 2
2433:             *    call me1.removeListener(listener2)
2434:             *    expected result: no action and no exception
2435:             *
2436:             * </pre>
2437:             */
2438:            public void testEMB123() throws IOException, MediaException,
2439:                    CreateException, RemoteException, NamingException,
2440:                    FinderException, RemoveException {
2441:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
2442:                        embTestConfig.getJpgPictureName1());
2443:                String me1 = mebTester.createMediaEntityBean();
2444:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2445:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2446:                GenericMediaListener listener1 = new GenericMediaListener();
2447:                GenericMediaListener listener2 = new GenericMediaListener();
2448:                int exception = -1;
2449:                //
2450:                // test 1
2451:                //
2452:                try {
2453:                    exception = mebTester.removeListenerExceptions(me1, null);
2454:                } catch (Throwable e) {
2455:                    fail("test 1 threw " + e.toString());
2456:                }
2457:                assertEquals("test 1: Should throw a NullPointerException",
2458:                        exception, MediaEntityLocalTestDriver.NULLPOINTER);
2459:                testTrace("test 1 passed");
2460:                //
2461:                // test 2
2462:                //
2463:                mebTester.addMediaEntityListener(me1, listener1);
2464:                assertEquals("test 2: listener not added", 1, mebTester
2465:                        .getMediaEntityListeners(me1).length);
2466:                mebTester.removeMediaEntityListener(me1, listener1);
2467:                assertEquals("test 2: listener not removed", 0, mebTester
2468:                        .getMediaEntityListeners(me1).length);
2469:                testTrace("test 2 passed");
2470:                //
2471:                // test 3
2472:                //
2473:                try {
2474:                    mebTester.removeMediaEntityListener(me1, listener2);
2475:                    testTrace("test 3 passed");
2476:                } catch (Throwable e) {
2477:                    fail("test 3 threw " + e.toString());
2478:                }
2479:                mebTester.removeMEBByPK(me1);
2480:                succeed();
2481:            }
2482:
2483:            /**
2484:             * <pre>
2485:             *
2486:             *  Testcase Name: removeMetaData(MetaDataEntityLocal)
2487:             *  Testcase Number: EMB124
2488:             *
2489:             *  setup: create Media entity me1 and meta data entity md1
2490:             *
2491:             *  test procedure:
2492:             *  1.call removeMetaData(null)
2493:             *    expected result: NullPointerException
2494:             *
2495:             *  2.call me1.addMetaData(md1), call me1.getMetaData() and verify meta data is added
2496:             *    call me1.removeMetaData(md1), call me1.getMetaData() and verify md1 is removed
2497:             *    expected result: md1 is removed
2498:             *
2499:             *  3.create meta data entity md2
2500:             *    call me1.removeMetaData(md2)
2501:             *    expected result: no exception
2502:             *
2503:             * </pre>
2504:             */
2505:            public void testEMB124() throws CreateException, IOException,
2506:                    MediaException, RemoteException, NamingException,
2507:                    FinderException, RemoveException {
2508:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
2509:                        embTestConfig.getJpgPictureName1());
2510:                String me1 = mebTester.createMediaEntityBean();
2511:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2512:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2513:                // use local home interface to create new meta data entity
2514:                String md1 = mebTester.createMetaDataEntityBean();
2515:                String md2 = mebTester.createMetaDataEntityBean();
2516:                int exception = -1;
2517:                //
2518:                // test 1
2519:                //
2520:                try {
2521:                    exception = mebTester.removeMetaDataExceptions(me1, null);
2522:                } catch (Throwable e) {
2523:                    fail("test 1 threw " + e.toString());
2524:                }
2525:                assertEquals("test 1: Should throw a NullPointerException",
2526:                        exception, MediaEntityLocalTestDriver.NULLPOINTER);
2527:                testTrace("test 1 passed");
2528:                //
2529:                // test
2530:                //
2531:                mebTester.addMediaEntityMetaData(me1, md1);
2532:                assertEquals("test 2; meta data not added", 1, mebTester
2533:                        .getMediaEntityMetaData(me1).length);
2534:                mebTester.removeMediaEntityMetaData(me1, md1);
2535:                assertEquals("test 2: meta data not removed", 0, mebTester
2536:                        .getMediaEntityMetaData(me1).length);
2537:                testTrace("test 2 passed");
2538:                //
2539:                // test 3
2540:                //
2541:                try {
2542:                    mebTester.removeMediaEntityMetaData(me1, md2);
2543:                    testTrace("test 3 passed");
2544:                } catch (Throwable e) {
2545:                    fail("test 3 threw " + e.toString());
2546:                }
2547:
2548:                mebTester.removeMEBByPK(me1);
2549:                mebTester.removeMDEBByPK(md1);
2550:                mebTester.removeMDEBByPK(md2);
2551:                succeed();
2552:            }
2553:
2554:            /**
2555:             * <pre>
2556:             *
2557:             *  Testcase Name: setChildren(MediaEntityLocal[] children)
2558:             *  Testcase Number: EMB125
2559:             *
2560:             *  setup:
2561:             *
2562:             *  test procedure:
2563:             *  1.call setChildren(null)
2564:             *    expected result: NullPointerException
2565:             *
2566:             *  2.call setChildren(new MediaEntityLocal[] {null})
2567:             *    expected result: NullPointerException
2568:             *
2569:             *  3.create nonembedded media with 1 child
2570:             *    call setChildren with only 2 children passed in
2571:             *    expected result: IllegalArgumentException
2572:             *
2573:             *  4.create nonembedded media with 1 child
2574:             *    call setChildren(new MediaEntityLocal[0])
2575:             *    expected result: IllegalArgumentException
2576:             *
2577:             *  5.create nonembedded media and set location
2578:             *    call setChildren
2579:             *    expected result: ContentUnmutableException
2580:             *
2581:             *  6.create embedded media and call setChildren(new MediaEntityLocal[0])
2582:             *    expected result: no exception
2583:             *
2584:             *  7.create nonembedded media with 1 child
2585:             *    call setChildren(new MediaEntityLocal[] {child})
2586:             *    expected result: no exception and child content is updated
2587:             *
2588:             *  8.create nonembedded media with no content
2589:             *    create child and call setChildren
2590:             *    expected result: ContentAccessException
2591:             *
2592:             * </pre>
2593:             */
2594:            public void testEMB125() throws MalformedURLException, IOException,
2595:                    MediaException, CreateException, RemoteException,
2596:                    NamingException, FinderException, RemoveException {
2597:
2598:                mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
2599:                mebTester.bindMediaFormat("bmp", new BmpFormat());
2600:
2601:                // playlist with 3 children
2602:                ComplexMediaLocationInfo me1NELocInfo = new ComplexMediaLocationInfo(
2603:                        ComplexMediaLocationInfo.MEDIAGPL1);
2604:                String me1NE = mebTester.createMediaEntityBean();
2605:                mebTester.setMediaEntityName(me1NE, "testPlaylist1.gpl");
2606:                mebTester.importMediaEntityContent(me1NE, me1NELocInfo
2607:                        .getRootURL(), null);
2608:
2609:                // playlist with 1 child
2610:                ComplexMediaLocationInfo me2NELocInfo = new ComplexMediaLocationInfo(
2611:                        ComplexMediaLocationInfo.MEDIAGPL2);
2612:                String me2NE = mebTester.createMediaEntityBean();
2613:                mebTester.setMediaEntityName(me2NE, "testPlaylist2.gpl");
2614:                mebTester.importMediaEntityContent(me2NE, me2NELocInfo
2615:                        .getRootURL(), null);
2616:
2617:                int exception = -1;
2618:                //
2619:                // test 1
2620:                //
2621:                try {
2622:                    exception = mebTester.setChildrenExceptions(me1NE, null);
2623:                } catch (Throwable e) {
2624:                    fail("test 1 threw " + e.toString());
2625:                }
2626:                assertEquals("test 1: Should throw a NullPointerException",
2627:                        MediaEntityLocalTestDriver.NULLPOINTER, exception);
2628:                testTrace("test 1 passed");
2629:                //
2630:                // test 2
2631:                //
2632:                try {
2633:                    exception = mebTester.setChildrenExceptions(me2NE,
2634:                            new String[] { null });
2635:                } catch (Throwable e) {
2636:                    fail("test 2 threw " + e.toString());
2637:                }
2638:                assertEquals("test 2: Should throw a NullPointerException",
2639:                        MediaEntityLocalTestDriver.NULLPOINTER, exception);
2640:                testTrace("test 2 passed");
2641:                //
2642:                // test 3
2643:                //
2644:                String mebChild1 = mebTester.createMediaEntityBean();
2645:                String mebChild2 = mebTester.createMediaEntityBean();
2646:
2647:                try {
2648:                    exception = mebTester.setChildrenExceptions(me2NE,
2649:                            new String[] { mebChild1, mebChild2 });
2650:                } catch (Throwable e) {
2651:                    fail("test 3 threw " + e.toString());
2652:                }
2653:                assertEquals(
2654:                        "test 3: Should throw an IllegalArgumentException",
2655:                        MediaEntityLocalTestDriver.ILLEGALARGUMENT, exception);
2656:                testTrace("test 3 passed");
2657:
2658:                //
2659:                // test 4
2660:                //
2661:                try {
2662:                    exception = mebTester.setChildrenExceptions(me2NE,
2663:                            new String[0]);
2664:                } catch (Throwable e) {
2665:                    fail("test 4 threw " + e.toString());
2666:                }
2667:                assertEquals(
2668:                        "test 4: Should throw an IllegalArgumentException",
2669:                        MediaEntityLocalTestDriver.ILLEGALARGUMENT, exception);
2670:                testTrace("test 4 passed");
2671:
2672:                //
2673:                // test 5
2674:                //
2675:                String me3NE = mebTester.createMediaEntityBean();
2676:                mebTester.setMediaEntityName(me3NE, "test.gpl");
2677:                mebTester.setMediaEntityLocation(me3NE, me2NELocInfo
2678:                        .getRootURL());
2679:                try {
2680:                    exception = mebTester.setChildrenExceptions(me3NE,
2681:                            new String[] { mebChild1 });
2682:                } catch (Throwable e) {
2683:                    fail("test 5 threw " + e.toString());
2684:                }
2685:                assertEquals(
2686:                        "test 5: Should throw an ContentUnmutableException",
2687:                        MediaEntityLocalTestDriver.CONTENTUNMUTABLE, exception);
2688:                testTrace("test 5 passed");
2689:                //
2690:                // test 6
2691:                //
2692:                EmbeddedMediaLocationInfo me4LocInfo = new EmbeddedMediaLocationInfo(
2693:                        embTestConfig.getBmpPictureName1());
2694:                String me4 = mebTester.createMediaEntityBean();
2695:                mebTester.setMediaEntityName(me4, me4LocInfo.getMediaName());
2696:                mebTester.setMediaEntityContent(me4, me4LocInfo.getMediaFile());
2697:
2698:                mebTester.setMediaEntityChildren(me4, new String[0]);
2699:                testTrace("test 6 passed");
2700:
2701:                //
2702:                // test 7
2703:                //
2704:                mebTester.setMediaEntityChildren(me2NE, new String[] { me4 });
2705:                String[] children = mebTester.getMediaEntityChildren(me2NE);
2706:                assertEquals("test 7: media entity does not have 1 child", 1,
2707:                        children.length);
2708:                assertTrue("test 7: child content does not match",
2709:                        java.util.Arrays.equals(mebTester
2710:                                .getMediaEntityContent(me4), mebTester
2711:                                .getMediaEntityContent(children[0])));
2712:                testTrace("test 7 passed");
2713:                //
2714:                // test 8
2715:                //
2716:                String noContentMedia = mebTester.createMediaEntityBean();
2717:                mebTester.setMediaEntityName(noContentMedia, "test.gpl");
2718:                String child3 = mebTester.createMediaEntityBean();
2719:                try {
2720:                    exception = mebTester.setChildrenExceptions(noContentMedia,
2721:                            new String[] { child3 });
2722:                } catch (Throwable e) {
2723:                    fail("test 8 threw " + e.toString());
2724:                }
2725:                assertEquals("test 8: Should throw a ContentAccessException",
2726:                        MediaEntityLocalTestDriver.CONTENTACCESS, exception);
2727:                testTrace("test 8 passed");
2728:
2729:                mebTester.removeMEBByPK(me1NE);
2730:                mebTester.removeMEBByPK(me2NE);
2731:                mebTester.removeMEBByPK(me3NE);
2732:                mebTester.removeMEBByPK(me4);
2733:                mebTester.removeMEBByPK(mebChild1);
2734:                mebTester.removeMEBByPK(mebChild2);
2735:                mebTester.removeMEBByPK(child3);
2736:                succeed();
2737:            }
2738:
2739:            /**
2740:             * <pre>
2741:             *
2742:             *  Testcase Name: setContent(byte[])
2743:             *  Testcase Number: EMB126
2744:             *
2745:             *  setup: create Media entity me1 from bmp media file
2746:             *
2747:             *  test procedure:
2748:             *  1.call setContent(null)
2749:             *    expected result: no exception
2750:             *
2751:             *  2.call getLastModified() and remember timestamp
2752:             *    call setContent() with testPicture2.bmp
2753:             *    call getContent()
2754:             *  	 wait 2 seconds
2755:             *  	 expected result: content of new file
2756:             *  					  call getLastModified() and check if timestamp changed
2757:             *  					  call getFormat and check it has not changed
2758:             *
2759:             *  3.call setContent with testPicture1.jpg
2760:             *    expected result: FormatSyntaxException (format change)
2761:             *
2762:             *  4.create Media entity from nonembedded media
2763:             *    call getLastModified and remember timestamp
2764:             *    call setContent with testPlaylist1.gpl
2765:             *    wait 2 seconds
2766:             *    call getContent
2767:             *    expected result: content matches testPlaylist1
2768:             *  					  call getChildren and check empty array is returned
2769:             *  					  call getLastModified and check timestamp has changed
2770:             *
2771:             *  5.call setName(&quot;testPicture1.jpg&quot;)
2772:             *    call setContent with testPicture1.jpg
2773:             *    expected result: no exception
2774:             *                     call getContent and verify new content and format change
2775:             *
2776:             *  6.create media listener and call me1.addListener(listener)
2777:             *    call setContent with testPicture1.bmp
2778:             *    expected result: ListenerVetoException
2779:             *
2780:             *  7.create media entity and call setName
2781:             *    call setContent with byte array larger than maxMediaSize
2782:             *    expected result: ContentTooLargeException
2783:             *
2784:             * </pre>
2785:             */
2786:            public void testEMB126() throws MalformedURLException,
2787:                    MediaException, IOException, InterruptedException,
2788:                    CreateException, RemoteException, NamingException,
2789:                    FinderException, RemoveException {
2790:
2791:                mebTester.bindMediaFormat("jpg", new JpegFormat());
2792:                mebTester.bindMediaFormat("bmp", new BmpFormat());
2793:                mebTester.bindMediaFormat("test", new GenericMediaFormat());
2794:                mebTester.bindMediaFormat("gpl", new GenericPlaylistFormat());
2795:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
2796:                        embTestConfig.getBmpPictureName1());
2797:                String me1 = mebTester.createMediaEntityBean();
2798:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2799:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2800:
2801:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
2802:                        embTestConfig.getBmpPictureName2());
2803:                EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(
2804:                        embTestConfig.getJpgPictureName1());
2805:
2806:                ComplexMediaLocationInfo me4NELocInfo = new ComplexMediaLocationInfo(
2807:                        ComplexMediaLocationInfo.MEDIAGPL1);
2808:                String me4NE = mebTester.createMediaEntityBean();
2809:                mebTester.setMediaEntityName(me4NE, me4NELocInfo.getRootFile()
2810:                        .getName());
2811:                mebTester.setMediaEntityContent(me4NE, me4NELocInfo
2812:                        .getRootFile());
2813:                int exception = -1;
2814:                //
2815:                // test 1
2816:                //
2817:                byte[] nullByteArray = null;
2818:                try {
2819:                    mebTester.setMediaEntityContent(me1, nullByteArray);
2820:                } catch (Exception e) {
2821:                    fail("test 1 threw " + e.toString());
2822:                }
2823:                testTrace("test 1 passed");
2824:                //
2825:                // test 2
2826:                //
2827:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2828:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2829:                Date beforeStamp = new Date(mebTester
2830:                        .getMediaEntityLastModified(me1));
2831:                mebTester.setMediaEntityContent(me1, me2LocInfo.getMediaFile());
2832:                Thread.sleep(1000);
2833:                Date afterStamp = new Date(mebTester
2834:                        .getMediaEntityLastModified(me1));
2835:                assertTrue("test 2: Modification date", afterStamp
2836:                        .after(beforeStamp));
2837:                assertTrue("test 2: content does not match",
2838:                        java.util.Arrays
2839:                                .equals(mebTester.getMediaEntityContent(me1),
2840:                                        getByteArrayFromFile(me2LocInfo
2841:                                                .getMediaFile())));
2842:                assertTrue("test 2: format changed", mebTester
2843:                        .getMediaEntityFormat(me1) instanceof  BmpFormat);
2844:                testTrace("test 2 passed");
2845:                //
2846:                // test 3
2847:                //
2848:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2849:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2850:                try {
2851:                    exception = mebTester.setContentExceptions(me1,
2852:                            getByteArrayFromFile(me3LocInfo.getMediaFile()));
2853:                } catch (Throwable e) {
2854:                    fail("test 3 threw " + e.toString());
2855:                }
2856:                assertEquals("test 3: Should throw a FormatSyntaxException",
2857:                        MediaEntityLocalTestDriver.FORMATSYNTAX, exception);
2858:                testTrace("test 3 passed");
2859:                //
2860:                // test 4
2861:                //
2862:                beforeStamp = new Date(mebTester
2863:                        .getMediaEntityLastModified(me4NE));
2864:                mebTester.setMediaEntityContent(me4NE, me4NELocInfo
2865:                        .getRootFile());
2866:                Thread.sleep(1000);
2867:                afterStamp = new Date(mebTester
2868:                        .getMediaEntityLastModified(me4NE));
2869:                assertTrue("test 4: Modification date", afterStamp
2870:                        .after(beforeStamp));
2871:                assertTrue("test 4: content did not change",
2872:                        java.util.Arrays
2873:                                .equals(mebTester.getMediaEntityContent(me4NE),
2874:                                        getByteArrayFromFile(me4NELocInfo
2875:                                                .getRootFile())));
2876:                assertTrue(
2877:                        "test 4: format changed",
2878:                        mebTester.getMediaEntityFormat(me4NE) instanceof  GenericPlaylistFormat);
2879:                assertEquals("test 4: children stored", 0, mebTester
2880:                        .getMediaEntityChildren(me4NE).length);
2881:                testTrace("test 4 passed");
2882:                //
2883:                // test 5
2884:                //
2885:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
2886:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
2887:
2888:                mebTester.setMediaEntityName(me1, "testPicture1.jpg");
2889:                beforeStamp = new Date(mebTester
2890:                        .getMediaEntityLastModified(me1));
2891:                mebTester.setMediaEntityContent(me1,
2892:                        getByteArrayFromFile(me3LocInfo.getMediaFile()));
2893:                Thread.sleep(1000);
2894:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
2895:                assertTrue("test 5: Modification date", afterStamp
2896:                        .after(beforeStamp));
2897:                assertTrue("test 5: content did not change",
2898:                        java.util.Arrays
2899:                                .equals(mebTester.getMediaEntityContent(me1),
2900:                                        getByteArrayFromFile(me3LocInfo
2901:                                                .getMediaFile())));
2902:                assertTrue("test 5: format did not change", mebTester
2903:                        .getMediaEntityFormat(me1) instanceof  JpegFormat);
2904:                testTrace("test 5 passed");
2905:                //
2906:                // test 6
2907:                //
2908:                String me5 = mebTester.createMediaEntityBean();
2909:                mebTester.setMediaEntityName(me5, "test.bmp");
2910:                // set content to testPicture1.bmp
2911:                mebTester.setMediaEntityContent(me5, me1LocInfo.getMediaFile());
2912:                GenericMediaListener testListener = new GenericMediaListener();
2913:                mebTester.addMediaEntityListener(me5, testListener);
2914:                try {
2915:                    // try to set content to testPicture2.bmp
2916:                    exception = mebTester.setContentExceptions(me5,
2917:                            getByteArrayFromFile(me2LocInfo.getMediaFile()));
2918:                } catch (Throwable e) {
2919:                    fail("test 6 threw " + e.toString());
2920:                }
2921:                assertEquals("test 6: Should throw a ListenerVetoException",
2922:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
2923:                assertTrue("test 6: content should not change", Arrays.equals(
2924:                        getByteArrayFromFile(me1LocInfo.getMediaFile()),
2925:                        mebTester.getMediaEntityContent(me5)));
2926:                testTrace("test 6 passed");
2927:                //
2928:                // test 7
2929:                //
2930:                if (embTestConfig.getIncludeLongRunningTest()) {
2931:                    String largeFilePath = embTestConfig.getMediaDir()
2932:                            + File.separatorChar + "Generated"
2933:                            + File.separatorChar + "largeFile.test";
2934:                    File largeFile = new File(largeFilePath);
2935:                    largeFile.createNewFile();
2936:                    FileOutputStream largeFileOutputStream = new FileOutputStream(
2937:                            largeFile);
2938:                    // create byte array 1 byte larger than maxMediaSize
2939:                    byte[] testArray = EMBStaticHelper
2940:                            .createRandomByteArray(Integer
2941:                                    .parseInt(embTestConfig.getMaxMediaSize()) + 1);
2942:                    largeFileOutputStream.write(testArray);
2943:                    largeFileOutputStream.close();
2944:
2945:                    String testInstance = mebTester.createMediaEntityBean();
2946:                    mebTester.setMediaEntityName(testInstance,
2947:                            "largeMedia.test");
2948:                    try {
2949:                        exception = mebTester.setContentExceptions(
2950:                                testInstance, getByteArrayFromFile(largeFile));
2951:                    } catch (Throwable e) {
2952:                        fail("test 7 threw " + e.toString());
2953:                    }
2954:                    assertEquals(
2955:                            "test 7: Should throw a ContentTooLargeException",
2956:                            MediaEntityLocalTestDriver.CONTENTTOOLARGE,
2957:                            exception);
2958:                    testTrace("test 7 passed");
2959:                    largeFile.delete();
2960:                    mebTester.removeMEBByPK(testInstance);
2961:                }
2962:
2963:                mebTester.removeMEBByPK(me1);
2964:                mebTester.removeMEBByPK(me4NE);
2965:                mebTester.removeMEBByPK(me5);
2966:                succeed();
2967:            }
2968:
2969:            /**
2970:             * <pre>
2971:             *
2972:             *  Testcase Name: setContent(InputStream)
2973:             *  Testcase Number: EMB127
2974:             *
2975:             *  setup: create Media entity me1 from bmp media file
2976:             *
2977:             *  test procedure:
2978:             *  1.call setContent(null)
2979:             *    expected result: NullPointerException
2980:             *
2981:             *  2.call getLastModified() and remember timestamp
2982:             *    call setContent() with testPicture2.bmp
2983:             *    call getContent()
2984:             *  	 wait 2 seconds
2985:             *  	 expected result: content of new file
2986:             *  					  call getLastModified() and check if timestamp changed
2987:             * 					  call getFormat and check it has not changed
2988:             *
2989:             *  3.call setContent with testPicture1.jpg
2990:             *    expected result: FormatSyntaxException (format change)
2991:             *
2992:             *  4.create Media entity from nonembedded media
2993:             *    call getLastModified and remember timestamp
2994:             *    call setName(&quot;testPlaylist1.gpl&quot;)
2995:             *    call setContent with testPlaylist1.gpl
2996:             *    wait 2 seconds
2997:             *    call getContent
2998:             *    expected result: content matches testPlaylist1
2999:             * 					  call getChildren and check empty array is returned
3000:             * 					  call getLastModified and check timestamp has changed
3001:             *
3002:             *  5.call setName(&quot;testPicture1.jpg&quot;)
3003:             *    call setContent with testPicture1.jpg
3004:             *    expected result: no exception
3005:             *                     call getContent and verify new content and format change
3006:             *
3007:             *  6.create media listener and call me1.addListener(listener)
3008:             *    call setContent with testPicture1.bmp
3009:             *    expected result: ListenerVetoException
3010:             *
3011:             *  7.create media entity and call setName
3012:             *    call setContent with file larger than maxMediaSize
3013:             *    expected result: ContentTooLargeException
3014:             *
3015:             * </pre>
3016:             */
3017:            public void testEMB127() throws IOException, MediaException,
3018:                    InterruptedException, CreateException, RemoteException,
3019:                    NamingException, FinderException, RemoveException {
3020:
3021:                mebTester.bindMediaFormat("jpg", new JpegFormat());
3022:                mebTester.bindMediaFormat("bmp", new BmpFormat());
3023:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3024:                        embTestConfig.getBmpPictureName1());
3025:                String me1 = mebTester.createMediaEntityBean();
3026:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3027:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3028:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
3029:                        embTestConfig.getBmpPictureName2());
3030:                EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(
3031:                        embTestConfig.getJpgPictureName1());
3032:                ComplexMediaLocationInfo me4NELocInfo = new ComplexMediaLocationInfo(
3033:                        ComplexMediaLocationInfo.MEDIAGPL1);
3034:                String me4NE = mebTester.createMediaEntityBean();
3035:                mebTester.setMediaEntityName(me4NE, me4NELocInfo.getRootFile()
3036:                        .getName());
3037:                mebTester.setMediaEntityContent(me4NE, me4NELocInfo
3038:                        .getRootFile());
3039:                int exception = -1;
3040:                //
3041:                // test 1
3042:                //
3043:                File nullFile = null;
3044:                try {
3045:                    exception = mebTester.setContentExceptions(me1, nullFile);
3046:                } catch (Throwable e) {
3047:                    fail("test 1 threw " + e.toString());
3048:                }
3049:                assertEquals("test 1: Should throw a NullPointerException",
3050:                        exception, MediaEntityLocalTestDriver.NULLPOINTER);
3051:                testTrace("test 1 passed");
3052:                //
3053:                // test 2
3054:                //
3055:                Date beforeStamp = new Date(mebTester
3056:                        .getMediaEntityLastModified(me1));
3057:                mebTester.setMediaEntityContent(me1, me2LocInfo.getMediaFile());
3058:                Thread.sleep(1000);
3059:                Date afterStamp = new Date(mebTester
3060:                        .getMediaEntityLastModified(me1));
3061:                assertTrue("test 2: Modification date", afterStamp
3062:                        .after(beforeStamp));
3063:                assertTrue("test 2: content does not match",
3064:                        java.util.Arrays
3065:                                .equals(mebTester.getMediaEntityContent(me1),
3066:                                        getByteArrayFromFile(me2LocInfo
3067:                                                .getMediaFile())));
3068:                assertTrue("test 2: format changed", mebTester
3069:                        .getMediaEntityFormat(me1) instanceof  BmpFormat);
3070:                testTrace("test 2 passed");
3071:                //
3072:                // test 3
3073:                //
3074:
3075:                try {
3076:                    exception = mebTester.setContentExceptions(me1, me3LocInfo
3077:                            .getMediaFile());
3078:                } catch (Throwable e) {
3079:                    fail("test 3 threw " + e.toString());
3080:                }
3081:                assertEquals("test 3: Should throw a FormatSyntaxException",
3082:                        MediaEntityLocalTestDriver.FORMATSYNTAX, exception);
3083:                testTrace("test 3 passed");
3084:                //
3085:                // test 4
3086:                //
3087:                mebTester.setMediaEntityName(me1, me4NELocInfo.getRootFile()
3088:                        .getName());
3089:                beforeStamp = new Date(mebTester
3090:                        .getMediaEntityLastModified(me1));
3091:                mebTester
3092:                        .setMediaEntityContent(me1, me4NELocInfo.getRootFile());
3093:                Thread.sleep(1000);
3094:                afterStamp = new Date(mebTester.getMediaEntityLastModified(me1));
3095:                assertTrue("test 4: Modification date", afterStamp
3096:                        .after(beforeStamp));
3097:                assertTrue("test 4: content does not match",
3098:                        java.util.Arrays
3099:                                .equals(mebTester.getMediaEntityContent(me1),
3100:                                        getByteArrayFromFile(me4NELocInfo
3101:                                                .getRootFile())));
3102:                assertTrue(
3103:                        "test 4: format changed",
3104:                        mebTester.getMediaEntityFormat(me1) instanceof  GenericPlaylistFormat);
3105:                assertEquals("test 4: children stored", 0, mebTester
3106:                        .getMediaEntityChildren(me1).length);
3107:                testTrace("test 4 passed");
3108:                //
3109:                // test 5
3110:                //
3111:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3112:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3113:
3114:                mebTester.setMediaEntityName(me1, "testPicture1.jpg");
3115:                beforeStamp = new Date(mebTester
3116:                        .getMediaEntityLastModified(me1));
3117:                mebTester.setMediaEntityContent(me1, me3LocInfo.getMediaFile());
3118:                Thread.sleep(1000);
3119:                afterStamp = new Date((mebTester
3120:                        .getMediaEntityLastModified(me1)));
3121:                assertTrue("test 5: Modification date", afterStamp
3122:                        .after(beforeStamp));
3123:                assertTrue("test 5: content did not change",
3124:                        java.util.Arrays
3125:                                .equals(mebTester.getMediaEntityContent(me1),
3126:                                        getByteArrayFromFile(me3LocInfo
3127:                                                .getMediaFile())));
3128:                assertTrue("test 5: format did not change", mebTester
3129:                        .getMediaEntityFormat(me1) instanceof  JpegFormat);
3130:                testTrace("test 5 passed");
3131:                //
3132:                // test 6
3133:                //
3134:                String me5 = mebTester.createMediaEntityBean();
3135:                mebTester.setMediaEntityName(me5, "test.bmp");
3136:                // set content to testPicture1.bmp
3137:                mebTester.setMediaEntityContent(me5, me1LocInfo.getMediaFile());
3138:                GenericMediaListener testListener = new GenericMediaListener();
3139:                mebTester.addMediaEntityListener(me5, testListener);
3140:                try {
3141:                    exception = mebTester.setContentExceptions(me5,
3142:                            getByteArrayFromFile(me2LocInfo.getMediaFile()));
3143:                } catch (Throwable e) {
3144:                    fail("test 6 threw " + e.toString());
3145:                }
3146:                assertEquals("test 6: Should throw a ListenerVetoException",
3147:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
3148:                assertTrue("test 6: content should not change", Arrays.equals(
3149:                        getByteArrayFromFile(me1LocInfo.getMediaFile()),
3150:                        mebTester.getMediaEntityContent(me5)));
3151:                testTrace("test 6 passed");
3152:                //
3153:                // test 7
3154:                //
3155:                if (embTestConfig.getIncludeLongRunningTest()) {
3156:                    String largeFilePath = embTestConfig.getMediaDir()
3157:                            + File.separatorChar + "Generated"
3158:                            + File.separatorChar + "largeFile.test";
3159:                    File largeFile = new File(largeFilePath);
3160:                    largeFile.createNewFile();
3161:                    FileOutputStream largeFileOutputStream = new FileOutputStream(
3162:                            largeFile);
3163:                    // create byte array 1 byte larger than maxMediaSize
3164:                    byte[] testArray = EMBStaticHelper
3165:                            .createRandomByteArray(Integer
3166:                                    .parseInt(embTestConfig.getMaxMediaSize()) + 1);
3167:                    largeFileOutputStream.write(testArray);
3168:                    largeFileOutputStream.close();
3169:
3170:                    String testInstance = mebTester.createMediaEntityBean();
3171:                    mebTester.setMediaEntityName(testInstance,
3172:                            "largeMedia.test");
3173:                    try {
3174:                        exception = mebTester.setContentExceptions(
3175:                                testInstance, largeFile);
3176:                    } catch (Throwable e) {
3177:                        fail("test 7 threw " + e.toString());
3178:                    }
3179:                    assertEquals(
3180:                            "test 7: Should throw a ContentTooLargeException",
3181:                            MediaEntityLocalTestDriver.CONTENTTOOLARGE,
3182:                            exception);
3183:                    testTrace("test 7 passed");
3184:                    largeFile.delete();
3185:                    mebTester.removeMEBByPK(testInstance);
3186:                }
3187:
3188:                mebTester.removeMEBByPK(me1);
3189:                mebTester.removeMEBByPK(me4NE);
3190:                mebTester.removeMEBByPK(me5);
3191:                succeed();
3192:            }
3193:
3194:            /**
3195:             * <pre>
3196:             *
3197:             *  Testcase name: setDescription(String)
3198:             *  Testcase Number: EMB128
3199:             *
3200:             *  setup: create Media entity from embedded media file
3201:             *
3202:             *  test procedure:
3203:             *  1.call setDescription(null)
3204:             *    expected result: NullPointerException
3205:             *
3206:             *  2.call setDescription(&quot;&quot;)
3207:             *    expected result : no exception
3208:             *
3209:             *  3.call getLastModified() and remember timestamp
3210:             *    call setDescription(&quot;abc&quot;)
3211:             *    wait 2 secs and call getDescription
3212:             *    expected result: &quot;abc&quot; and verify timestamp has changed
3213:             *
3214:             *  4.create media listener and call addListener(listener)
3215:             *    call setDescription(&quot;&quot;)
3216:             *    expected result: ListenerVetoException
3217:             *
3218:             * </pre>
3219:             */
3220:            public void testEMB128() throws MediaException, IOException,
3221:                    InterruptedException, CreateException, RemoteException,
3222:                    NamingException, FinderException, RemoveException {
3223:
3224:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3225:                        embTestConfig.getBmpPictureName1());
3226:                String me1 = mebTester.createMediaEntityBean();
3227:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3228:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3229:                int exception = -1;
3230:                //
3231:                // test 1
3232:                //
3233:                mebTester.setMediaEntityDescription(me1, null);
3234:                assertNull("test 1: Description should be null", mebTester
3235:                        .getMediaEntityDescription(me1));
3236:                testTrace("test 1 passed");
3237:                //
3238:                // test 2
3239:                //
3240:                try {
3241:                    mebTester.setMediaEntityDescription(me1, "");
3242:                    testTrace("test 2 passed");
3243:                } catch (Throwable e) {
3244:                    fail("test 2 threw exception  " + e.toString());
3245:                } //
3246:                // test 3
3247:                //
3248:                Date beforeStamp = new Date(mebTester
3249:                        .getMediaEntityLastModified(me1));
3250:                String tstDesc = EMBStaticHelper.createRandomString(12);
3251:                mebTester.setMediaEntityDescription(me1, tstDesc);
3252:                Thread.sleep(1000);
3253:                assertEquals("test 3 description", mebTester
3254:                        .getMediaEntityDescription(me1), tstDesc);
3255:                Date afterStamp = new Date(mebTester
3256:                        .getMediaEntityLastModified(me1));
3257:                assertTrue("test 3: Modification date", afterStamp
3258:                        .after(beforeStamp));
3259:                testTrace("test 3 passed");
3260:                //
3261:                // test 4
3262:                //
3263:                GenericMediaListener testListener = new GenericMediaListener();
3264:                mebTester.addMediaEntityListener(me1, testListener);
3265:                try {
3266:                    exception = mebTester.setDescriptionExceptions(me1,
3267:                            "newDescription");
3268:                } catch (Throwable e) {
3269:                    fail("test 4 threw " + e.toString());
3270:                }
3271:                assertEquals("test 4: Should throw a ListenerVetoException",
3272:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
3273:                assertEquals("test 4: description should not change", tstDesc,
3274:                        mebTester.getMediaEntityDescription(me1));
3275:                testTrace("test 4 passed");
3276:
3277:                mebTester.removeMEBByPK(me1);
3278:                succeed();
3279:            }
3280:
3281:            /**
3282:             * <pre>
3283:             *
3284:             *  Testcase Name: setLocation(URL)
3285:             *  Testcase Number: EMB129
3286:             *
3287:             *  setup: create Media entity using instance of MediaEntityLocalHome
3288:             *
3289:             *  test procedure:
3290:             *  1.call setLocation(null)
3291:             *    call getLocation
3292:             *    expected result: null
3293:             *
3294:             *  2.call getLastModified() and remember timestamp
3295:             *    call setLocation(valid local location URL)
3296:             *    wait 2 seconds and call getLocation
3297:             *    expected result: URL equal to new location and timestamp was updated
3298:             *
3299:             *  3.create media listener and call addListener(listener)
3300:             *    call setLocation(valid URL)
3301:             *    expected result: ListenerVetoException
3302:             *
3303:             *  4.call setContent with byte array from testPicture1.jpg
3304:             *    call setLocation(valid URL)
3305:             *    expected result: LocationUnmutableException
3306:             *
3307:             * </pre>
3308:             */
3309:            public void testEMB129() throws MediaException, IOException,
3310:                    InterruptedException, CreateException, RemoteException,
3311:                    NamingException, FinderException, RemoveException {
3312:
3313:                mebTester.bindMediaFormat("jpg", new JpegFormat());
3314:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3315:                        embTestConfig.getJpgPictureName1());
3316:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
3317:                        embTestConfig.getJpgPictureName2());
3318:
3319:                String me1 = mebTester.createMediaEntityBean();
3320:                mebTester.setMediaEntityName(me1, "test.jpg");
3321:                int exception = -1;
3322:                //
3323:                // test 1
3324:                //
3325:                mebTester.setMediaEntityLocation(me1, null);
3326:                assertNull("test 1: location not null", mebTester
3327:                        .getMediaEntityLocation(me1));
3328:                testTrace("test 1 passed");
3329:                //
3330:                // test 2
3331:                //
3332:                Date beforeStamp = new Date(mebTester
3333:                        .getMediaEntityLastModified(me1));
3334:                mebTester.setMediaEntityLocation(me1, me1LocInfo.getMediaURL());
3335:                Thread.sleep(1000);
3336:                Date afterStamp = new Date(mebTester
3337:                        .getMediaEntityLastModified(me1));
3338:                assertTrue("test 2: Modification date", afterStamp
3339:                        .after(beforeStamp));
3340:                assertTrue("test 2: URL did not change", mebTester
3341:                        .getMediaEntityLocation(me1).equals(
3342:                                me1LocInfo.getMediaURL()));
3343:                testTrace("test 2 passed");
3344:                //
3345:                // test 3
3346:                //
3347:                GenericMediaListener testListener = new GenericMediaListener();
3348:                mebTester.addMediaEntityListener(me1, testListener);
3349:                try {
3350:                    exception = mebTester.setLocationExceptions(me1, me2LocInfo
3351:                            .getMediaURL());
3352:                } catch (Throwable e) {
3353:                    fail("test 3 threw " + e.toString());
3354:                }
3355:                assertEquals("test 3: Should throw a ListenerVetoException",
3356:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
3357:                assertTrue("test 3: URL should not change", me1LocInfo
3358:                        .getMediaURL().equals(
3359:                                mebTester.getMediaEntityLocation(me1)));
3360:                testTrace("test 3 passed");
3361:                //
3362:                // test 4
3363:                //
3364:                String me2 = mebTester.createMediaEntityBean();
3365:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
3366:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
3367:                try {
3368:                    exception = mebTester.setLocationExceptions(me2, me1LocInfo
3369:                            .getMediaURL());
3370:                } catch (Throwable e) {
3371:                    fail("test 4 threw " + e.toString());
3372:                }
3373:                assertEquals(
3374:                        "test 4: Should throw a LocationUnmutableException",
3375:                        MediaEntityLocalTestDriver.LOCATIONUNMUTABLE, exception);
3376:                testTrace("test 4 passed");
3377:
3378:                mebTester.removeMEBByPK(me1);
3379:                mebTester.removeMEBByPK(me2);
3380:                succeed();
3381:            }
3382:
3383:            /**
3384:             * <pre>
3385:             *
3386:             *  Testcase Name: setMimeType(String)
3387:             *  Testcase Number: EMB130
3388:             *
3389:             *  setup: create Media entity from embedded media file
3390:             *
3391:             *  test procedure:
3392:             *  1.call setMimeType(null)
3393:             *    expected result: NullPointerException
3394:             *
3395:             *  2.call getLastModified() and remember timestamp
3396:             *    call setMimeType(&quot;www/unknown&quot;)
3397:             *    wait 2 seconds and call check getMimeType()
3398:             *    expected result: mime type equal to &quot;www/unknown&quot; and timestamp updated
3399:             *
3400:             *  3.create media listener and call addListener(listener)
3401:             *    call setMimeType(&quot;image/bmp&quot;);
3402:             *    expected result: ListenerVetoException
3403:             *
3404:             * </pre>
3405:             */
3406:            public void testEMB130() throws MalformedURLException,
3407:                    InterruptedException, MediaException, IOException,
3408:                    CreateException, RemoteException, NamingException,
3409:                    FinderException, RemoveException {
3410:
3411:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3412:                        embTestConfig.getBmpPictureName1());
3413:                String me1 = mebTester.createMediaEntityBean();
3414:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3415:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3416:                int exception = -1;
3417:                //
3418:                // test 1
3419:                //
3420:                try {
3421:                    mebTester.setMediaEntityMimeType(me1, null);
3422:                } catch (Throwable e) {
3423:                    fail("test 1 threw " + e.toString());
3424:                }
3425:                assertNotNull("test 1: mimeType is null", mebTester
3426:                        .getMediaEntityMimeType(me1));
3427:                testTrace("test 1 passed");
3428:                //
3429:                // test 2
3430:                //
3431:                Date beforeStamp = new Date(mebTester
3432:                        .getMediaEntityLastModified(me1));
3433:                String tstMimeType = "www/unknown";
3434:                mebTester.setMediaEntityMimeType(me1, tstMimeType);
3435:                Thread.sleep(1000);
3436:                Date afterStamp = new Date(mebTester
3437:                        .getMediaEntityLastModified(me1));
3438:                assertTrue("test 2: Modification date", afterStamp
3439:                        .after(beforeStamp));
3440:                assertEquals("test 2 URL changed", mebTester
3441:                        .getMediaEntityMimeType(me1), tstMimeType);
3442:                testTrace("test 2 passed");
3443:                //
3444:                // test 3
3445:                //
3446:                GenericMediaListener testListener = new GenericMediaListener();
3447:                mebTester.addMediaEntityListener(me1, testListener);
3448:                try {
3449:                    exception = mebTester.setMimeTypeExceptions(me1,
3450:                            "image/bmp");
3451:                } catch (Throwable e) {
3452:                    fail("test 3 threw " + e.toString());
3453:                }
3454:                assertEquals("test 3: Should throw a ListenerVetoException",
3455:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
3456:
3457:                assertEquals("test 3: mimeType should not change", tstMimeType,
3458:                        mebTester.getMediaEntityMimeType(me1));
3459:                testTrace("test 3 passed");
3460:
3461:                mebTester.removeMEBByPK(me1);
3462:                succeed();
3463:            }
3464:
3465:            /**
3466:             * <pre>
3467:             *
3468:             *  Testcase Name: setName()
3469:             *  Testcase Number: EMB131
3470:             *
3471:             *  setup: create Media entity from jpg media file
3472:             * 		  rebind jpg to format registry
3473:             *  test procedure:
3474:             *  1.call setName(null)
3475:             *    expected result: NullPointerException
3476:             *
3477:             *  2.call setName with random string and file extension
3478:             *    expected result: IllegalArgumentException
3479:             *
3480:             *  3.call setName with string and random file extension (no invalid characters)
3481:             *    expected result: FormatNotFoundException
3482:             *
3483:             *  4.call setName with random string and jpeg file extension
3484:             *    call getName
3485:             *    expected result: name matches random string
3486:             *
3487:             *  5.create media listener and call addListener(listener)
3488:             *    call setName(&quot;test.jpg&quot;)
3489:             *    expected result: ListenerVetoException
3490:             *
3491:             * </pre>
3492:             */
3493:            public void testEMB131() throws IOException, MediaException,
3494:                    CreateException, RemoteException, NamingException,
3495:                    FinderException, RemoveException {
3496:
3497:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3498:                        embTestConfig.getBmpPictureName1());
3499:                String me1 = mebTester.createMediaEntityBean();
3500:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3501:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3502:                int exception = -1;
3503:                //
3504:                // test 1
3505:                //
3506:                try {
3507:                    exception = mebTester.setNameExceptions(me1, null);
3508:                } catch (Throwable e) {
3509:                    fail("test 1 threw " + e.toString());
3510:                }
3511:                assertEquals("test 1: Should throw a NullPointerException",
3512:                        MediaEntityLocalTestDriver.NULLPOINTER, exception);
3513:                testTrace("test 1 passed");
3514:                //
3515:                // test 2
3516:                //
3517:                try {
3518:                    exception = mebTester.setNameExceptions(me1,
3519:                            EMBStaticHelper.createRandomString(EMBStaticHelper
3520:                                    .randomInt(0, 5))
3521:                                    + "&(*#?:;,$%"
3522:                                    + '.'
3523:                                    + EMBStaticHelper
3524:                                            .createRandomString(EMBStaticHelper
3525:                                                    .randomInt(0, 3)));
3526:                } catch (Throwable e) {
3527:                    fail("test 2 threw " + e.toString());
3528:                }
3529:                assertEquals("test 2: Should throw a IllegalArgumentException",
3530:                        MediaEntityLocalTestDriver.ILLEGALARGUMENT, exception);
3531:                testTrace("test 2 passed");
3532:                //
3533:                // test 3
3534:                //
3535:                try {
3536:                    mebTester.unbindMediaFormat("lnv");
3537:                } catch (Exception e) {
3538:                }
3539:                try {
3540:                    exception = mebTester.setNameExceptions(me1, "test.lnv");
3541:                } catch (Throwable e) {
3542:                    fail("test 3 threw " + e.toString());
3543:                }
3544:                assertEquals("test 3: Should throw a FormatNotFoundException",
3545:                        MediaEntityLocalTestDriver.FORMATNOTFOUND, exception);
3546:                testTrace("test 3 passed");
3547:                //
3548:                // test 4
3549:                //
3550:                String tempName = "tmp.jpg";
3551:                Date beforeStamp = new Date(mebTester
3552:                        .getMediaEntityLastModified(me1));
3553:                mebTester.setMediaEntityName(me1, tempName);
3554:                Date afterStamp = new Date(mebTester
3555:                        .getMediaEntityLastModified(me1));
3556:                assertTrue("test 4: timestamp not updated", afterStamp
3557:                        .after(beforeStamp));
3558:                assertEquals("test 4: name incorrect", tempName, mebTester
3559:                        .getMediaEntityName(me1));
3560:                testTrace("test 4 passed");
3561:                //
3562:                // test 5
3563:                //
3564:                GenericMediaListener testListener = new GenericMediaListener();
3565:                mebTester.addMediaEntityListener(me1, testListener);
3566:                String oldName = mebTester.getMediaEntityName(me1);
3567:                try {
3568:                    exception = mebTester.setNameExceptions(me1, "test.jpg");
3569:                } catch (ListenerVetoException e) {
3570:                    fail("test 5 threw " + e.toString());
3571:                }
3572:                assertEquals("test 5: Should throw a ListenerVetoException",
3573:                        MediaEntityLocalTestDriver.LISTENERVETO, exception);
3574:                assertEquals("test 5: name should not change", oldName,
3575:                        mebTester.getMediaEntityName(me1));
3576:                testTrace("test 5 passed");
3577:
3578:                mebTester.removeMEBByPK(me1);
3579:                succeed();
3580:            }
3581:
3582:            /**
3583:             * <pre>
3584:             *
3585:             *  Testcase Name: setPreviousVersion(MediaEntityLocal)
3586:             *  Testcase Number: EMB132
3587:             *
3588:             *  setup: create Media entities me1, me2, and me3 from embedded media files
3589:             *
3590:             *  test procedure:
3591:             *  1.call me1.setPreviousVersion(null)
3592:             *    call me1.getPreviousVersion() and me1.getNextVersion()
3593:             *    expected result: both are null
3594:             *
3595:             *  2.call me2.setPreviousVersion(me1)
3596:             *   expected result: me1.getPreviousVersion() is null
3597:             *   				  me1.getNextVersion() is me2
3598:             *  			  		  me2.getPreviousVersion() is me1
3599:             *  					  me2.getNextVersion() is null
3600:             *
3601:             *  3.call me2.setPreviousVersion(me1)
3602:             *    expected result: no exception
3603:             *
3604:             *  4.call me3.setPreviousVersion(me1)
3605:             *    expected result: VersionIntegrityException
3606:             *
3607:             *  5.call me2.setPreviousVersion(me3)
3608:             *    expected result: VersionIntegrityException
3609:             *
3610:             *  6.call me1.setPreviousVersion(me3)
3611:             *    expected result: VersionIntegrityException
3612:             *
3613:             *  7.call me3.setPreviousVersion(null)
3614:             *    expected result: no exception
3615:             *
3616:             *  8.call me3.setPreviousVersion(me2)
3617:             *    expected result: me1.getPreviousVersion() is null
3618:             *  					  me1.getNextVersion() is me2
3619:             *   				  me2.getPreviousVersion() is me1
3620:             * 					  me2.getNextVersion() is me3
3621:             *   				  me3.getPreviousVersion() is me2
3622:             *  					  me3.getNextVersion() is null
3623:             *
3624:             *  9.call me2.setPreviousVersion(null)
3625:             *    expected result: VersionIntegrityException
3626:             *
3627:             *  10.call me3.setPreviousVersion(null)
3628:             *     expected result: me1.getPreviousVersion() is null
3629:             *     				   me2.getPreviousVersion() is me1
3630:             *  					   me2.getNextVersion() is null
3631:             *  					   me3.getPreviousVersion() is null
3632:             *  					   me3.getNextVersion() is null
3633:             *
3634:             *
3635:             * </pre>
3636:             */
3637:            public void testEMB132() throws MalformedURLException, IOException,
3638:                    MediaException, CreateException, RemoteException,
3639:                    NamingException, FinderException, RemoveException {
3640:
3641:                mebTester.bindMediaFormat("jpg", new JpegFormat());
3642:                mebTester.bindMediaFormat("bmp", new BmpFormat());
3643:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3644:                        embTestConfig.getJpgPictureName1());
3645:                String me1 = mebTester.createMediaEntityBean();
3646:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3647:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3648:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
3649:                        embTestConfig.getJpgPictureName2());
3650:                String me2 = mebTester.createMediaEntityBean();
3651:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
3652:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
3653:                EmbeddedMediaLocationInfo me3LocInfo = new EmbeddedMediaLocationInfo(
3654:                        embTestConfig.getBmpPictureName1());
3655:                String me3 = mebTester.createMediaEntityBean();
3656:                mebTester.setMediaEntityName(me3, me3LocInfo.getMediaName());
3657:                mebTester.setMediaEntityContent(me3, me3LocInfo.getMediaFile());
3658:                int exception = -1;
3659:                //
3660:                // test 1
3661:                //
3662:                try {
3663:                    mebTester.setMediaEntityPreviousVersion(me1, null);
3664:                } catch (Throwable e) {
3665:                    fail("test 1 threw " + e.toString());
3666:                }
3667:                assertNull("test 1: me1.getPreviousVersion is not null",
3668:                        mebTester.getMediaEntityPreviousVersion(me1));
3669:                assertNull("test 1: me1.getNextVersion is not null", mebTester
3670:                        .getMediaEntityNextVersion(me1));
3671:                testTrace("test 1 passed");
3672:                //
3673:                // test 2
3674:                //
3675:                mebTester.setMediaEntityPreviousVersion(me2, me1);
3676:                assertNull("test 2: me1.getPreviousVersion is not null",
3677:                        mebTester.getMediaEntityPreviousVersion(me1));
3678:                assertEquals("test 2: me1.getNextVersion is not me2", mebTester
3679:                        .getMediaEntityNextVersion(me1), me2);
3680:                assertEquals("test 2: me2.getPreviousVersion is not me1",
3681:                        mebTester.getMediaEntityPreviousVersion(me2), me1);
3682:                assertNull("test 2: me2.getNextVersion is not null", mebTester
3683:                        .getMediaEntityNextVersion(me2));
3684:                testTrace("test 2 passed");
3685:                //
3686:                // test 3
3687:                //
3688:                try {
3689:                    mebTester.setMediaEntityPreviousVersion(me2, me1);
3690:                    testTrace("test 3 passed");
3691:                } catch (Throwable e) {
3692:                    fail(" test 3 threw " + e.toString());
3693:                } //
3694:                // test 4
3695:                //
3696:                try {
3697:                    exception = mebTester
3698:                            .setPreviousVersionExceptions(me3, me1);
3699:                } catch (Throwable e) {
3700:                    fail("test 4 threw " + e.toString());
3701:                }
3702:                assertEquals(
3703:                        "test 4: Should throw a VersionChainIntegrityException",
3704:                        MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY,
3705:                        exception);
3706:                testTrace("test 4 passed");
3707:                //
3708:                // test 5
3709:                //
3710:                try {
3711:                    exception = mebTester
3712:                            .setPreviousVersionExceptions(me2, me3);
3713:                } catch (Throwable e) {
3714:                    fail("test 5 threw " + e.toString());
3715:                }
3716:                assertEquals(
3717:                        "test 5: Should throw a VersionChainIntegrityException",
3718:                        MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY,
3719:                        exception);
3720:                testTrace("test 5 passed");
3721:                //
3722:                // test 6
3723:                //
3724:                try {
3725:                    exception = mebTester
3726:                            .setPreviousVersionExceptions(me1, me3);
3727:                } catch (Throwable e) {
3728:                    fail("test 6 threw " + e.toString());
3729:                }
3730:                assertEquals(
3731:                        "test 6: Should throw a VersionChainIntegrityException",
3732:                        MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY,
3733:                        exception);
3734:                testTrace("test 6 passed");
3735:                //
3736:                // test 7
3737:                //
3738:                try {
3739:                    mebTester.setMediaEntityPreviousVersion(me3, null);
3740:                    testTrace("test 7 passed");
3741:                } catch (Throwable e) {
3742:                    fail(" test 7 threw " + e.toString());
3743:                } //
3744:                // test 8
3745:                //
3746:                mebTester.setMediaEntityPreviousVersion(me3, me2);
3747:                assertNull("test 8: me1.getPreviousVersion is not null",
3748:                        mebTester.getMediaEntityPreviousVersion(me1));
3749:                assertEquals("test 8: me1.getNextVersion is not me2", mebTester
3750:                        .getMediaEntityNextVersion(me1), me2);
3751:                assertEquals("test 8: me2.getPreviousVersion is not me1",
3752:                        mebTester.getMediaEntityPreviousVersion(me2), me1);
3753:                assertEquals("test 8: me2.getNextVersion is not me3", mebTester
3754:                        .getMediaEntityNextVersion(me2), me3);
3755:                assertEquals("test 8: me3.getPreviousVersion is not me2",
3756:                        mebTester.getMediaEntityPreviousVersion(me3), me2);
3757:                assertNull("test 8: me3.getNextVersion is not null", mebTester
3758:                        .getMediaEntityNextVersion(me3));
3759:                testTrace("test 8 passed");
3760:                //
3761:                // test 9
3762:                //
3763:                try {
3764:                    exception = mebTester.setPreviousVersionExceptions(me2,
3765:                            null);
3766:                } catch (Throwable e) {
3767:                    fail("test 9 threw " + e.toString());
3768:                }
3769:                assertEquals(
3770:                        "test 9: Should throw a VersionChainIntegrityException",
3771:                        MediaEntityLocalTestDriver.VERSIONCHAININTEGRITY,
3772:                        exception);
3773:                testTrace("test 9 passed");
3774:                //
3775:                // test 10
3776:                //
3777:                mebTester.setMediaEntityPreviousVersion(me3, null);
3778:                assertNull("test 10: me1.getPreviousVersion is not null",
3779:                        mebTester.getMediaEntityPreviousVersion(me1));
3780:                assertEquals("test 10: me1.getNextVersion is not me2",
3781:                        mebTester.getMediaEntityNextVersion(me1), me2);
3782:                assertEquals("test 10: me2.getPreviousVersion is not me1",
3783:                        mebTester.getMediaEntityPreviousVersion(me2), me1);
3784:                assertNull("test 10: me2.getNextVersion is not null", mebTester
3785:                        .getMediaEntityNextVersion(me2));
3786:                assertNull("test 10: me3.getPreviousVersion is not null",
3787:                        mebTester.getMediaEntityPreviousVersion(me3));
3788:                assertNull("test 10: me3.getNextVersion is not null", mebTester
3789:                        .getMediaEntityNextVersion(me3));
3790:                testTrace("test 10 passed");
3791:
3792:                mebTester.removeMEBByPK(me1);
3793:                mebTester.removeMEBByPK(me2);
3794:                mebTester.removeMEBByPK(me3);
3795:                succeed();
3796:            }
3797:
3798:            /**
3799:             * <pre>
3800:             *
3801:             *  Testcase Name: setProxy(MediaEntityLocal)
3802:             *  Testcase Number: EMB133
3803:             *
3804:             *  setup: create Media entites me1 and me2 from embedded media files
3805:             *
3806:             *  test procedure:
3807:             *  1.call me1.setProxy(me2)
3808:             *    call me1.getProxy()
3809:             *    expected result: me2
3810:             *
3811:             *  2.call me2.setProxy(null)
3812:             *    call me2.getProxy()
3813:             *    expected result: not null and not me2
3814:             *
3815:             *  3.call me1.setProxy(me2)
3816:             *    call me2.setProxy(me1)
3817:             *    call me1.setProxy(me1)
3818:             *    expected result: no exception
3819:             *
3820:             * </pre>
3821:             */
3822:            public void testEMB133() throws MalformedURLException,
3823:                    InterruptedException, IOException, MediaException,
3824:                    CreateException, RemoteException, NamingException,
3825:                    FinderException, RemoveException {
3826:
3827:                mebTester.bindMediaFormat("jpg", new JpegFormat());
3828:                mebTester.bindMediaFormat("bmp", new BmpFormat());
3829:
3830:                EmbeddedMediaLocationInfo me1LocInfo = new EmbeddedMediaLocationInfo(
3831:                        embTestConfig.getBmpPictureName1());
3832:                String me1 = mebTester.createMediaEntityBean();
3833:                mebTester.setMediaEntityName(me1, me1LocInfo.getMediaName());
3834:                mebTester.setMediaEntityContent(me1, me1LocInfo.getMediaFile());
3835:
3836:                EmbeddedMediaLocationInfo me2LocInfo = new EmbeddedMediaLocationInfo(
3837:                        embTestConfig.getJpgPictureName1());
3838:                String me2 = mebTester.createMediaEntityBean();
3839:                mebTester.setMediaEntityName(me2, me2LocInfo.getMediaName());
3840:                mebTester.setMediaEntityContent(me2, me2LocInfo.getMediaFile());
3841:
3842:                MediaBean bmpMediaBean = new MediaBean(me1LocInfo
3843:                        .getMediaFile(), "image/bmp");
3844:                MediaBean jpgMediaBean = new MediaBean(me2LocInfo
3845:                        .getMediaFile(), "image/jpeg");
3846:                Media proxy = null;
3847:                //
3848:                // test 1
3849:                //
3850:                mebTester.setMediaEntityProxy(me1, me2);
3851:                try {
3852:                    proxy = mebTester.getMediaEntityProxy(me1);
3853:                    assertNotNull("test 1: proxy is null", proxy);
3854:                } catch (Throwable e) {
3855:                    fail("test 1 threw " + e.toString());
3856:                }
3857:                assertTrue("test 1: proxy does not match", Arrays.equals(proxy
3858:                        .getContent(), mebTester.getMediaEntityContent(me2)));
3859:                testTrace("test 1 passed");
3860:                //
3861:                // test 2
3862:                //
3863:                mebTester.setMediaEntityProxy(me1, null);
3864:                assertNotNull("test 2: proxy is null", mebTester
3865:                        .getMediaEntityProxy(me1));
3866:                assertFalse("test 2: proxy not altered", Arrays.equals(
3867:                        mebTester.getMediaEntityProxy(me1).getContent(),
3868:                        mebTester.getMediaEntityContent(me2)));
3869:                testTrace("test 2 passed");
3870:                //
3871:                // test 3
3872:                //
3873:                try {
3874:                    mebTester.setMediaEntityProxy(me1, me2);
3875:                    mebTester.setMediaEntityProxy(me2, me1);
3876:                    mebTester.setMediaEntityProxy(me1, me1);
3877:                    testTrace("test 3 passed");
3878:                } catch (Throwable e) {
3879:                    fail("test 3  threw Exception " + e.toString());
3880:                }
3881:
3882:                mebTester.removeMEBByPK(me1);
3883:                mebTester.removeMEBByPK(me2);
3884:                succeed();
3885:            }
3886:
3887:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.