geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r393673 - in /geronimo/branches/1.1: etc/ modules/service-builder/src/schema/ plugins/geronimo-packaging-plugin/ plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/ plugins/geronimo-packaging-plugin/src/test-res...
Date Thu, 13 Apr 2006 00:47:55 GMT
Author: djencks
Date: Wed Apr 12 17:47:52 2006
New Revision: 393673

URL: http://svn.apache.org/viewcvs?rev=393673&view=rev
Log:
GERONIMO-1836 Make PlanProcessor work even if an existing environment element has the wrong
namespace, comment on the import element in environment, and bump the plugin version

Added:
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/plan.xml
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/result.xml
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/PlanProcessorTest.java
Modified:
    geronimo/branches/1.1/etc/project.properties
    geronimo/branches/1.1/modules/service-builder/src/schema/geronimo-config-1.1.xsd
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/project.xml
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PlanProcessor.java

Modified: geronimo/branches/1.1/etc/project.properties
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/etc/project.properties?rev=393673&r1=393672&r2=393673&view=diff
==============================================================================
--- geronimo/branches/1.1/etc/project.properties (original)
+++ geronimo/branches/1.1/etc/project.properties Wed Apr 12 17:47:52 2006
@@ -86,7 +86,7 @@
 tranql_vendors_version=1.1
 release_notes_version=1.0
 
-geronimo_packaging_plugin_version=1.1.0-3
+geronimo_packaging_plugin_version=1.1.0-4
 geronimo_assembly_plugin_version=1.1.0-9
 geronimo_deployment_plugin_version=1.1.0-1
 geronimo_dependency_plugin_version=1.1.0-1

Modified: geronimo/branches/1.1/modules/service-builder/src/schema/geronimo-config-1.1.xsd
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/service-builder/src/schema/geronimo-config-1.1.xsd?rev=393673&r1=393672&r2=393673&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/service-builder/src/schema/geronimo-config-1.1.xsd (original)
+++ geronimo/branches/1.1/modules/service-builder/src/schema/geronimo-config-1.1.xsd Wed Apr
12 17:47:52 2006
@@ -192,6 +192,19 @@
     </xs:complexType>
 
     <xs:simpleType name="importType">
+        <xs:annotation>
+            <xs:documentation><![CDATA[
+            The import element is restrictive.  The default (when omitted) is to include
the specified dependency in
+            the classloader (as a parent or URL) and (if the dependency is a configuration)
make sure it is started
+            before starting the current configuration.  Specifying "classes" means that the
classes must be included
+            in the current configurations classloader but the dependency does not need to
be started. (I'm not sure this
+            is actually possible, but it is what is meant).  Specifying "services" means
that the dependency (a configuration)
+            must be started before the current configuration, but it is not included as a
parent classloader.
+
+            You probably never need to use the import element.
+
+          ]]></xs:documentation>
+        </xs:annotation>
         <xs:restriction base="xs:string">
             <xs:enumeration value="classes"/>
             <xs:enumeration value="services"/>

Modified: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/project.xml?rev=393673&r1=393672&r2=393673&view=diff
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/project.xml (original)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/project.xml Wed Apr 12 17:47:52
2006
@@ -22,7 +22,7 @@
     <groupId>geronimo</groupId>
     <id>geronimo-packaging-plugin</id>
     <name>Geronimo :: Maven Packaging Plugin</name>
-    <currentVersion>1.1.0-3</currentVersion>
+    <currentVersion>1.1.0-4</currentVersion>
 
     <dependencies>
         <dependency>
@@ -173,6 +173,7 @@
 
     <build>
         <sourceDirectory>src/java</sourceDirectory>
+        <unitTestSourceDirectory>${basedir}/src/test</unitTestSourceDirectory>
 
         <resources>
             <resource>
@@ -185,6 +186,22 @@
                 </includes>
             </resource>
         </resources>
+        <unitTest>
+            <includes>
+                <include>**/*Test.java</include>
+            </includes>
+            <excludes>
+                <exclude>**/Abstract*.java</exclude>
+            </excludes>
+            <resources>
+                <resource>
+                    <directory>${basedir}/src/test-resources</directory>
+                    <includes>
+                        <include>**/*</include>
+                    </includes>
+                </resource>
+            </resources>
+        </unitTest>
     </build>
 </project>
 

Modified: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PlanProcessor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PlanProcessor.java?rev=393673&r1=393672&r2=393673&view=diff
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PlanProcessor.java
(original)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PlanProcessor.java
Wed Apr 12 17:47:52 2006
@@ -35,6 +35,7 @@
 import org.apache.xmlbeans.XmlOptions;
 
 import javax.xml.namespace.QName;
+
 import java.io.File;
 import java.io.StringWriter;
 import java.util.Iterator;
@@ -42,7 +43,7 @@
 import java.util.List;
 
 /**
- * @version $Rev: 384686 $ $Date$
+ * @version $Rev$ $Date$
  */
 public class PlanProcessor {
     private static Log log = LogFactory.getLog(PlanProcessor.class);
@@ -51,6 +52,7 @@
 //    private static final String INCLUDE_PROPERTY = "geronimo.include";
     private static final String DEPENDENCY_PROPERTY = "geronimo.dependency";
     private static final String REFERENCE_PROPERTY = "geronimo.reference";
+    private static final String ENVIRONMENT_LOCAL_NAME = "environment";
     private static final QName ENVIRONMENT_QNAME = new QName("http://geronimo.apache.org/xml/ns/deployment-1.1",
"environment");
 
     private List artifacts;
@@ -156,41 +158,13 @@
 
             String plan = writer.toString();
 
+            LinkedHashSet dependencies = toDependencies();
+            org.apache.geronimo.kernel.repository.Artifact configId = new org.apache.geronimo.kernel.repository.Artifact(groupId,
artifactId, version, "car");
             XmlObject doc = XmlObject.Factory.parse(plan);
             XmlCursor xmlCursor = doc.newCursor();
             try {
 
-                xmlCursor.toFirstContentToken();
-                xmlCursor.toFirstChild();
-                QName childName = xmlCursor.getName();
-                Environment oldEnvironment = null;
-                if (childName != null && childName.equals(ENVIRONMENT_QNAME)) {
-                    XmlObject xmlObject = xmlCursor.getObject();
-                    EnvironmentType environmentType = (EnvironmentType) xmlObject.copy().changeType(EnvironmentType.type);
-                    oldEnvironment = EnvironmentBuilder.buildEnvironment(environmentType);
-                    xmlCursor.removeXml();
-                } else {
-                    oldEnvironment = new Environment();
-                }
-
-                org.apache.geronimo.kernel.repository.Artifact configId = new org.apache.geronimo.kernel.repository.Artifact(groupId,
artifactId, version, "car");
-
-                LinkedHashSet dependencies = toDependencies();
-
-                Environment newEnvironment = new Environment();
-                newEnvironment.setConfigId(configId);
-                newEnvironment.setDependencies(dependencies);
-
-                EnvironmentBuilder.mergeEnvironments(oldEnvironment, newEnvironment);
-                EnvironmentType environmentType = EnvironmentBuilder.buildEnvironmentType(oldEnvironment);
-
-                xmlCursor.beginElement(ENVIRONMENT_QNAME);
-                XmlCursor element = environmentType.newCursor();
-                try {
-                    element.copyXmlContents(xmlCursor);
-                } finally {
-                    element.dispose();
-                }
+                mergeEnvironment(xmlCursor, configId, dependencies);
 
                 File targetDir = new File(this.targetDir);
                 if (targetDir.exists()) {
@@ -208,11 +182,63 @@
                 xmlCursor.dispose();
             }
         } catch (Exception e) {
-            log.error(e.getClass().getName()+": "+e.getMessage(), e);
+            log.error(e.getClass().getName() + ": " + e.getMessage(), e);
             throw e;
         }
     }
 
+    void mergeEnvironment(XmlCursor xmlCursor, org.apache.geronimo.kernel.repository.Artifact
configId, LinkedHashSet dependencies) {
+        xmlCursor.toFirstContentToken();
+        xmlCursor.toFirstChild();
+        QName childName = xmlCursor.getName();
+        Environment oldEnvironment;
+        if (childName != null && childName.getLocalPart().equals(ENVIRONMENT_LOCAL_NAME))
{
+            convertElement(xmlCursor, ENVIRONMENT_QNAME.getNamespaceURI());
+            XmlObject xmlObject = xmlCursor.getObject();
+            EnvironmentType environmentType = (EnvironmentType) xmlObject.copy().changeType(EnvironmentType.type);
+            oldEnvironment = EnvironmentBuilder.buildEnvironment(environmentType);
+            xmlCursor.removeXml();
+        } else {
+            oldEnvironment = new Environment();
+        }
+
+
+        Environment newEnvironment = new Environment();
+        newEnvironment.setConfigId(configId);
+        newEnvironment.setDependencies(dependencies);
+
+        EnvironmentBuilder.mergeEnvironments(oldEnvironment, newEnvironment);
+        EnvironmentType environmentType = EnvironmentBuilder.buildEnvironmentType(oldEnvironment);
+
+        xmlCursor.beginElement(ENVIRONMENT_QNAME);
+        XmlCursor element = environmentType.newCursor();
+        try {
+            element.copyXmlContents(xmlCursor);
+        } finally {
+            element.dispose();
+        }
+    }
+
+    private void convertElement(XmlCursor cursor, String namespace) {
+        cursor.push();
+        XmlCursor end = cursor.newCursor();
+        try {
+            end.toCursor(cursor);
+            end.toEndToken();
+            while (cursor.hasNextToken() && cursor.isLeftOf(end)) {
+                if (cursor.isStart()) {
+                    if (!namespace.equals(cursor.getName().getNamespaceURI())) {
+                        cursor.setName(new QName(namespace, cursor.getName().getLocalPart()));
+                    }
+                }
+                cursor.toNextToken();
+            }
+            cursor.pop();
+        } finally {
+            end.dispose();
+        }
+    }
+
     private LinkedHashSet toDependencies() {
         LinkedHashSet dependencies = new LinkedHashSet();
         for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
@@ -239,6 +265,7 @@
             return null;
         }
     }
+
     private static org.apache.geronimo.kernel.repository.Artifact toGeronimoArtifact(Dependency
dependency) {
         String groupId = dependency.getGroupId();
         String artifactId = dependency.getArtifactId();

Added: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/plan.xml?rev=393673&view=auto
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/plan.xml (added)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/plan.xml Wed
Apr 12 17:47:52 2006
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--Copyright 2004-2005 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.-->
+<!--$Rev: 388890 $ $Date: 2006-03-26 01:00:55 -0800 (Sun, 26 Mar 2006) $-->
+<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1">
+  <environment>
+    <configId>
+      <groupId>geronimo</groupId>
+      <artifactId>system-database</artifactId>
+      <version>1.1-SNAPSHOT</version>
+      <type>car</type>
+    </configId>
+    <dependencies>
+      <dependency>
+        <groupId>geronimo</groupId>
+        <artifactId>j2ee-server</artifactId>
+        <version>1.1-SNAPSHOT</version>
+        <type>car</type>
+      </dependency>
+      <dependency>
+        <groupId>geronimo</groupId>
+        <artifactId>geronimo-derby</artifactId>
+        <version>1.1-SNAPSHOT</version>
+        <type>jar</type>
+        <import>classes</import>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.derby</groupId>
+        <artifactId>derby</artifactId>
+        <version>10.1.1.0</version>
+        <type>jar</type>
+        <import>classes</import>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.derby</groupId>
+        <artifactId>derbynet</artifactId>
+        <version>10.1.1.0</version>
+        <type>jar</type>
+        <import>classes</import>
+      </dependency>
+    </dependencies>
+    <hidden-classes/>
+    <non-overridable-classes/>
+  </environment>
+  <resourceadapter>
+    <outbound-resourceadapter>
+      <connection-definition>
+        <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
+        <connectiondefinition-instance>
+          <name>SystemDatasource</name>
+          <config-property-setting name="UserName"/>
+          <config-property-setting name="Password"/>
+          <config-property-setting name="DatabaseName">SystemDatabase</config-property-setting>
+          <config-property-setting name="CreateDatabase">true</config-property-setting>
+          <connectionmanager>
+            <xa-transaction>
+              <transaction-caching/>
+            </xa-transaction>
+            <single-pool>
+              <max-size>100</max-size>
+              <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
+              <match-one/>
+            </single-pool>
+          </connectionmanager>
+        </connectiondefinition-instance>
+      </connection-definition>
+    </outbound-resourceadapter>
+  </resourceadapter>
+  <gbean name="DerbySystem" class="org.apache.geronimo.derby.DerbySystemGBean">
+    <reference name="ServerInfo">
+      <name>ServerInfo</name>
+    </reference>
+    <attribute name="derbySystemHome">var/derby</attribute>
+  </gbean>
+  <gbean name="DerbyNetwork" class="org.apache.geronimo.derby.DerbyNetworkGBean">
+    <reference name="derbySystem">
+      <name>DerbySystem</name>
+    </reference>
+    <attribute name="host">localhost</attribute>
+    <attribute name="port">1527</attribute>
+  </gbean>
+  <gbean name="DerbyLog" class="org.apache.geronimo.derby.DerbyLogGBean">
+    <reference name="DerbySystem">
+      <name>DerbySystem</name>
+    </reference>
+  </gbean>
+  <gbean name="TransactionalThreadPooledTimer" class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledTransactionalTimer">
+    <attribute name="repeatCount">5</attribute>
+    <reference name="TransactionContextManager">
+      <name>TransactionContextManager</name>
+    </reference>
+    <reference name="ManagedConnectionFactoryWrapper">
+      <name>SystemDatasource</name>
+    </reference>
+    <reference name="ThreadPool">
+      <name>DefaultThreadPool</name>
+    </reference>
+    <dependency>
+      <name>DerbySystem</name>
+    </dependency>
+  </gbean>
+  <gbean name="NonTransactionalThreadPooledTimer" class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledNonTransactionalTimer">
+    <reference name="TransactionContextManager">
+      <name>TransactionContextManager</name>
+    </reference>
+    <reference name="ManagedConnectionFactoryWrapper">
+      <name>SystemDatasource</name>
+    </reference>
+    <reference name="ThreadPool">
+      <name>DefaultThreadPool</name>
+    </reference>
+    <dependency>
+      <name>DerbySystem</name>
+    </dependency>
+  </gbean>
+</connector>
\ No newline at end of file

Added: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/result.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/result.xml?rev=393673&view=auto
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/result.xml
(added)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test-resources/result.xml
Wed Apr 12 17:47:52 2006
@@ -0,0 +1,126 @@
+<!--Copyright 2004-2005 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.-->
+<!--$Rev: 388890 $ $Date: 2006-03-26 01:00:55 -0800 (Sun, 26 Mar 2006) $-->
+<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
+  <dep:environment>
+    <dep:configId>
+      <dep:groupId>geronimo</dep:groupId>
+      <dep:artifactId>system-database</dep:artifactId>
+      <dep:version>1.1-SNAPSHOT</dep:version>
+      <dep:type>car</dep:type>
+    </dep:configId>
+    <dep:dependencies>
+      <dep:dependency>
+        <dep:groupId>geronimo</dep:groupId>
+        <dep:artifactId>j2ee-server</dep:artifactId>
+        <dep:version>1.1-SNAPSHOT</dep:version>
+        <dep:type>car</dep:type>
+      </dep:dependency>
+      <dep:dependency>
+        <dep:groupId>geronimo</dep:groupId>
+        <dep:artifactId>geronimo-derby</dep:artifactId>
+        <dep:version>1.1-SNAPSHOT</dep:version>
+        <dep:type>jar</dep:type>
+        <dep:import>classes</dep:import>
+      </dep:dependency>
+      <dep:dependency>
+        <dep:groupId>org.apache.derby</dep:groupId>
+        <dep:artifactId>derby</dep:artifactId>
+        <dep:version>10.1.1.0</dep:version>
+        <dep:type>jar</dep:type>
+        <dep:import>classes</dep:import>
+      </dep:dependency>
+      <dep:dependency>
+        <dep:groupId>org.apache.derby</dep:groupId>
+        <dep:artifactId>derbynet</dep:artifactId>
+        <dep:version>10.1.1.0</dep:version>
+        <dep:type>jar</dep:type>
+        <dep:import>classes</dep:import>
+      </dep:dependency>
+    </dep:dependencies>
+    <dep:hidden-classes/>
+    <dep:non-overridable-classes/>
+  </dep:environment>
+  <resourceadapter>
+    <outbound-resourceadapter>
+      <connection-definition>
+        <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
+        <connectiondefinition-instance>
+          <name>SystemDatasource</name>
+          <config-property-setting name="UserName"/>
+          <config-property-setting name="Password"/>
+          <config-property-setting name="DatabaseName">SystemDatabase</config-property-setting>
+          <config-property-setting name="CreateDatabase">true</config-property-setting>
+          <connectionmanager>
+            <xa-transaction>
+              <transaction-caching/>
+            </xa-transaction>
+            <single-pool>
+              <max-size>100</max-size>
+              <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
+              <match-one/>
+            </single-pool>
+          </connectionmanager>
+        </connectiondefinition-instance>
+      </connection-definition>
+    </outbound-resourceadapter>
+  </resourceadapter>
+  <gbean name="DerbySystem" class="org.apache.geronimo.derby.DerbySystemGBean">
+    <reference name="ServerInfo">
+      <name>ServerInfo</name>
+    </reference>
+    <attribute name="derbySystemHome">var/derby</attribute>
+  </gbean>
+  <gbean name="DerbyNetwork" class="org.apache.geronimo.derby.DerbyNetworkGBean">
+    <reference name="derbySystem">
+      <name>DerbySystem</name>
+    </reference>
+    <attribute name="host">localhost</attribute>
+    <attribute name="port">1527</attribute>
+  </gbean>
+  <gbean name="DerbyLog" class="org.apache.geronimo.derby.DerbyLogGBean">
+    <reference name="DerbySystem">
+      <name>DerbySystem</name>
+    </reference>
+  </gbean>
+  <gbean name="TransactionalThreadPooledTimer" class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledTransactionalTimer">
+    <attribute name="repeatCount">5</attribute>
+    <reference name="TransactionContextManager">
+      <name>TransactionContextManager</name>
+    </reference>
+    <reference name="ManagedConnectionFactoryWrapper">
+      <name>SystemDatasource</name>
+    </reference>
+    <reference name="ThreadPool">
+      <name>DefaultThreadPool</name>
+    </reference>
+    <dependency>
+      <name>DerbySystem</name>
+    </dependency>
+  </gbean>
+  <gbean name="NonTransactionalThreadPooledTimer" class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledNonTransactionalTimer">
+    <reference name="TransactionContextManager">
+      <name>TransactionContextManager</name>
+    </reference>
+    <reference name="ManagedConnectionFactoryWrapper">
+      <name>SystemDatasource</name>
+    </reference>
+    <reference name="ThreadPool">
+      <name>DefaultThreadPool</name>
+    </reference>
+    <dependency>
+      <name>DerbySystem</name>
+    </dependency>
+  </gbean>
+</connector>

Added: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/PlanProcessorTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/PlanProcessorTest.java?rev=393673&view=auto
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/PlanProcessorTest.java
(added)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/test/org/apache/geronimo/plugin/packaging/PlanProcessorTest.java
Wed Apr 12 17:47:52 2006
@@ -0,0 +1,90 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.plugin.packaging;
+
+import java.net.URL;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.geronimo.kernel.repository.Artifact;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class PlanProcessorTest extends TestCase {
+
+    public void testExistingEnvironmentMerge() throws Exception {
+        URL planURL = this.getClass().getClassLoader().getResource("plan.xml");
+        XmlObject xmlObject = XmlObject.Factory.parse(planURL);
+        XmlCursor xmlCursor = xmlObject.newCursor();
+        Artifact configId = new Artifact("groupId", "artifactId", "version", "car");
+        LinkedHashSet dependencies = new LinkedHashSet();
+        PlanProcessor planProcessor = new PlanProcessor();
+        planProcessor.mergeEnvironment(xmlCursor, configId, dependencies);
+        System.out.println(xmlObject.toString());
+        URL expectedURL = this.getClass().getClassLoader().getResource("result.xml");
+        XmlObject result = XmlObject.Factory.parse(expectedURL);
+        List problems = new ArrayList();
+        boolean ok = compareXmlObjects(xmlObject, result, problems);
+        assertTrue("problems: " + problems, ok);
+
+    }
+    private boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List
problems) {
+        XmlCursor test = xmlObject.newCursor();
+        XmlCursor expected = expectedObject.newCursor();
+        boolean similar = true;
+        int elementCount = 0;
+        while (toNextStartToken(test)) {
+            elementCount++;
+            if (!toNextStartToken(expected)) {
+                problems.add("test longer than expected at element: " + elementCount);
+                return false;
+            }
+            QName actualQName = test.getName();
+            QName expectedQName = expected.getName();
+            if (!actualQName.equals(expectedQName)) {
+                problems.add("Different elements at elementCount: " + elementCount + ", test:
" + actualQName + ", expected: " + expectedQName);
+                similar = false;
+            }
+            test.toNextToken();
+            expected.toNextToken();
+        }
+        if (toNextStartToken(expected)) {
+            problems.add("test shorter that expected at element: " + elementCount);
+            similar = false;
+        }
+        return similar;
+    }
+
+    private boolean toNextStartToken(XmlCursor cursor) {
+        while (!cursor.isStart()) {
+            if (!cursor.hasNextToken()) {
+                return false;
+            }
+            cursor.toNextToken();
+        }
+        return true;
+    }
+
+}



Mime
View raw message