Source Code Cross Referenced for InterpreterJVMTest.java in  » IDE » DrJava » edu » rice » cs » drjava » model » repl » newjvm » 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 » IDE » DrJava » edu.rice.cs.drjava.model.repl.newjvm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*BEGIN_COPYRIGHT_BLOCK
002:         *
003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are met:
008:         *    * Redistributions of source code must retain the above copyright
009:         *      notice, this list of conditions and the following disclaimer.
010:         *    * Redistributions in binary form must reproduce the above copyright
011:         *      notice, this list of conditions and the following disclaimer in the
012:         *      documentation and/or other materials provided with the distribution.
013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014:         *      names of its contributors may be used to endorse or promote products
015:         *      derived from this software without specific prior written permission.
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         *
029:         * This software is Open Source Initiative approved Open Source Software.
030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
031:         * 
032:         * This file is part of DrJava.  Download the current version of this project
033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034:         * 
035:         * END_COPYRIGHT_BLOCK*/
036:
037:        package edu.rice.cs.drjava.model.repl.newjvm;
038:
039:        import edu.rice.cs.drjava.DrJavaTestCase;
040:        import edu.rice.cs.drjava.model.repl.DynamicJavaAdapter;
041:        import edu.rice.cs.drjava.model.repl.ExceptionReturnedException;
042:        import edu.rice.cs.drjava.model.repl.JavaInterpreter;
043:
044:        import java.util.Hashtable;
045:
046:        /**
047:         * simple test suite over InterpreterJVM
048:         */
049:        public final class InterpreterJVMTest extends DrJavaTestCase {
050:            private InterpreterJVM jvm = InterpreterJVM.ONLY;
051:            private Hashtable<String, InterpreterData> _debugInterpreters;
052:            private JavaInterpreter _interpreter1;
053:            private JavaInterpreter _interpreter2;
054:            private JavaInterpreter _interpreter3;
055:
056:            private void _addInterpreter(String name,
057:                    JavaInterpreter interpreter) {
058:                InterpreterJVM.ONLY.addInterpreter(name, interpreter);
059:            }
060:
061:            public void setUp() throws Exception {
062:                super .setUp();
063:                _debugInterpreters = InterpreterJVM.ONLY.getInterpreters();
064:                _interpreter1 = new DynamicJavaAdapter(new ClassPathManager());
065:                _interpreter2 = new DynamicJavaAdapter(new ClassPathManager());
066:                _interpreter3 = new DynamicJavaAdapter(new ClassPathManager());
067:            }
068:
069:            /**
070:             * ensures that our InterpreterJVM adds named debug interpreters correctly
071:             */
072:            public void testAddNamedDebugInterpreter() {
073:                assertTrue(_debugInterpreters.isEmpty());
074:                _addInterpreter("interpreter1", _interpreter1);
075:                assertSame(_interpreter1, _debugInterpreters
076:                        .get("interpreter1").getInterpreter());
077:                assertTrue(!_debugInterpreters.containsKey("interpreter2"));
078:
079:                _addInterpreter("interpreter2", _interpreter2);
080:                assertSame(_interpreter1, _debugInterpreters
081:                        .get("interpreter1").getInterpreter());
082:                assertSame(_interpreter2, _debugInterpreters
083:                        .get("interpreter2").getInterpreter());
084:
085:                try {
086:                    _addInterpreter("interpreter1", _interpreter3);
087:                    fail();
088:                } catch (IllegalArgumentException ex) {
089:                    assertSame(_interpreter1, _debugInterpreters.get(
090:                            "interpreter1").getInterpreter());
091:                    assertSame(_interpreter2, _debugInterpreters.get(
092:                            "interpreter2").getInterpreter());
093:                }
094:            }
095:
096:            /**
097:             * verifies that the InterpreterJVM can switch between active interpreters.
098:             */
099:            public void testSwitchingActiveInterpreter()
100:                    throws ExceptionReturnedException {
101:                String var0 = "stuff";
102:                String var1 = "junk";
103:                String var2 = "raargh";
104:                Object val0 = new Byte("5");
105:                Object val1 = new Short("2");
106:                Object val2 = new Long(2782);
107:                _addInterpreter("1", _interpreter1);
108:                _addInterpreter("2", _interpreter2);
109:
110:                JavaInterpreter interpreter = (JavaInterpreter) jvm
111:                        .getActiveInterpreter();
112:                interpreter.defineVariable(var0, val0);
113:                assertEquals(val0, interpreter.interpret(var0));
114:
115:                jvm.setActiveInterpreter("1");
116:                interpreter = (JavaInterpreter) jvm.getActiveInterpreter();
117:                try {
118:                    interpreter.interpret(var0);
119:                    fail();
120:                } catch (ExceptionReturnedException ex) {
121:                    // correct behavior -- var0 should not be defined
122:                }
123:                interpreter.defineVariable(var1, val1);
124:                assertEquals(val1, interpreter.interpret(var1));
125:
126:                jvm.setActiveInterpreter("2");
127:                interpreter = (JavaInterpreter) jvm.getActiveInterpreter();
128:                try {
129:                    interpreter.interpret(var0);
130:                    fail();
131:                } catch (ExceptionReturnedException ex) {
132:                }
133:                try {
134:                    interpreter.interpret(var1);
135:                    fail();
136:                } catch (ExceptionReturnedException ex) {
137:                    // correct behavior -- var0 & var1 should not be defined
138:                }
139:                interpreter.defineVariable(var2, val2);
140:                assertEquals(val2, interpreter.interpret(var2));
141:
142:                jvm.setToDefaultInterpreter();
143:                interpreter = (JavaInterpreter) jvm.getActiveInterpreter();
144:                try {
145:                    interpreter.interpret(var1);
146:                    fail();
147:                } catch (ExceptionReturnedException ex) {
148:                }
149:                try {
150:                    interpreter.interpret(var2);
151:                    fail();
152:                } catch (ExceptionReturnedException ex) {
153:                    // correct behavior -- var1 & var2 should not be defined
154:                }
155:                assertEquals(val0, jvm.getActiveInterpreter().interpret(var0));
156:
157:                jvm.setActiveInterpreter("1");
158:                interpreter = (JavaInterpreter) jvm.getActiveInterpreter();
159:                try {
160:                    interpreter.interpret(var0);
161:                    fail();
162:                } catch (ExceptionReturnedException ex) {
163:                }
164:                try {
165:                    interpreter.interpret(var2);
166:                    fail();
167:                } catch (ExceptionReturnedException ex) {
168:                    // correct behavior -- var1 & var2 should not be defined
169:                }
170:                assertEquals(val1, interpreter.interpret(var1));
171:
172:                try {
173:                    jvm.setActiveInterpreter("not an interpreter");
174:                    fail();
175:                } catch (IllegalArgumentException ex) {
176:                    assertEquals(
177:                            "Interpreter 'not an interpreter' does not exist.",
178:                            ex.getMessage());
179:                }
180:            }
181:        }
w___w___w_.j___a___v__a___2_s___.c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.