[embjopr-commits] EMBJOPR SVN: r847 - in trunk/jsfunit: src/test/java/org/jboss/jopr/jsfunit and 1 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Sat Nov 7 00:38:06 EST 2009


Author: ozizka at redhat.com
Date: 2009-11-07 00:38:06 -0500 (Sat, 07 Nov 2009)
New Revision: 847

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/Labels.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java
Modified:
   trunk/jsfunit/pom.xml
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java
Log:
 * Server edition and version, and Jopr version used to adjust strings and testuite behavior dynamicaly. (JBQA-2770, JBQA-2774)
 * But still using the constants - first we have to tune up the metadata.


Modified: trunk/jsfunit/pom.xml
===================================================================
--- trunk/jsfunit/pom.xml	2009-11-07 05:35:43 UTC (rev 846)
+++ trunk/jsfunit/pom.xml	2009-11-07 05:38:06 UTC (rev 847)
@@ -8,7 +8,6 @@
       <!-- Does not work in Maven 2.2.1 -->
       <mavenConflictResolvers>newest,nearest</mavenConflictResolvers>
 
-      <jopr.version>1.2.0-SNAPSHOT</jopr.version>
       <cargo.plugin.version>1.0.1-SNAPSHOT</cargo.plugin.version>
       <jvm.args.debug></jvm.args.debug> <!-- Used by the -Pdebug profile. -->
       <jvm.args.profiler></jvm.args.profiler> <!-- Used by the -Pprofile profile. -->
@@ -111,6 +110,14 @@
         <scope>compile</scope>
         <version>1.7R2</version>
       </dependency>
+
+      <!-- For version comparison -->
+      <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-artifact</artifactId>
+        <version>2.2.1</version>
+        <scope>compile</scope>
+      </dependency>
       
       <dependency>
          <groupId>org.jboss.jsfunit</groupId>
@@ -247,6 +254,7 @@
                            <jboss.bind.address>${cargo.jboss.bind.address}</jboss.bind.address>
                            <jsfunit.jboss.home.dir>${basedir}/target/jboss42x</jsfunit.jboss.home.dir>
                            <htmlunit.browser>${htmlunit.browser}</htmlunit.browser>
+                           <jopr.version>${jopr.version}</jopr.version>
                         </systemProperties>
                      </container>
 
@@ -466,6 +474,7 @@
                            <htmlunit.browser>${htmlunit.browser}</htmlunit.browser>
                            <jsfunit.jboss.isSecured>${jboss.isSecured}</jsfunit.jboss.isSecured>
                            <jboss.platform.mbeanserver>true</jboss.platform.mbeanserver> <!-- Makes the JVM resource appear. -->
+                           <jopr.version>${jopr.version}</jopr.version>
                         </systemProperties>
                      </container>
 
@@ -821,12 +830,18 @@
    <build>
       <finalName>admin-console-jsfunit</finalName>
 
+      <!-- Intentionally set to the same dir:
+        We need the classes as sources to include them in the WAR.
+        We need them as tests to let the Surefire plugin run them. -->
       <sourceDirectory>src/test/java</sourceDirectory>
       <testSourceDirectory>src/test/java</testSourceDirectory>
 
       <!-- To add the dir to IDEs nav tree. -->
       <resources>
         <resource>
+          <directory>${basedir}/src/main/resources</directory>
+        </resource>
+        <resource>
           <directory>${basedir}/testdata</directory>
           <excludes><exclude>**/*</exclude></excludes>
         </resource>

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java	2009-11-07 05:38:06 UTC (rev 847)
@@ -0,0 +1,50 @@
+
+package org.jboss.jopr.jsfunit;
+
+import org.apache.cactus.ServletTestCase;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.EjtsEnvironmentInfo;
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * @author ondra
+ */
+public class EjtsSelfTest extends ServletTestCase {
+
+	private static final Logger log = Logger.getLogger( EjtsSelfTest.class.getName() );
+
+	/** */
+	public void testEnvironmentInfo() throws EmbJoprTestException, Exception {
+		EjtsEnvironmentInfo eei = EjtsEnvironmentInfo.createFromLocalServer();
+		log.info( eei.toString() );
+
+		doCompareVersions("2.3.0.GA", "2.4.0-SNAPSHOT", -1);
+		doCompareVersions("2.4.0.GA", "2.4.0-SNAPSHOT", 1);
+		doCompareVersions("2.4.1.GA", "2.4.0-SNAPSHOT", 1);
+		doCompareVersions("2.4.1", "2.4.0-SNAPSHOT", 1);
+		doCompareVersions("2.4.0", "2.4.0-SNAPSHOT", 1);
+		doCompareVersions("2.4.0", "2.4.0.GA", 0);
+		doCompareVersions("2.4.0.CR1", "2.4.0.GA", -1);
+		doCompareVersions("2.4.CR1", "2.4.0.GA", -1);
+		doCompareVersions("2.4.CR1", "2.4.0", -1);
+	}
+
+		private void doCompareVersions( String v1, String v2, int expectedSignum ){
+		log.info( String.format("Comparing versions:  %s  and  %s  produces:  %d", v1, v2, EjtsEnvironmentInfo.compareVersions(v1, v2) ) );
+	}
+
+
+
+	/** */
+	public void testLabels() throws EmbJoprTestException, Exception {
+		Labels labels = Labels.createDefault();
+		log.info( labels.toString() );
+	}
+
+
+}// class
+
+
+
+

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java	2009-11-07 05:35:43 UTC (rev 846)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbJoprTestConstants.java	2009-11-07 05:38:06 UTC (rev 847)
@@ -1,13 +1,10 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
 
 package org.jboss.jopr.jsfunit;
 
 /**
- *
- * @author Ondrej Zizka
+ *  TODO: Values copied to .properties files yet, (JBQA-2770, JBQA-2774), but still using this file.
+ * 
+ *  @author Ondrej Zizka
  */
 public interface EmbJoprTestConstants {
 

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/Labels.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/Labels.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/Labels.java	2009-11-07 05:38:06 UTC (rev 847)
@@ -0,0 +1,136 @@
+package org.jboss.jopr.jsfunit;
+
+import java.io.*;
+import java.net.URL;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.jboss.jopr.jsfunit.util.EjtsEnvironmentInfo;
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * @author Ondrej Zizka
+ */
+public class Labels
+{
+	
+	private static final Logger log = Logger.getLogger( Labels.class.getName() );
+
+
+	Properties props; // = new Properties();
+
+	private Labels(){}
+
+
+	/**
+	 * Returns a properties object with labels for the current environment:
+	 * Server edition and version, Jopr version.
+	 */
+	public static Labels createDefault() throws Exception
+	{
+
+		Labels ret = new Labels();
+
+		// Common
+		ret.props = loadProperties("labels--common.properties");
+
+		EjtsEnvironmentInfo si = EjtsEnvironmentInfo.getInstance();
+		//String joprVersion = JBossASDiscoveryComponent.class.getPackage().getVersion();
+		String curJoprVersion = System.getProperty("jopr.version");
+
+
+
+		// EAP / AS
+		String serverEdition = si.isEAP() ? "eap" : "as";
+
+		String editionPropsFile = "labels-"+serverEdition+".properties";
+		ret.mergeProperties( loadProperties( editionPropsFile ) ) ;
+
+		// Incrementally apply version updates.
+
+		// EAP / AS version.
+		for( String buildNumber : StringUtils.split("") ){ // TODO: Load dynamically.
+			if( NumberUtils.toLong(buildNumber)  >  NumberUtils.toLong(si.getBuildNumber()) )
+				break;
+			String buildPropsFile = "labels-"+serverEdition+"-"+buildNumber+".properties";
+			ret.mergeProperties( loadProperties( buildPropsFile ) ) ;
+		}
+
+		// JOPR
+		for( String joprVersion : StringUtils.split("2.3.0.GA") ){ // TODO: Load dynamically.
+			if( EjtsEnvironmentInfo.compareVersions(joprVersion, curJoprVersion)  >  0 )
+				break;
+			String buildPropsFile = "labels-jopr-"+joprVersion+".properties";
+			ret.mergeProperties( loadProperties( buildPropsFile ) ) ;
+		}
+
+		return ret;
+
+	}
+
+
+
+	/** Merge properties - rewrite old ones with the new ones. */
+	public void mergeProperties( Properties props ){
+		for( Entry e : props.entrySet() ){
+			this.props.setProperty( (String)e.getKey(), (String)e.getValue() );
+		}
+	}
+
+
+	/** Loads properties. */
+	public static Properties loadProperties(String name) throws IOException {
+		try {
+			InputStream in = getInputStream(name);
+			Properties props = new Properties();
+			props.load(in);
+			in.close();
+			return props;
+		} catch (IOException ex) {
+			throw ex;
+		}
+	}
+
+	/** Open input stream for given classpath resource. */
+	protected static InputStream getInputStream( String path ) throws IOException
+	{
+		//ClassLoader loader = ClassLoader.getSystemClassLoader();
+		ClassLoader loader = Labels.class.getClassLoader();
+		if (loader == null)
+			return null;
+
+		URL url = loader.getResource(path);
+		if (url == null)
+			url = loader.getResource("/" + path);
+		if (url == null)
+			throw new IOException("Not found on classpath: "+path);
+
+		try {
+			InputStream in = url.openStream();
+			return in;
+		} catch (IOException ex) {
+			throw ex;
+		}
+	}
+
+
+
+
+	/** toString() */
+	public String toString(){
+		StringBuilder sb = new StringBuilder();
+		Set<Entry<Object, Object>> entrySet = this.props.entrySet();
+		for( Entry<Object, Object> entry : entrySet ){
+			sb.append("  ").append(entry.getKey()).append(" = ").append(entry.getValue()).append("\n");
+		}
+		return sb.toString();
+	}
+
+
+}// class
+
+

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java	2009-11-07 05:38:06 UTC (rev 847)
@@ -0,0 +1,112 @@
+/*
+
+VersionNumber 	5.0.0.GA
+VersionName 	EAP
+BuildDate 	20091020
+BuildNumber 	200910202128
+
+Started 	True
+BuildOS 	Linux(amd64,2.6.18-164.2.1.el5)
+BuildID 	200910202128
+InShutdown 	False
+StartDate 	Wed, 4 Nov 2009 16:00:16 +0100
+BuildJVM 	14.1-b02(Sun Microsystems Inc.)
+MetaData 	{}
+Version 	5.0.0.GA (build: SVNTag=JBPAPP_5_0_0_GA date=200910202128)
+
+*/
+
+
+package org.jboss.jopr.jsfunit.util;
+
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.jboss.jopr.jsfunit.JMXUtils;
+
+/**
+ *
+ * @author Ondrej Zizka
+ */
+public class EjtsEnvironmentInfo
+{
+
+	private static EjtsEnvironmentInfo INSTANCE;
+	public static EjtsEnvironmentInfo getInstance() throws Exception {
+		if( null == INSTANCE )
+			INSTANCE = createFromLocalServer();
+		return INSTANCE;
+	}
+
+
+	private String versionName;
+	private String versionNumber;
+	private String buildNumber;
+	private String joprVersion;
+
+	public String getBuildNumber() {		return buildNumber;	}
+	public String getVersionName() {		return versionName;	}
+	public String getVersionNumber() {		return versionNumber;	}
+	public String getJoprVersion() {		return joprVersion;	}
+	
+	public boolean isEAP(){ return "EAP".equals( this.versionName ); }
+
+	public String toString(){
+		return String.format("EJTS environment info:\n   versionName: %s\n   versionNumber: %s\n   buildNumber: %s\n   Jopr Version: %s",
+						versionName, versionNumber, buildNumber, joprVersion
+		);
+	}
+	
+
+
+
+	/**
+	 * Creates an instance from local running JBoss AS.
+	 */
+	public static EjtsEnvironmentInfo createFromLocalServer() throws Exception
+	{
+		EjtsEnvironmentInfo envInfo = new EjtsEnvironmentInfo();
+		try {
+			JMXUtils jmx = JMXUtils.getInstanceForLocalJBoss();
+			envInfo.versionName = (String) jmx.getMBeanAttribute("jboss.system:type=Server", "VersionName");
+			envInfo.versionNumber = (String) jmx.getMBeanAttribute("jboss.system:type=Server", "VersionNumber");
+			envInfo.buildNumber = (String) jmx.getMBeanAttribute("jboss.system:type=Server", "BuildNumber");
+		}catch ( Exception ex ){
+			throw new Exception("Error getting server info via JMX: "+ex.getMessage(), ex);
+		}
+
+		envInfo.joprVersion = System.getProperty("jopr.version");
+
+		return envInfo;
+	}
+
+
+
+	/**
+	 * Compares two version strings, like compareTo() does.
+	 * TODO: Maven comparison algorithm works bad; Code own one.
+	 */
+	public static int compareVersions(String v1s, String v2s){
+
+		/*
+		int v1n = 0;
+		int v2n = 0;
+
+		String[] v1parts = StringUtils.split(v1, ".-");
+		String[] v2parts = StringUtils.split(v2, ".-");
+
+		int longer =
+
+		for( int i = v1parts.length-1; i >= 0; i--){
+		}
+
+		throw new UnsupportedOperationException();
+		*/
+
+		// Maven's algorithm.
+		DefaultArtifactVersion v1 = new DefaultArtifactVersion(v1s);
+		DefaultArtifactVersion v2 = new DefaultArtifactVersion(v2s);
+		return v1.compareTo(v2);
+	}
+
+
+	
+}// class



More information about the embjopr-commits mailing list