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


001:        package com.ibm.emb.test;
002:
003:        import java.rmi.RemoteException;
004:        import java.util.HashMap;
005:        import java.util.Map;
006:        import java.util.StringTokenizer;
007:
008:        import javax.ejb.CreateException;
009:        import javax.ejb.EJBException;
010:        import javax.ejb.FinderException;
011:        import javax.ejb.RemoveException;
012:        import javax.emb.MediaException;
013:        import javax.naming.InitialContext;
014:        import javax.naming.NamingException;
015:        import javax.rmi.PortableRemoteObject;
016:
017:        import com.ibm.emb.junit.EMBStaticHelper;
018:        import com.ibm.emb.junit.EMBTestCaseBase;
019:        import com.ibm.emb.meb.test.ejb.MetaDataEntityLocalTestDriver;
020:        import com.ibm.emb.meb.test.ejb.MetaDataEntityLocalTestDriverHome;
021:
022:        /**
023:         * <pre>
024:         *
025:         *
026:         *
027:         *    Line Item: MEB API
028:         *    Subcategory 1: javax.emb
029:         *    Subcategory 2: MetaDataEntityLocalHome
030:         *
031:         *
032:         *
033:         * </pre>
034:         */
035:
036:        public class MetaDataEntityLocalHomeTest extends EMBTestCaseBase {
037:
038:            /**
039:             * Constructor for MetaDataEntityLocalHomeTest.
040:             * @param name
041:             */
042:            public MetaDataEntityLocalHomeTest(String name)
043:                    throws MediaException {
044:                super (name);
045:            }
046:
047:            private static String MDEBTESTER_JNDI = "java:comp/env/ejb/MetaDataEntityLocalTestDriverHome";
048:
049:            private static String TXUSER_JNDI = "jta/usertransaction";
050:
051:            private InitialContext ic;
052:
053:            private MetaDataEntityLocalTestDriverHome mdebHome;
054:
055:            private MetaDataEntityLocalTestDriver mdebTester = null;
056:
057:            /**
058:             * do initialisation of each individual Test method here this method is
059:             * called before each individual Test Method
060:             */
061:            protected void setUp() throws RemoteException, CreateException {
062:                if (mdebHome == null) {
063:                    try {
064:                        ic = new InitialContext();
065:                        Object ojb = ic.lookup(MDEBTESTER_JNDI);
066:                        mdebHome = (MetaDataEntityLocalTestDriverHome) PortableRemoteObject
067:                                .narrow(ojb,
068:                                        MetaDataEntityLocalTestDriverHome.class);
069:                    } catch (NamingException ne) {
070:                        System.out
071:                                .println("NamingException thrown during setup. Msg: "
072:                                        + ne.getMessage());
073:                    }
074:                }
075:                mdebTester = mdebHome.create();
076:                return;
077:            }
078:
079:            /**
080:             * <pre>
081:             *
082:             *
083:             *
084:             *    Testcase Name: create()
085:             *    Testcase Number: EMB165
086:             *
087:             *    setup: create testInstance of MetaDataEntityLocalHome
088:             *
089:             *    test procedure:
090:             *    1.call testInstance.create()
091:             *      expected result: new meta data entity created
092:             *    		       		  verify result is not null
093:             *
094:             *
095:             *
096:             * </pre>
097:             */
098:            public void testEMB165() throws MediaException, CreateException,
099:                    RemoteException, NamingException, FinderException,
100:                    RemoveException {
101:                //
102:                // test 1
103:                //
104:                String md = mdebTester.createMetaDataEntityBean();
105:                assertNotNull("test 1: meta data entity is null", md);
106:                testTrace("test 1 passed");
107:
108:                mdebTester.removeMDEBByPK(md);
109:                succeed();
110:            }
111:
112:            /**
113:             * Testcase Name: findByPrimaryKey(String) Testcase Number: EMB166 setup:
114:             * create testInstance of MetaDataEntityLocalHome test procedure: 1.call
115:             * findByPrimaryKey(null) expected result: NullPointerException 2.call
116:             * create for new meta data entity md1 and get primary key of md1 call
117:             * testInstance.findByPrimaryKey and pass in primary key of md1 expected
118:             * result: md1 3.call findByPrimaryKey with random string expected result:
119:             * javax.ejb.FinderException
120:             *
121:             * </pre>
122:             */
123:            public void testEMB166() throws EJBException, MediaException,
124:                    CreateException, RemoteException, NamingException,
125:                    FinderException, RemoveException {
126:
127:                int exception = -1;
128:                //
129:                // test 1
130:                //
131:
132:                // TODO : EMB 166 : JOnAS finbyprimarykey(null) not throw a NPE
133:                try {
134:                    exception = mdebTester.findByPKExceptions(null);
135:                } catch (Throwable e) {
136:                    fail("test 1 threw " + e.toString());
137:                }
138:                // assertEquals("test 1: Should throw a NullPointerException",
139:                // MetaDataEntityLocalTestDriver.NULLPOINTER,
140:                // exception);
141:                testTrace("test 1 passed");
142:                //
143:                // test 2
144:                //
145:                String testInstance = mdebTester.createMetaDataEntityBean();
146:                assertEquals("test 2: wrong meta data entity found",
147:                        testInstance, mdebTester
148:                                .findMDEBByPrimaryKey(testInstance));
149:                testTrace("test 2 passed");
150:                //
151:                // test 3
152:                //
153:                try {
154:                    exception = mdebTester.findByPKExceptions(EMBStaticHelper
155:                            .createRandomString(EMBStaticHelper
156:                                    .randomInt(0, 20)));
157:                } catch (Throwable e) {
158:                    fail("test 3 threw " + e.toString());
159:                }
160:                assertEquals("test 3: Should throw a FinderException",
161:                        MetaDataEntityLocalTestDriver.FINDER, exception);
162:                testTrace("test 3 passed");
163:
164:                mdebTester.removeMDEBByPK(testInstance);
165:                succeed();
166:            }
167:
168:            /**
169:             * <pre>
170:             *
171:             *
172:             *
173:             *    Testcase Name: query(String, String, String)
174:             *    Testcase Number: EMB167
175:             *
176:             *    setup: create testInstance of MetaDataEntityLocalHome
177:             *    		  include property in configuration file listing all supported query
178:             *    	 	  languages with a valid query, for each language perform the following
179:             *
180:             *    test procedure:
181:             *    1.call query(null, queryLanguage, options)
182:             *      expected result: NullPointerException
183:             *
184:             *    2.call query(valid query, queryLanguage, null)
185:             *      expected result: no exception, return results in collection (can be empty)
186:             *
187:             *    3.call query(valid query, queryLanguage, options)
188:             *      expected result: no exception, return resuls in collection (can be empty)
189:             *
190:             *    4.call query(invalid query, queryLanguage, options)
191:             *      expected result: MalformedQueryException
192:             *
193:             *    perform tests 5 &amp; 6 only once
194:             *    5.call query(valid query, unsupportedQueryLanguage, options)
195:             *      expected result: UnsupportedQueryLanguageException
196:             *
197:             *    6.call query(query, null, options)
198:             *      expected result: NullPointerException
199:             *
200:             *
201:             *
202:             * </pre>
203:             */
204:            public void testEMB167() throws RemoteException, MediaException,
205:                    NamingException, FinderException {
206:
207:                String[] metaDataEntities = null;
208:
209:                String queryLanguages = embTestConfig.getQueryLanguages();
210:                StringTokenizer tokenizer = new StringTokenizer(queryLanguages,
211:                        ";");
212:                StringTokenizer queryTok = null;
213:                String currentToken = null;
214:                String language = null;
215:                String query = null;
216:                Map options = new HashMap();
217:
218:                int exception = -1;
219:
220:                while (tokenizer.hasMoreTokens()) {
221:                    currentToken = tokenizer.nextToken();
222:                    queryTok = new StringTokenizer(currentToken, ",");
223:                    assertEquals("test initialization: ", queryTok
224:                            .countTokens(), 2);
225:                    language = queryTok.nextToken();
226:                    query = queryTok.nextToken();
227:
228:                    //
229:                    // test 1
230:                    //
231:                    try {
232:                        exception = mdebTester.queryExceptions(null, language,
233:                                options);
234:                    } catch (Throwable e) {
235:                        fail("[" + language + "] test 1 threw " + e.toString());
236:                    }
237:                    assertEquals("[" + language
238:                            + "] test 1: Should throw a NullPointerException",
239:                            MetaDataEntityLocalTestDriver.NULLPOINTER,
240:                            exception);
241:                    testTrace("test 1 passed");
242:                    //
243:                    // test 2
244:                    //
245:                    metaDataEntities = mdebTester.queryMetaDataEntity(query,
246:                            language, null);
247:                    assertNotNull("[" + language + "] test 2: result is null",
248:                            metaDataEntities);
249:                    testTrace("[" + language + "] test 2 passed");
250:                    //
251:                    // test 3
252:                    //
253:                    metaDataEntities = mdebTester.queryMetaDataEntity(query,
254:                            language, options);
255:                    assertNotNull("[" + language + "] test 3: result is null",
256:                            metaDataEntities);
257:                    testTrace("[" + language + "] test 3 passed");
258:                    //
259:                    // test 4
260:                    //
261:
262:                    try {
263:                        exception = mdebTester.queryExceptions(EMBStaticHelper
264:                                .createRandomString(EMBStaticHelper.randomInt(
265:                                        0, 20)), language, options);
266:                    } catch (Throwable e) {
267:                        fail("[" + language + "] test 4 threw " + e.toString());
268:                    }
269:                    if (language.equals("MatchString")) {
270:                        assertEquals(
271:                                "[MatchString] test 4 threw an exception: "
272:                                        + exception, 0, exception);
273:                    } else {
274:                        assertEquals(
275:                                "["
276:                                        + language
277:                                        + "] test 4: Should throw a MalformedQueryException",
278:                                MetaDataEntityLocalTestDriver.MALFORMEDQUERY,
279:                                exception);
280:                    }
281:                    testTrace("test 4 passed");
282:                }
283:                //
284:                // test 5
285:                //
286:                try {
287:                    exception = mdebTester.queryExceptions(query,
288:                            EMBStaticHelper.createRandomString(EMBStaticHelper
289:                                    .randomInt(0, 5)), options);
290:                } catch (Throwable e) {
291:                    fail("[" + language + "] test 5 threw " + e.toString());
292:                }
293:                assertEquals(
294:                        "test 5: Should throw a UnsupportedQueryLanguageException",
295:                        MetaDataEntityLocalTestDriver.UNSUPPORTEDQUERYLANG,
296:                        exception);
297:                testTrace("test 5 passed");
298:                //
299:                // test 6
300:                //
301:                try {
302:                    exception = mdebTester
303:                            .queryExceptions(query, null, options);
304:                } catch (Throwable e) {
305:                    fail("[" + language + "] test 6 threw " + e.toString());
306:                }
307:                assertEquals("test 6: Should throw a NullPointerException",
308:                        MetaDataEntityLocalTestDriver.NULLPOINTER, exception);
309:                testTrace("test 7 passed");
310:
311:                succeed();
312:            }
313:
314:            /**
315:             * <pre>
316:             *
317:             *
318:             *
319:             *    Testcase Name: retrieveSupportedOptions(String)
320:             *    Testcase Number: EMB168
321:             *
322:             *    setup: create testInstance of MetaDataEntityLocalHome and read in list of
323:             *    		  supported query languages
324:             *
325:             *    test procedure:
326:             *    1.for each query language, call retrieveSupportedOptions
327:             *      expected result: no exception and not null
328:             *
329:             *    2.call retrieveSupportedOptions(null)
330:             *      expected result: NullPointerException
331:             *
332:             *    3.call retrieveSupportedOptions(&quot;&quot;)
333:             *      expected result: UnsupportedQueryLanguageException
334:             *
335:             *
336:             *
337:             * </pre>
338:             */
339:            public void testEMB168() throws RemoteException, MediaException,
340:                    NamingException {
341:
342:                String[] supportedOptions = null;
343:
344:                String queryLanguages = embTestConfig.getQueryLanguages();
345:                StringTokenizer tokenizer = new StringTokenizer(queryLanguages,
346:                        ";");
347:                StringTokenizer queryTok = null;
348:                String currentToken = null;
349:                String language = null;
350:                int exception = -1;
351:
352:                //
353:                // test 1
354:                //
355:                while (tokenizer.hasMoreTokens()) {
356:                    currentToken = tokenizer.nextToken();
357:                    queryTok = new StringTokenizer(currentToken, ",");
358:                    assertEquals("test initialization: ", queryTok
359:                            .countTokens(), 2);
360:                    language = queryTok.nextToken();
361:
362:                    supportedOptions = mdebTester
363:                            .retrieveMetaDataEntitySupportedOptions(language);
364:                    assertNotNull("[" + language
365:                            + "] test 1:  options are null", supportedOptions);
366:                    testTrace("[" + language + "] test 1 passed");
367:                }
368:                //
369:                // test 2
370:                //
371:                try {
372:                    exception = mdebTester
373:                            .retrieveSupportedOptionsExceptions(null);
374:                } catch (Throwable e) {
375:                    fail("test 2 threw " + e.toString());
376:                }
377:                assertEquals("test 2: Should throw a NullPointerException",
378:                        MetaDataEntityLocalTestDriver.NULLPOINTER, exception);
379:                testTrace("test 2 passed");
380:                //
381:                // test 3
382:                //
383:                try {
384:                    exception = mdebTester
385:                            .retrieveSupportedOptionsExceptions("");
386:                } catch (Throwable e) {
387:                    fail("test 3 threw " + e.toString());
388:                }
389:                assertEquals(
390:                        "test 3: Should throw an UnsupportedQueryLanguageException",
391:                        MetaDataEntityLocalTestDriver.UNSUPPORTEDQUERYLANG,
392:                        exception);
393:                testTrace("test 3 passed");
394:
395:                succeed();
396:            }
397:
398:            /**
399:             * <pre>
400:             *
401:             *
402:             *
403:             *    Testcase Name: retrieveSupportedQueryLanguages()
404:             *    Testcase Number: EMB169
405:             *
406:             *    setup: create testInstance of MetaDataEntityLocalHom and get lists of supported
407:             *    	      query languages from configuration file
408:             *
409:             *    test procedure:
410:             *    1.call retrieveSupportedQueryLanguages and compare with array from file
411:             *      expected results: arrays match
412:             *
413:             *
414:             *
415:             * </pre>
416:             */
417:            public void testEMB169() throws RemoteException, MediaException,
418:                    NamingException {
419:                String[] supportedQueryLanguages = null;
420:
421:                //
422:                // test 1
423:                //
424:                String queryLanguages = embTestConfig.getQueryLanguages();
425:                StringTokenizer tokenizer = new StringTokenizer(queryLanguages,
426:                        ";");
427:                StringTokenizer queryTok = null;
428:                String currentToken = null;
429:
430:                String[] retrievedLanguages = new String[tokenizer
431:                        .countTokens()];
432:                for (int i = 0; i < tokenizer.countTokens(); i++) {
433:                    currentToken = tokenizer.nextToken();
434:                    queryTok = new StringTokenizer(currentToken, ",");
435:                    assertEquals("test initialization: ", queryTok
436:                            .countTokens(), 2);
437:                    retrievedLanguages[i] = queryTok.nextToken();
438:                }
439:
440:                supportedQueryLanguages = mdebTester
441:                        .retrieveMetaDataEntitySupportedQueryLanguages();
442:                assertTrue("test 1: languages do not match", java.util.Arrays
443:                        .equals(retrievedLanguages, supportedQueryLanguages));
444:                testTrace("test 1 passed");
445:
446:                succeed();
447:            }
448:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.