Source Code Cross Referenced for BootJarTest.java in  » Net » Terracotta » com » tc » object » tools » 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 » Net » Terracotta » com.tc.object.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.object.tools;
006:
007:        import com.tc.object.BaseDSOTestCase;
008:        import com.tc.object.Portability;
009:        import com.tc.object.PortabilityImpl;
010:        import com.tc.object.config.DSOClientConfigHelper;
011:        import com.tc.object.config.TransparencyClassSpec;
012:        import com.tc.object.config.TransparencyClassSpecImpl;
013:        import com.tc.util.Assert;
014:        import com.tc.util.TCAssertionError;
015:
016:        import java.io.File;
017:        import java.util.HashSet;
018:        import java.util.Iterator;
019:        import java.util.Set;
020:
021:        public class BootJarTest extends BaseDSOTestCase {
022:
023:            private final static String STRING_CLASS = "java.lang.String";
024:            private final ClassBytesProvider bytesProvider = new ClassLoaderBytesProvider(
025:                    getClass().getClassLoader());
026:
027:            public BootJarTest() {
028:                // 
029:            }
030:
031:            public void testInvalidBootJarVersion() throws Exception {
032:                File jarFile = this .getTempFile("dso-boot.jar");
033:                BootJar bootJar = BootJar.getBootJarForWriting(jarFile,
034:                        "bogus_jvm_signature_666");
035:                bootJar.loadClassIntoJar(STRING_CLASS, bytesProvider
036:                        .getBytesForClass(STRING_CLASS), false);
037:                bootJar.close();
038:                try {
039:                    BootJar.getBootJarForReading(jarFile);
040:                    fail("The test was expecting an InvalidJVMVersionException, but it was not thrown.");
041:                } catch (InvalidJVMVersionException e) {
042:                    // we expect this to happen since the vm signature won't
043:                    // match the running VM signature)
044:                }
045:            }
046:
047:            public void testFindBootJar() throws Exception {
048:                // use absolute file to make sure the path is fully qualified on windows
049:                // (ie. has drive letter)
050:                File bootJar = new File("/path/to/dso-boot/dso-boot.jar")
051:                        .getAbsoluteFile();
052:
053:                String origBootClassPath = System
054:                        .getProperty("sun.boot.class.path");
055:
056:                System.setProperty("sun.boot.class.path", bootJar
057:                        .getAbsolutePath()
058:                        + System.getProperty("path.separator")
059:                        + origBootClassPath);
060:
061:                assertEquals(bootJar, BootJar.findBootJar());
062:
063:                System.setProperty("sun.boot.class.path", origBootClassPath);
064:
065:                bootJar = new File(
066:                        "/path/to/dso-boot/dso-boot-hotspot_win32_150.jar")
067:                        .getAbsoluteFile();
068:
069:                System.setProperty("sun.boot.class.path", bootJar
070:                        .getAbsolutePath()
071:                        + System.getProperty("path.separator")
072:                        + origBootClassPath);
073:
074:                assertEquals(bootJar, BootJar.findBootJar());
075:
076:                System.setProperty("sun.boot.class.path", origBootClassPath);
077:            }
078:
079:            public void testAllSuperClassesPresentInBootJar() throws Exception {
080:                Portability portability = new PortabilityImpl(this 
081:                        .configHelper());
082:                BootJar bootJar = BootJar.getDefaultBootJarForReading();
083:                if (bootJar == null) {
084:                    throw new TCAssertionError("Boot Jar Not Found !");
085:                }
086:                Set allClasses = bootJar.getAllPreInstrumentedClasses();
087:                Set missingClasses = new HashSet();
088:                for (Iterator iter = allClasses.iterator(); iter.hasNext();) {
089:                    String classname = (String) iter.next();
090:                    Class clazz = Class.forName(classname);
091:                    while (clazz != null && clazz != Object.class) {
092:                        clazz = clazz.getSuperclass();
093:                        if (!portability.isInstrumentationNotNeeded(clazz
094:                                .getName())
095:                                && !allClasses.contains(clazz.getName())) {
096:                            System.err
097:                                    .println(" Class "
098:                                            + classname
099:                                            + " is in the bootjar, but its super class "
100:                                            + clazz.getName()
101:                                            + " not in the bootjar !");
102:                            missingClasses.add(clazz.getName());
103:                        }
104:                    }
105:                }
106:                if (!missingClasses.isEmpty()) {
107:                    System.err
108:                            .println("\n\nThe Following classes should go into bootjar !");
109:                    printClasses(missingClasses);
110:                }
111:                Assert.assertTrue(missingClasses.isEmpty());
112:            }
113:
114:            private void printClasses(Set classes) {
115:                for (Iterator iter = classes.iterator(); iter.hasNext();) {
116:                    String className = (String) iter.next();
117:                    System.err.println(" " + className);
118:                }
119:            }
120:
121:            protected boolean cleanTempDir() {
122:                return false;
123:            }
124:
125:            public void tests() throws Exception {
126:                String vmSig = "vm signature";
127:                DSOClientConfigHelper config = configHelper();
128:
129:                File jar = getTempFile("dso-boot.jar");
130:
131:                BootJar bootJar = BootJar.getBootJarForWriting(jar, vmSig);
132:
133:                // load a regular class into the jar.
134:                bootJar.loadClassIntoJar(STRING_CLASS, bytesProvider
135:                        .getBytesForClass(STRING_CLASS), false);
136:                // load an "instrumented" class into the jar.
137:                String classname = Boolean.class.getName();
138:                TransparencyClassSpec spec = new TransparencyClassSpecImpl(
139:                        classname, config);
140:                spec.markPreInstrumented();
141:                byte[] classBytes = bytesProvider.getBytesForClass(classname);
142:                assertNotNull(classBytes);
143:                bootJar.loadClassIntoJar(spec.getClassName(), classBytes, spec
144:                        .isPreInstrumented());
145:                bootJar.close();
146:
147:                bootJar = BootJar.getBootJarForReading(jar,
148:                        new BootJarSignature(vmSig));
149:
150:                Set allPreInstrumentedClasses = bootJar
151:                        .getAllPreInstrumentedClasses();
152:                assertEquals(1, allPreInstrumentedClasses.size());
153:                assertTrue(allPreInstrumentedClasses.contains(classname));
154:                assertFalse(allPreInstrumentedClasses
155:                        .contains(java.lang.String.class.getName()));
156:
157:                bootJar.close();
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.