You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by mc...@apache.org on 2008/04/11 03:39:03 UTC
svn commit: r647028 - in
/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test:
java/org/apache/geronimo/jee/application/ resources/application/
Author: mcconne
Date: Thu Apr 10 18:39:01 2008
New Revision: 647028
URL: http://svn.apache.org/viewvc?rev=647028&view=rev
Log:
GERONIMODEVTOOLS-312 First junit testcase for schema conversion
Added:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml (with props)
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml (with props)
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml (with props)
Modified:
geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/java/org/apache/geronimo/jee/application/GeronimoApplicationTest.java
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/java/org/apache/geronimo/jee/application/GeronimoApplicationTest.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/java/org/apache/geronimo/jee/application/GeronimoApplicationTest.java?rev=647028&r1=647027&r2=647028&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/java/org/apache/geronimo/jee/application/GeronimoApplicationTest.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/java/org/apache/geronimo/jee/application/GeronimoApplicationTest.java Thu Apr 10 18:39:01 2008
@@ -26,13 +26,22 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.ValidationEvent;
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.geronimo.jee.deployment.Module;
import org.custommonkey.xmlunit.Diff;
+import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+import org.xml.sax.XMLReader;
/**
* <strong>GeronimoApplicationTest</strong> is used to test various JAXB
@@ -45,6 +54,7 @@
* <p>The following JAXB operations are performed:
* <ol>
* <li>Unmarshalling and marshalling sequence
+ * <li>Namespace conversion
* </ol>
*
*
@@ -52,18 +62,32 @@
*/
public class GeronimoApplicationTest extends TestCase {
- public void testUnmarshallMarshall() throws Exception {
+ public void testUnmarshallAndMarshall() throws Exception {
- unmarshallAndMarshall("application/geronimo-application-example-1.xml",
+ unmarshallAndMarshall("application/geronimo-application-example-1.xml",
"application/geronimo-application-expected-1.xml");
-
- unmarshallAndMarshall("application/geronimo-application-example-2.xml",
- "application/geronimo-application-expected-2.xml");
-
- unmarshallAndMarshall("application/geronimo-application-example-3.xml",
- "application/geronimo-application-expected-3.xml");
+
+ unmarshallAndMarshall("application/geronimo-application-example-2.xml",
+ "application/geronimo-application-expected-2.xml");
+
+ unmarshallAndMarshall("application/geronimo-application-example-3.xml",
+ "application/geronimo-application-expected-3.xml");
}
+
+ public void testConvertNamespace() throws Exception {
+
+ convertNamespace("application/geronimo-application-example-4.xml",
+ "application/geronimo-application-expected-1.xml");
+
+ convertNamespace("application/geronimo-application-example-5.xml",
+ "application/geronimo-application-expected-2.xml");
+
+ convertNamespace("application/geronimo-application-example-6.xml",
+ "application/geronimo-application-expected-3.xml");
+ }
+
+
private void unmarshallAndMarshall(String fileExample, String fileExpected) throws Exception {
//
@@ -112,6 +136,67 @@
System.out.println("[Actual XML] " + '\n' + actual + '\n');
throw e;
}
+
+ }
+
+ private void convertNamespace(String fileExample,String fileExpected) throws Exception {
+
+ //
+ // Create unmarshaller and marshaller
+ //
+ JAXBContext jAXBContext = JAXBContext.newInstance(Application.class,Module.class);
+ Unmarshaller unmarshaller = jAXBContext.createUnmarshaller();
+ Marshaller marshaller = jAXBContext.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+
+ //
+ // Create SAXParser
+ //
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(false);
+ SAXParser parser = factory.newSAXParser();
+
+ //
+ // Create NamespaceFilter to filter for v1.1 namespaces
+ //
+ NamespaceFilter xmlFilter = new NamespaceFilter(parser.getXMLReader());
+
+ //
+ // Read example and expected XML files
+ //
+ InputStream exampleInputStream = this.getClass().getClassLoader().getResourceAsStream(fileExample);
+ InputStream expectedInputStream = this.getClass().getClassLoader().getResourceAsStream(fileExpected);
+ String example = readContent(exampleInputStream);
+ String expected = readContent(expectedInputStream);
+
+ //
+ // Unmarshall the example file
+ //
+ SAXSource source = new SAXSource(xmlFilter, new InputSource(new ByteArrayInputStream(expected.getBytes())));
+ Object jAXBElement = unmarshaller.unmarshal(source);
+
+ //
+ // Marshall the output of the unmarshall
+ //
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ marshaller.marshal(jAXBElement, baos);
+ byte[] bytes = baos.toByteArray();
+ String actual = new String(bytes);
+
+ //
+ // Compare actual and expected
+ //
+ try {
+ Diff myDiff = new Diff(expected, actual);
+ assertTrue("Files are similar " + myDiff, myDiff.similar());
+ } catch (AssertionFailedError e) {
+ System.out.println("[Example XML] " + '\n' + example + '\n');
+ System.out.println("[Expected XML] " + '\n' + expected + '\n');
+ System.out.println("[Actual XML] " + '\n' + actual + '\n');
+ throw e;
+ }
}
private String readContent(InputStream in) throws IOException {
@@ -125,4 +210,23 @@
String content = sb.toString();
return content;
}
+
+ public static class NamespaceFilter extends XMLFilterImpl {
+ private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new byte[0]));
+
+ public NamespaceFilter(XMLReader xmlReader) {
+ super(xmlReader);
+ }
+
+ public void startElement(String uri, String localName, String qname, Attributes atts) throws SAXException {
+ if (uri.equals("http://geronimo.apache.org/xml/ns/j2ee/application-1.2")) {
+ uri = "http://geronimo.apache.org/xml/ns/j2ee/application-2.0";
+ }
+ else if (uri.equals("http://geronimo.apache.org/xml/ns/deployment-1.1")) {
+ uri = "http://geronimo.apache.org/xml/ns/deployment-1.2";
+ }
+ super.startElement(uri, localName, qname, atts);
+ }
+ }
+
}
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml?rev=647028&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml Thu Apr 10 18:39:01 2008
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<!-- @version $Rev$ $Date$ -->
+
+<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.2"
+ xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
+ <dep:environment>
+ <dep:moduleId>
+ <dep:groupId>org.apache.geronimo.testsuite</dep:groupId>
+ <dep:artifactId>corba-mytime-ear</dep:artifactId>
+ <dep:version>2.2-SNAPSHOT</dep:version>
+ <dep:type>car</dep:type>
+ </dep:moduleId>
+ </dep:environment>
+</application>
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-4.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml?rev=647028&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml Thu Apr 10 18:39:01 2008
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<!-- @version $Rev$ $Date$ -->
+
+<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.2">
+ <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+ <moduleId>
+ <groupId>org.apache.geronimo.plugins.monitoring</groupId>
+ <artifactId>agent-ear</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ <type>ear</type>
+ </moduleId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.plugins.monitoring</groupId>
+ <artifactId>agent-ds</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ <type>car</type>
+ </dependency>
+ </dependencies>
+ </environment>
+</application>
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-5.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml?rev=647028&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml Thu Apr 10 18:39:01 2008
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<!-- @version $Rev$ $Date$ -->
+
+<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.2">
+
+ <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+ <moduleId>
+ <groupId>org.apache.geronimo.testsuite</groupId>
+ <artifactId>jca-cms-ear</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ <type>ear</type>
+ </moduleId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.configs</groupId>
+ <artifactId>system-database</artifactId>
+ <type>car</type>
+ </dependency>
+ </dependencies>
+ </environment>
+
+ <module>
+ <connector>tranql.rar</connector>
+ <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
+ <resourceadapter>
+ <outbound-resourceadapter>
+ <connection-definition>
+ <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
+ <connectiondefinition-instance>
+ <name>cmsds</name>
+ <!--<config-property-setting name="UserName"></config-property-setting>-->
+ <!--<config-property-setting name="Password"></config-property-setting>-->
+ <config-property-setting name="DatabaseName">TestDatabase</config-property-setting>
+ <config-property-setting name="CreateDatabase">false</config-property-setting>
+ <connectionmanager>
+ <container-managed-security/>
+ <xa-transaction>
+ <transaction-caching/>
+ </xa-transaction>
+ <single-pool>
+ <max-size>10</max-size>
+ <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
+ <select-one-assume-match/>
+ </single-pool>
+ </connectionmanager>
+ </connectiondefinition-instance>
+ <connectiondefinition-instance>
+ <name>configuredsecurityds</name>
+ <config-property-setting name="UserName">system</config-property-setting>
+ <config-property-setting name="Password">manager</config-property-setting>
+ <config-property-setting name="DatabaseName">TestDatabase</config-property-setting>
+ <config-property-setting name="CreateDatabase">true</config-property-setting>
+ <connectionmanager>
+ <xa-transaction>
+ <transaction-caching/>
+ </xa-transaction>
+ <single-pool>
+ <max-size>10</max-size>
+ <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
+ <select-one-assume-match/>
+ </single-pool>
+ </connectionmanager>
+ </connectiondefinition-instance>
+ </connection-definition>
+ </outbound-resourceadapter>
+ </resourceadapter>
+ <gbean name="test-cms-realm" class="org.apache.geronimo.security.realm.GenericSecurityRealm">
+ <attribute name="realmName">test-cms-realm</attribute>
+ <xml-reference name="LoginModuleConfiguration" xmlns:lc="http://geronimo.apache.org/xml/ns/loginconfig-1.1">
+ <lc:login-config>
+ <lc:login-module-ref control-flag="REQUIRED">
+ <lc:pattern>
+ <name xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">test-cms-credentials
+ </name>
+ </lc:pattern>
+ </lc:login-module-ref>
+ <lc:login-module control-flag="REQUIRED" wrap-principals="false">
+ <lc:login-domain-name>test-app-credentials</lc:login-domain-name>
+ <lc:login-module-class>org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule</lc:login-module-class>
+ <lc:option name="usersURI">var/security/demo_users.properties</lc:option>
+ <lc:option name="groupsURI">var/security/demo_groups.properties</lc:option>
+ </lc:login-module>
+ </lc:login-config>
+ </xml-reference>
+ <reference name="ServerInfo">
+ <name>ServerInfo</name>
+ </reference>
+ </gbean>
+ <gbean name="test-cms-credentials"
+ class="org.apache.geronimo.connector.outbound.security.PasswordCredentialLoginModuleWrapperGBean">
+ <attribute name="loginModuleClass">
+ org.apache.geronimo.connector.outbound.security.CallerIdentityPasswordCredentialLoginModule
+ </attribute>
+ <reference name="ManagedConnectionFactoryWrapper">
+ <name>cmsds</name>
+ </reference>
+ <attribute name="loginDomainName">test-cms-credentials</attribute>
+ </gbean>
+ </connector>
+ </module>
+ <module>
+ <web>web.war</web>
+ <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0">
+ <security-realm-name>test-cms-realm</security-realm-name>
+ <security xmlns="http://geronimo.apache.org/xml/ns/security-2.0">
+ <credential-store-ref>
+ <name xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">test-credential-store</name>
+ </credential-store-ref>
+ <default-subject>
+ <realm>test-cms-realm</realm>
+ <id>test</id>
+ </default-subject>
+ <role-mappings>
+ <role role-name="test">
+ <principal class="org.apache.geronimo.connector.outbound.security.ResourcePrincipal" name="george"/>
+ </role>
+ <role role-name="fail">
+ <run-as-subject>
+ <realm>test-cms-realm</realm>
+ <id>fail</id>
+ </run-as-subject>
+ </role>
+ </role-mappings>
+ </security>
+ </web-app>
+ </module>
+ <gbean name="test-credential-store" class="org.apache.geronimo.security.credentialstore.SimpleCredentialStoreImpl">
+ <xml-attribute name="credentialStore">
+ <credential-store xmlns="http://geronimo.apache.org/xml/ns/credentialstore-1.0">
+ <realm name="test-cms-realm">
+ <subject>
+ <id>test</id>
+ <credential>
+ <type>org.apache.geronimo.security.credentialstore.NameCallbackHandler</type>
+ <value>george</value>
+ </credential>
+ <credential>
+ <type>org.apache.geronimo.security.credentialstore.PasswordCallbackHandler</type>
+ <value>bone</value>
+ </credential>
+ </subject>
+ <subject>
+ <id>fail</id>
+ <credential>
+ <type>org.apache.geronimo.security.credentialstore.NameCallbackHandler</type>
+ <value>gracie</value>
+ </credential>
+ <credential>
+ <type>org.apache.geronimo.security.credentialstore.PasswordCallbackHandler</type>
+ <value>biscuit</value>
+ </credential>
+ </subject>
+ </realm>
+ </credential-store>
+ </xml-attribute>
+ <dependency>
+ <name>test-cms-realm</name>
+ </dependency>
+ </gbean>
+</application>
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-example-6.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml