KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > CorrectJVMTestBase


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.test;
5
6 import java.util.regex.Matcher JavaDoc;
7 import java.util.regex.Pattern JavaDoc;
8
9 /**
10  * Checks that the VM that the buildsystem thinks it's running the tests with is the VM that it's *actually* running the
11  * tests with.
12  */

13 public class CorrectJVMTestBase extends TCTestCase {
14
15   private static final Pattern JavaDoc VERSION_PATTERN = Pattern.compile("(\\d+\\.\\d+\\.\\d+(_\\d+)?)(-\\S+)?");
16
17   public void testVersion() throws Exception JavaDoc {
18     String JavaDoc actualVersion = System.getProperty("java.runtime.version");
19     String JavaDoc expectedVersion = TestConfigObject.getInstance().jvmVersion();
20
21     Matcher JavaDoc matcher = VERSION_PATTERN.matcher(actualVersion);
22
23     System.err.println("Actual JVM version: '" + actualVersion + "'; expected JVM version: '" + expectedVersion + "'");
24
25     assertTrue("Actual version of '" + actualVersion + "' matches pattern", matcher.matches());
26     assertEquals(expectedVersion, matcher.group(1));
27   }
28
29   public void testType() throws Exception JavaDoc {
30     String JavaDoc vmName = System.getProperty("java.vm.name").toLowerCase();
31     String JavaDoc expectedType = TestConfigObject.getInstance().jvmType().trim().toLowerCase();
32
33     System.err.println("Actual JVM type: '" + vmName + "'; expected JVM type: '" + expectedType + "'");
34
35     assertTrue("Actual type of '" + vmName + "' includes expected type of '" + expectedType + "'", vmName
36         .indexOf(expectedType) >= 0);
37   }
38
39 }
40
Popular Tags