Source Code Cross Referenced for TestMIDletControllerEventProducer.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » main » 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 » 6.0 JDK Modules » j2me » com.sun.midp.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.main;
028:
029:        import com.sun.midp.events.EventQueue;
030:        import com.sun.midp.events.ListenerTestEventQueue;
031:
032:        import com.sun.midp.i3test.TestCase;
033:
034:        import com.sun.midp.security.SecurityToken;
035:
036:        import java.util.Random;
037:
038:        /**
039:         * Unit tests for the MIDletControllerEventProducer class. This class, and
040:         * event producer classes in general, don't have much logic. However, they do
041:         * implement the mapping between specific data and generic event fields (e.g.,
042:         * intParam1 or stringParam2) which is important to test.
043:         */
044:        public class TestMIDletControllerEventProducer extends TestCase
045:                implements  MIDletControllerEventConsumer {
046:
047:            private SecurityToken token;
048:
049:            Random rand = new Random();
050:
051:            // Constant test data.
052:
053:            static final int SUITE_ID = 10000;
054:            static final String CLASS_NAME = "the midlet class name";
055:            static final String DISPLAY_NAME = "the display-name of the midlet";
056:            static final int TARGET_SUITE_ID = 10001;
057:            static final String TARGET_CLASS_NAME = "the target midlet's class name";
058:            static final String ERROR_DETAILES = "the error details";
059:
060:            // The following instance variables comprise the test fixture.
061:            // They are freshly initialized before each test is run.
062:
063:            int currentIsolateId;
064:            int amsIsolateId;
065:            int displayId;
066:            int displayId2;
067:            int externalId;
068:            int errorCode;
069:
070:            EventQueue queue;
071:            MIDletControllerEventProducer producer;
072:            MIDletControllerEventListener listener;
073:
074:            /**
075:             * Runs all tests. If a test throw a NullPointerException,
076:             * the most likely cause is that the listener has not registered with
077:             * the event queue for that event type.
078:             */
079:            public void runTests() throws Throwable {
080:                token = getSecurityToken();
081:
082:                setUp();
083:
084:                declare("testMIDletStartErrorEvent");
085:                testMIDletStartErrorEvent();
086:
087:                declare("testMIDletCreateNotifyEvent");
088:                testMIDletCreateNotifyEvent();
089:
090:                declare("testMIDletActiveNotifyEvent");
091:                testMIDletActiveNotifyEvent();
092:
093:                declare("testMIDletPauseNotifyEvent");
094:                testMIDletPauseNotifyEvent();
095:
096:                declare("testMIDletDestroyNotifyEvent");
097:                testMIDletDestroyNotifyEvent();
098:
099:                declare("testMIDletResumeRequest");
100:                testMIDletResumeRequest();
101:
102:                declare("testMIDletDestroyRequestEvent");
103:                testMIDletDestroyRequestEvent();
104:
105:                declare("testMIDletForegroundTransferEvent");
106:                testMIDletForegroundTransferEvent();
107:
108:                declare("testDisplayCreateNotifyEvent");
109:                testDisplayCreateNotifyEvent();
110:
111:                declare("testDisplayForegroundRequestEvent");
112:                testDisplayForegroundRequestEvent();
113:
114:                declare("testDisplayBackgroundRequestEvent");
115:                testDisplayBackgroundRequestEvent();
116:
117:                declare("testDisplayPreemptEvents");
118:                testDisplayPreemptEvents();
119:
120:                tearDown();
121:            }
122:
123:            /**
124:             * Initializes the test fixture with random data, creates the stub event
125:             * queue, and creates the MIDletControllerEventProducer under test.
126:             */
127:            void setUp() {
128:                currentIsolateId = rand.nextInt();
129:                amsIsolateId = rand.nextInt();
130:                displayId = rand.nextInt();
131:                displayId2 = rand.nextInt();
132:                externalId = rand.nextInt();
133:                errorCode = rand.nextInt();
134:
135:                queue = new ListenerTestEventQueue();
136:                producer = new MIDletControllerEventProducer(queue,
137:                        amsIsolateId, currentIsolateId);
138:                listener = new MIDletControllerEventListener(queue, this );
139:            }
140:
141:            /**
142:             * Nulls out the stub event queue and the event producer.
143:             */
144:            void tearDown() {
145:                queue = null;
146:                producer = null;
147:            }
148:
149:            // the actual tests
150:
151:            /**
152:             * Tests sendMIDletStartErrorEvent().
153:             */
154:            void testMIDletStartErrorEvent() {
155:                producer.sendMIDletStartErrorEvent(SUITE_ID, CLASS_NAME,
156:                        externalId, errorCode, ERROR_DETAILES);
157:            }
158:
159:            /**
160:             * Tests sendMIDletCreateNotifyEvent().
161:             */
162:            void testMIDletCreateNotifyEvent() {
163:                producer.sendMIDletCreateNotifyEvent(SUITE_ID, CLASS_NAME,
164:                        externalId, DISPLAY_NAME);
165:            }
166:
167:            /**
168:             * Tests sendMIDletActiveNotifyEvent().
169:             */
170:            void testMIDletActiveNotifyEvent() {
171:                producer.sendMIDletActiveNotifyEvent(SUITE_ID, CLASS_NAME);
172:            }
173:
174:            /**
175:             * Tests sendMIDletPauseNotifyEvent().
176:             */
177:            void testMIDletPauseNotifyEvent() {
178:                producer.sendMIDletPauseNotifyEvent(SUITE_ID, CLASS_NAME);
179:            }
180:
181:            /**
182:             * Tests sendMIDletDestroyNotifyEvent().
183:             */
184:            void testMIDletDestroyNotifyEvent() {
185:                producer.sendMIDletDestroyNotifyEvent(SUITE_ID, CLASS_NAME);
186:            }
187:
188:            /**
189:             * Tests sendMIDletResumeRequest().
190:             */
191:            void testMIDletResumeRequest() {
192:                producer.sendMIDletResumeRequest(SUITE_ID, CLASS_NAME);
193:            }
194:
195:            /**
196:             * Tests sendMIDletDestroyRequestEvent().
197:             */
198:            void testMIDletDestroyRequestEvent() {
199:                producer.sendMIDletDestroyRequestEvent(displayId);
200:            }
201:
202:            /**
203:             * Tests sendMIDletForegroundTransferEvent().
204:             */
205:            void testMIDletForegroundTransferEvent() {
206:                producer.sendMIDletForegroundTransferEvent(SUITE_ID,
207:                        CLASS_NAME, TARGET_SUITE_ID, TARGET_CLASS_NAME);
208:            }
209:
210:            /**
211:             * Tests sendDisplayCreateNotifyEvent().
212:             */
213:            void testDisplayCreateNotifyEvent() {
214:                producer.sendDisplayCreateNotifyEvent(displayId, CLASS_NAME);
215:            }
216:
217:            /**
218:             * Tests sendDisplayForegroundRequestEvent().
219:             */
220:            void testDisplayForegroundRequestEvent() {
221:                producer.sendDisplayForegroundRequestEvent(displayId, true);
222:            }
223:
224:            /**
225:             * Tests sendDisplayBackgroundRequestEvent().
226:             */
227:            void testDisplayBackgroundRequestEvent() {
228:                producer.sendDisplayBackgroundRequestEvent(displayId);
229:            }
230:
231:            /**
232:             * Tests sendDisplayPreemptStartEvent() and
233:             * sendDisplayPreemptStopEvent().
234:             */
235:            void testDisplayPreemptEvents() {
236:                producer.sendDisplayPreemptStartEvent(displayId);
237:                producer.sendDisplayPreemptStopEvent(displayId2);
238:            }
239:
240:            /**
241:             * Process a MIDlet start error event.
242:             * Notify from last to first added to allow the listener to
243:             * remove itself without causing a missed notification.
244:             *
245:             * MIDletControllerEventConsumer I/F method.
246:             *
247:             * @param midletSuiteId ID of the MIDlet suite
248:             * @param midletClassName Class name of the MIDlet
249:             * @param midletExternalAppId ID of given by an external application
250:             *                            manager
251:             * @param error start error code
252:             * @param details start error details
253:             */
254:            public void handleMIDletStartErrorEvent(int midletSuiteId,
255:                    String midletClassName, int midletExternalAppId, int error,
256:                    String details) {
257:
258:                assertEquals(SUITE_ID, midletSuiteId);
259:                assertEquals(CLASS_NAME, midletClassName);
260:                assertEquals(externalId, midletExternalAppId);
261:                assertEquals(errorCode, error);
262:                assertEquals(ERROR_DETAILES, details);
263:            }
264:
265:            /**
266:             * Process a MIDlet created notification.
267:             * MIDletControllerEventConsumer I/F method.
268:             *
269:             * @param midletSuiteId ID of the MIDlet suite
270:             * @param midletClassName Class name of the MIDlet
271:             * @param midletIsolateId isolate ID of the sending MIDlet
272:             * @param midletExternalAppId ID of given by an external application
273:             *                            manager
274:             * @param midletDisplayName name to show the user
275:             */
276:            public void handleMIDletCreateNotifyEvent(int midletSuiteId,
277:                    String midletClassName, int midletIsolateId,
278:                    int midletExternalAppId, String midletDisplayName) {
279:
280:                assertEquals(SUITE_ID, midletSuiteId);
281:                assertEquals(CLASS_NAME, midletClassName);
282:                assertEquals(currentIsolateId, midletIsolateId);
283:                assertEquals(externalId, midletExternalAppId);
284:                assertEquals(DISPLAY_NAME, midletDisplayName);
285:            }
286:
287:            /**
288:             * Process a MIDlet active notification
289:             * MIDletControllerEventConsumer I/F method.
290:             *
291:             * TBD: param midletProxy proxy with information about MIDlet
292:             *
293:             * @param midletSuiteId ID of the MIDlet suite
294:             * @param midletClassName Class name of the MIDlet
295:             */
296:            public void handleMIDletActiveNotifyEvent(int midletSuiteId,
297:                    String midletClassName) {
298:
299:                assertEquals(SUITE_ID, midletSuiteId);
300:                assertEquals(CLASS_NAME, midletClassName);
301:            }
302:
303:            /**
304:             * Process a MIDlet paused notification.
305:             * MIDletControllerEventConsumer I/F method.
306:             *
307:             * TBD: param midletProxy proxy with information about MIDlet
308:             *
309:             * @param midletSuiteId ID of the MIDlet suite
310:             * @param midletClassName Class name of the MIDlet
311:             */
312:            public void handleMIDletPauseNotifyEvent(int midletSuiteId,
313:                    String midletClassName) {
314:
315:                assertEquals(SUITE_ID, midletSuiteId);
316:                assertEquals(CLASS_NAME, midletClassName);
317:            }
318:
319:            /**
320:             * Process a MIDlet destroyed event.
321:             * MIDletControllerEventConsumer I/F method.
322:             *
323:             * @param midletSuiteId ID of the MIDlet suite
324:             * @param midletClassName Class name of the MIDlet
325:             */
326:            public void handleMIDletDestroyNotifyEvent(int midletSuiteId,
327:                    String midletClassName) {
328:
329:                assertEquals(SUITE_ID, midletSuiteId);
330:                assertEquals(CLASS_NAME, midletClassName);
331:            }
332:
333:            /**
334:             * Processes a MIDLET_RESUME_REQUEST event.
335:             *
336:             * MIDletControllerEventConsumer I/F method.
337:             *
338:             * @param midletSuiteId ID of the MIDlet suite
339:             * @param midletClassName Class name of the MIDlet
340:             */
341:            public void handleMIDletResumeRequestEvent(int midletSuiteId,
342:                    String midletClassName) {
343:
344:                assertEquals(SUITE_ID, midletSuiteId);
345:                assertEquals(CLASS_NAME, midletClassName);
346:            }
347:
348:            /**
349:             * Handles notification event of MIDlet resources pause.
350:             * MIDletControllerEventConsumer I/F method.
351:             *
352:             * @param midletSuiteId ID of the MIDlet suite
353:             * @param midletClassName Class name of the MIDlet
354:             */
355:            public void handleMIDletRsPauseNotifyEvent(int midletSuiteId,
356:                    String midletClassName) {
357:
358:                assertEquals(SUITE_ID, midletSuiteId);
359:                assertEquals(CLASS_NAME, midletClassName);
360:            }
361:
362:            /**
363:             * Process a MIDlet destroy request event.
364:             * MIDletControllerEventConsumer I/F method.
365:             *
366:             * @param midletIsolateId isolate ID of the sending Display
367:             * @param midletDisplayId ID of the sending Display
368:             */
369:            public void handleMIDletDestroyRequestEvent(int midletIsolateId,
370:                    int midletDisplayId) {
371:
372:                assertEquals(currentIsolateId, midletIsolateId);
373:                assertEquals(displayId, midletDisplayId);
374:            }
375:
376:            /**
377:             * Process an ACTIVATE_ALL_EVENT.
378:             * MIDletControllerEventConsumer I/F method.
379:             *
380:             */
381:            public void handleActivateAllEvent() {
382:                assertTrue(true);
383:            }
384:
385:            /**
386:             * Process a PAUSE_ALL_EVENT.
387:             * MIDletControllerEventConsumer I/F method.
388:             */
389:            public void handlePauseAllEvent() {
390:                assertTrue(true);
391:            }
392:
393:            /**
394:             * Process a SHUTDOWN_ALL_EVENT.
395:             * MIDletControllerEventConsumer I/F method.
396:             *
397:             * It simply calls "shutdown()". In future it shall be merged with
398:             * "shutdown()" and substitute it.
399:             */
400:            public void handleDestroyAllEvent() {
401:                assertTrue(true);
402:            }
403:
404:            /**
405:             * Processes FATAL_ERROR_NOTIFICATION.
406:             *
407:             * MIDletControllerEventConsumer I/F method.
408:             *
409:             * @param midletIsolateId isolate ID of the sending isolate
410:             * @param midletDisplayId ID of the sending Display
411:             */
412:            public void handleFatalErrorNotifyEvent(int midletIsolateId,
413:                    int midletDisplayId) {
414:
415:                assertEquals(currentIsolateId, midletIsolateId);
416:                assertEquals(displayId, midletDisplayId);
417:            }
418:
419:            /**
420:             * Process a Display created notification.
421:             * MIDletControllerEventConsumer I/F method.
422:             *
423:             * @param midletIsolateId isolate ID of the sending Display
424:             * @param midletDisplayId ID of the sending Display
425:             * @param midletClassName Class name of the MIDlet that owns the display
426:             */
427:            public void handleDisplayCreateNotifyEvent(int midletIsolateId,
428:                    int midletDisplayId, String midletClassName) {
429:
430:                assertEquals(currentIsolateId, midletIsolateId);
431:                assertEquals(displayId, midletDisplayId);
432:                assertEquals(CLASS_NAME, midletClassName);
433:            }
434:
435:            /**
436:             * Process a foreground request event.
437:             * MIDletControllerEventConsumer I/F method.
438:             *
439:             * @param midletIsolateId isolate ID of the sending Display
440:             * @param midletDisplayId ID of the sending Display
441:             * @param isAlert true if the current displayable is an Alert
442:             */
443:            public void handleDisplayForegroundRequestEvent(
444:                    int midletIsolateId, int midletDisplayId, boolean isAlert) {
445:
446:                assertEquals(currentIsolateId, midletIsolateId);
447:                assertEquals(displayId, midletDisplayId);
448:                assertTrue(isAlert);
449:            }
450:
451:            /**
452:             * Process a background request event.
453:             * MIDletControllerEventConsumer I/F method.
454:             *
455:             *
456:             * @param midletIsolateId isolate ID of the sending Display
457:             * @param midletDisplayId ID of the sending Display
458:             */
459:            public void handleDisplayBackgroundRequestEvent(
460:                    int midletIsolateId, int midletDisplayId) {
461:
462:                assertEquals(currentIsolateId, midletIsolateId);
463:                assertEquals(displayId, midletDisplayId);
464:            }
465:
466:            /**
467:             * Process a "display preempt start" event.
468:             * <p>
469:             * Set the foreground to a given display if a certain display
470:             * has the foreground. Used to start preempting.
471:             *
472:             * MIDletControllerEventConsumer I/F method.
473:             *
474:             * @param midletIsolateId isolate ID of the sending Display
475:             * @param midletDisplayId ID of the sending Display
476:             */
477:            public void handleDisplayPreemptStartEvent(int midletIsolateId,
478:                    int midletDisplayId) {
479:
480:                assertEquals(currentIsolateId, midletIsolateId);
481:                assertEquals(displayId, midletDisplayId);
482:            }
483:
484:            /**
485:             * Process a "display preempt stop" event.
486:             * <p>
487:             * Set the foreground to a given display if a certain display
488:             * has the foreground. Used to end preempting.
489:             *
490:             * MIDletControllerEventConsumer I/F method.
491:             *
492:             * @param midletIsolateId isolate ID of the sending Display
493:             * @param midletDisplayId ID of the sending Display
494:             */
495:            public void handleDisplayPreemptStopEvent(int midletIsolateId,
496:                    int midletDisplayId) {
497:
498:                assertEquals(currentIsolateId, midletIsolateId);
499:                assertEquals(displayId2, midletDisplayId);
500:            }
501:
502:            /**
503:             * Process a select foreground event by putting the foreground selector
504:             * MIDlet in the foreground.
505:             *
506:             * MIDletControllerEventConsumer I/F method.
507:             *
508:             */
509:            public void handleMIDletForegroundSelectEvent(int onlyFromLaunched) {
510:            }
511:
512:            /**
513:             * Process an event to transition the foreground from a current display
514:             * to a target MIDlet by ID and classname. If the source display
515:             * does not currently own the foreground the request is ignored.
516:             * If the target MIDlet is found in the active list then it it set
517:             * as the foreground. If not found, then it should be added as
518:             * the next display to get the foreground (when it asks).
519:             *
520:             * MIDletControllerEventConsumer I/F method.
521:             *
522:             * @param originMIDletSuiteId ID of MIDlet from which
523:             *        to take forefround ownership away,
524:             * @param originMIDletClassName Name of MIDlet from which
525:             *        to take forefround ownership away
526:             * @param targetMIDletSuiteId ID of MIDlet
527:             *        to give forefround ownership to,
528:             * @param targetMIDletClassName Name of MIDlet
529:             *        to give forefround ownership to
530:             */
531:            public void handleMIDletForegroundTransferEvent(
532:                    int originMIDletSuiteId, String originMIDletClassName,
533:                    int targetMIDletSuiteId, String targetMIDletClassName) {
534:
535:                assertEquals(SUITE_ID, originMIDletSuiteId);
536:                assertEquals(CLASS_NAME, originMIDletClassName);
537:
538:                assertEquals(TARGET_SUITE_ID, targetMIDletSuiteId);
539:                assertEquals(TARGET_CLASS_NAME, targetMIDletClassName);
540:            }
541:
542:            /**
543:             * Processes SET_FOREGROUND_BY_NAME_REQUEST event.
544:             * <p>
545:             * Set specified MIDlet to foreground.
546:             *
547:             * @param midletSuiteId MIDlet's suite ID
548:             * @param midletClassName MIDlet's class name
549:             */
550:            public void handleSetForegroundByNameRequestEvent(
551:                    int midletSuiteId, String midletClassName) {
552:
553:                assertEquals(SUITE_ID, midletSuiteId);
554:                assertEquals(CLASS_NAME, midletClassName);
555:            }
556:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.