001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.object.tools;
005:
006: import com.tc.test.TCTestCase;
007:
008: import java.util.Properties;
009:
010: public class BootJarSignatureTest extends TCTestCase {
011:
012: public void testExceptions() {
013: try {
014: new BootJarSignature(new Properties());
015: fail();
016: } catch (UnsupportedVMException uve) {
017: // expected
018: }
019:
020: try {
021: new BootJarSignature(makeProps(null, "Sun", "1.5.0_04",
022: null, "i686"));
023: fail();
024: } catch (UnsupportedVMException uve) {
025: // expected
026: }
027:
028: try {
029: new BootJarSignature(makeProps("Windows NT", null,
030: "1.5.0_04", null, "i686"));
031: fail();
032: } catch (UnsupportedVMException uve) {
033: // expected
034: }
035:
036: try {
037: new BootJarSignature(makeProps("Windows NT", "1.4.2_04",
038: null, null, "i686"));
039: fail();
040: } catch (UnsupportedVMException uve) {
041: // expected
042: }
043:
044: try {
045: new BootJarSignature(makeProps("Linux", "Sun", "1.5.0",
046: "unknown", null));
047: fail();
048: } catch (UnsupportedVMException uve) {
049: // expected
050: }
051: }
052:
053: public void testSolaris() throws UnsupportedVMException {
054: Properties props = makeProps("SunOS", "Sun Microsystems Inc.",
055: "1.5.0_06", null, "sparc");
056: BootJarSignature sig = new BootJarSignature(props);
057: assertEquals("hotspot_solaris_150_06", sig.getSignature());
058:
059: props = makeProps("SunOS", "Sun Microsystems Inc.", "1.4.2_12",
060: null, "x86");
061: sig = new BootJarSignature(props);
062: assertEquals("hotspot_solaris-x86_142_12", sig.getSignature());
063:
064: try {
065: props = makeProps("SunOS", "Sun Microsystems Inc.",
066: "1.5.0_06", null, null);
067: new BootJarSignature(props);
068: fail();
069: } catch (UnsupportedVMException uve) {
070: // expected (since os.arch was null)
071: }
072:
073: }
074:
075: public void testWindows() throws UnsupportedVMException {
076: Properties props = makeProps("Windows XP",
077: "Sun Microsystems Inc.", "1.5.0_06", null, null);
078: BootJarSignature sig = new BootJarSignature(props);
079: assertEquals("hotspot_win32_150_06", sig.getSignature());
080:
081: props = makeProps("Windows 2000", "Sun Microsystems Inc.",
082: "1.4.2_12", null, null);
083: sig = new BootJarSignature(props);
084: assertEquals("hotspot_win32_142_12", sig.getSignature());
085: }
086:
087: public void testMac() throws UnsupportedVMException {
088: Properties props = makeProps("Mac OS X",
089: "Apple Computer, Inc.", "1.5.0_05", null, null);
090: BootJarSignature sig = new BootJarSignature(props);
091: assertEquals("hotspot_osx_150_05", sig.getSignature());
092: }
093:
094: public void testLinux() throws UnsupportedVMException {
095: Properties props = makeProps("Linux", "Sun Microsystems, Inc.",
096: "1.5.0_01", null, null);
097: BootJarSignature sig = new BootJarSignature(props);
098: assertEquals("hotspot_linux_150_01", sig.getSignature());
099:
100: props = makeProps("Linux", "BEA Systems, Inc.", "1.5.0_03",
101: null, null);
102: sig = new BootJarSignature(props);
103: assertEquals("jrockit_linux_150_03", sig.getSignature());
104:
105: props = makeProps("Linux", "IBM Corporation", "1.5.0",
106: "pxi32dev-20070201 (SR4)", null);
107: sig = new BootJarSignature(props);
108: assertEquals("ibm_linux_150_sr4", sig.getSignature());
109:
110: // experimental version identifiers in case these should pop up one day
111: props = makeProps("Linux", "IBM Corporation, Inc.", "1.5.0_11",
112: "pxi32dev-20070201 (SR4)", null);
113: sig = new BootJarSignature(props);
114: assertEquals("ibm_linux_150_11sr4", sig.getSignature());
115:
116: // test this exceptional case
117: props = makeProps("Linux", "Sun Microsystems, Inc.",
118: "1.4.2_05", null, null);
119: props.setProperty("java.vm.name",
120: "BEA WebLogic JRockit(TM) 1.4.2_05 JVM R24.5.0-0");
121: props.setProperty("jrockit.version",
122: "ari-41062-20050215-0919-linux-ia32");
123: sig = new BootJarSignature(props);
124: assertEquals("jrockit_linux_142_05", sig.getSignature());
125: }
126:
127: private Properties makeProps(String os, String vendor,
128: String version, String runtime, String arch) {
129: Properties props = new Properties();
130: if (version != null)
131: props.put("java.version", version);
132: if (os != null)
133: props.put("os.name", os);
134: if (arch != null)
135: props.put("os.arch", arch);
136: if (runtime != null)
137: props.put("java.runtime.version", runtime);
138: if (vendor != null)
139: props.put("java.vendor", vendor);
140: return props;
141: }
142:
143: }
|