Source Code Cross Referenced for ProtocolConstraintsTest.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 javax.emb.MediaException;
004:        import javax.emb.ProtocolConstraints;
005:
006:        import com.ibm.emb.junit.EMBStaticHelper;
007:        import com.ibm.emb.junit.EMBTestCaseBase;
008:        import com.ibm.emb.junit.EMBTestRunner;
009:
010:        /**
011:         * <pre>
012:         *
013:         *
014:         *
015:         *
016:         *     Line Item: MFB API
017:         *     Subcategory 1: javax.emb
018:         *     Subcategory 2: ProtocolConstraint
019:         *
020:         *
021:         *
022:         *
023:         * </pre>
024:         */
025:        public class ProtocolConstraintsTest extends EMBTestCaseBase {
026:
027:            public ProtocolConstraintsTest(String name) throws MediaException {
028:                super (name);
029:            }
030:
031:            public static void main(String args[]) {
032:                EMBTestRunner.run(ProtocolConstraintsTest.class);
033:            }
034:
035:            /**
036:             * <pre>
037:             *
038:             *
039:             *
040:             *
041:             *     Testcase Name: getConstraint(String)
042:             *     Testcase Number: EMB145
043:             *
044:             *     setup: create testInstance of ProtocolConstraints
045:             *
046:             *     test procedure:
047:             *     1.call getConstraint(null)
048:             *       expected result: NullPointerException
049:             *
050:             *     2.call getConstraint(random String)
051:             *       expected result: null
052:             *
053:             *     3.call setConstraint(&quot;test&quot;, random String)
054:             *       call getConstraint(&quot;test&quot;)
055:             *       expected result: random String that was passed in
056:             *
057:             *     4.call setConstraint(&quot;SERVER_TYPE, random array of Strings)
058:             *     	 call getConstraint(&quot;SERVER_TYPE&quot;)
059:             *       expected result: array of Strings
060:             *
061:             *
062:             *
063:             *
064:             * </pre>
065:             */
066:            public void testEMB145() {
067:                //
068:                // test 1
069:                //
070:                ProtocolConstraints testInstance = new ProtocolConstraints();
071:                try {
072:                    testInstance.getConstraint(null);
073:                    fail("test 1: Should throw a NullPointerException");
074:                } catch (NullPointerException e) {
075:                    testTrace("test 1 passed");
076:                } catch (Exception e) {
077:                    fail("test 1: Should throw a NullPointerException but threw "
078:                            + e.toString());
079:                }
080:                //
081:                // test 2
082:                //
083:                testInstance = new ProtocolConstraints();
084:                assertNull("test 2: random constraint not null", testInstance
085:                        .getConstraint(EMBStaticHelper
086:                                .createRandomString(EMBStaticHelper.randomInt(
087:                                        0, 10))));
088:                testTrace("test 2 passed");
089:                //
090:                // test 3
091:                //
092:                testInstance = new ProtocolConstraints();
093:                String constraint = "test";
094:                String value = "testValue";
095:                try {
096:                    testInstance.setConstraint(constraint, value);
097:                    fail("test 3: Should throw a IllegalArgumentException.");
098:                } catch (IllegalArgumentException e) {
099:                    testTrace("test 3 passed");
100:                }
101:
102:                //
103:                // test 4
104:                //
105:                testInstance = new ProtocolConstraints();
106:                String[] constraintValues = new String[EMBStaticHelper
107:                        .randomInt(0, 5)];
108:                for (int i = 0; i < constraintValues.length; i++) {
109:                    constraintValues[i] = EMBStaticHelper
110:                            .createRandomString(EMBStaticHelper
111:                                    .randomInt(0, 10));
112:                }
113:                testInstance.setConstraint(ProtocolConstraints.SERVER_TYPE,
114:                        constraintValues);
115:
116:                String[] serverTypeValues = (String[]) testInstance
117:                        .getConstraint(ProtocolConstraints.SERVER_TYPE);
118:                assertTrue("test 4: constraint values do not match",
119:                        java.util.Arrays.equals(serverTypeValues,
120:                                constraintValues));
121:                testTrace("test 4 passed");
122:
123:                succeed();
124:            }
125:
126:            /**
127:             * <pre>
128:             *
129:             *
130:             *
131:             *
132:             *     Testcase Name: getConstraintTypes()
133:             *     Testcase Number: EMB146
134:             *
135:             *     setup: create testInstance of ProtocolConstraints
136:             *
137:             *     test procedure:
138:             *     1.
139:             *       call setConstraint(&quot;SERVER_TYPE&quot;, random array of Strings)
140:             *       call setConstraint(&quot;CLIENT_TYPE&quot;, random array of Strings)
141:             *       expected result: 2 element String array &quot;SERVER_TYPE&quot;, and &quot;CLIENT_TYPE&quot;
142:             *
143:             *
144:             *
145:             *
146:             * </pre>
147:             */
148:            public void testEMB146() {
149:                ProtocolConstraints testInstance = new ProtocolConstraints();
150:
151:                //
152:                // test 1
153:                //
154:
155:                String[] serverTypes = new String[EMBStaticHelper.randomInt(0,
156:                        5)];
157:                for (int i = 0; i < serverTypes.length; i++) {
158:                    serverTypes[i] = EMBStaticHelper
159:                            .createRandomString(EMBStaticHelper
160:                                    .randomInt(0, 10));
161:                }
162:                String[] clientTypes = new String[EMBStaticHelper.randomInt(0,
163:                        5)];
164:                for (int j = 0; j < clientTypes.length; j++) {
165:                    clientTypes[j] = EMBStaticHelper
166:                            .createRandomString(EMBStaticHelper
167:                                    .randomInt(0, 10));
168:                }
169:                testInstance.setConstraint("SERVER_TYPE", serverTypes);
170:                testInstance.setConstraint("CLIENT_TYPE", clientTypes);
171:
172:                String[] constraints = testInstance.getConstraintTypes();
173:                boolean serverTypeFound = false;
174:                boolean clientTypeFound = false;
175:
176:                for (int k = 0; k < constraints.length; k++) {
177:                    if (constraints[k].equals(ProtocolConstraints.SERVER_TYPE)) {
178:                        serverTypeFound = true;
179:                    } else if (constraints[k]
180:                            .equals(ProtocolConstraints.CLIENT_TYPE)) {
181:                        clientTypeFound = true;
182:                    }
183:                }
184:
185:                assertTrue("test 1: did not find constraint (SERVER_TYPE)",
186:                        serverTypeFound);
187:                assertTrue("test 1: did not find constraint (CLIENT_TYPE)",
188:                        clientTypeFound);
189:                testTrace("test 1 passed");
190:
191:                succeed();
192:            }
193:
194:            /**
195:             * <pre>
196:             *
197:             *
198:             *
199:             *
200:             *     Testcase Name: setConstraint(String, Object)
201:             *     Testcase Number: EMB147
202:             *
203:             *     setup: create testInstance of ProtocolConstraints
204:             *
205:             *     test procedure:
206:             *
207:             *     1.call setConstraint(null, random String)
208:             *       expected result: NullPointerException
209:             *
210:             *     2.call setConstraint(&quot;test&quot;, null)
211:             *       expected result: NullPointerException
212:             *
213:             *     3.call setConstraint(&quot;test&quot;, random String)
214:             *       call getConstraint(&quot;test&quot;)
215:             *       expected result: random String that was passed in
216:             *
217:             *     4.a.call setConstraint(&quot;SERVER_TYPE&quot;, array of Strings)
218:             *         call getConstraint(&quot;SERVER_TYPE&quot;)
219:             *         expected result: array of Strings passed in
220:             *     	 b.call setConstraint(&quot;SERVER_TYPE&quot;, random Object)
221:             *         expected result: IllegalArgumentException
222:             *
223:             *     5.a.call setConstraint(&quot;CLIENT_TYPE&quot;, array of Strings)
224:             *         call getConstraint(&quot;CLIENT_TYPE&quot;)
225:             *         expected result: array of Strings passed in
226:             *     	 b.call setConstraint(&quot;CLIENT_TYPE&quot;, random Object)
227:             *         expected result: IllegalArgumentException
228:             *
229:             *
230:             *
231:             *
232:             * </pre>
233:             */
234:            public void testEMB147() {
235:                //
236:                // test 1
237:                //
238:                ProtocolConstraints testInstance = new ProtocolConstraints();
239:                try {
240:                    testInstance.setConstraint(null, new Object());
241:                    fail("test 1: Should throw a NullPointerException");
242:                } catch (NullPointerException e) {
243:                    testTrace("test 1 passed");
244:                } catch (Exception e) {
245:                    fail("test 1: Should throw a NullPointerException but threw "
246:                            + e.toString());
247:                }
248:
249:                //
250:                // test 2
251:                //
252:                testInstance = new ProtocolConstraints();
253:                try {
254:                    testInstance.setConstraint("test", null);
255:                    fail("test 2: Should throw a IllegalArgumentException");
256:                } catch (NullPointerException e) {
257:                    fail("test 2: Should throw a IllegalArgumentException but threw "
258:                            + e.toString());
259:                } catch (IllegalArgumentException e) {
260:                    testTrace("test 2 passed");
261:                } catch (Exception e) {
262:                    fail("test 2: Should throw a IllegalArgumentException but threw "
263:                            + e.toString());
264:                }
265:
266:                //
267:                // test 3
268:                //
269:                testInstance = new ProtocolConstraints();
270:                String[] testString = { EMBStaticHelper
271:                        .createRandomString(EMBStaticHelper.randomInt(0, 50)) };
272:                testInstance.setConstraint(ProtocolConstraints.SERVER_TYPE,
273:                        testString);
274:                assertSame("test 3: ", testString, testInstance
275:                        .getConstraint(ProtocolConstraints.SERVER_TYPE));
276:                testTrace("test 3 passed");
277:
278:                //
279:                // test 4a
280:                //
281:                testInstance = new ProtocolConstraints();
282:                String[] serverTypes = new String[EMBStaticHelper.randomInt(0,
283:                        5)];
284:                for (int i = 0; i < serverTypes.length; i++) {
285:                    serverTypes[i] = EMBStaticHelper
286:                            .createRandomString(EMBStaticHelper
287:                                    .randomInt(0, 10));
288:                }
289:                testInstance.setConstraint(ProtocolConstraints.SERVER_TYPE,
290:                        serverTypes);
291:                assertTrue(
292:                        "test 4a: server types do not match",
293:                        java.util.Arrays
294:                                .equals(
295:                                        serverTypes,
296:                                        (String[]) testInstance
297:                                                .getConstraint(ProtocolConstraints.SERVER_TYPE)));
298:                testTrace("test 4a passed");
299:                //
300:                // test 4b
301:                //
302:                testInstance = new ProtocolConstraints();
303:                Object randomObj = new Object();
304:                try {
305:                    testInstance.setConstraint(ProtocolConstraints.SERVER_TYPE,
306:                            randomObj);
307:                } catch (IllegalArgumentException e) {
308:                    testTrace("test 4b passed");
309:                } catch (Exception e) {
310:                    fail("test 4b: Should throw a MediaException");
311:                }
312:
313:                //
314:                // test 5a
315:                //
316:                testInstance = new ProtocolConstraints();
317:                String[] clientTypes = new String[EMBStaticHelper.randomInt(0,
318:                        5)];
319:                for (int j = 0; j < clientTypes.length; j++) {
320:                    clientTypes[j] = EMBStaticHelper
321:                            .createRandomString(EMBStaticHelper
322:                                    .randomInt(0, 10));
323:                }
324:                testInstance.setConstraint(ProtocolConstraints.CLIENT_TYPE,
325:                        clientTypes);
326:                assertTrue(
327:                        "test 5a: server types do not match",
328:                        java.util.Arrays
329:                                .equals(
330:                                        clientTypes,
331:                                        (String[]) testInstance
332:                                                .getConstraint(ProtocolConstraints.CLIENT_TYPE)));
333:                testTrace("test 5a passed");
334:                //
335:                // test 5b
336:                //
337:                testInstance = new ProtocolConstraints();
338:                randomObj = new Object();
339:                try {
340:                    testInstance.setConstraint(ProtocolConstraints.CLIENT_TYPE,
341:                            randomObj);
342:                } catch (IllegalArgumentException e) {
343:                    testTrace("test 5b passed");
344:                } catch (Exception e) {
345:                    fail("test 5b: Should throw a MediaException");
346:                }
347:
348:                succeed();
349:            }
350:
351:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.