geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcco...@apache.org
Subject svn commit: r649871 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test: java/org/apache/geronimo/jee/application/ resources/application/
Date Sun, 20 Apr 2008 02:55:21 GMT
Author: mcconne
Date: Sat Apr 19 19:55:19 2008
New Revision: 649871

URL: http://svn.apache.org/viewvc?rev=649871&view=rev
Log:
GERONIMODEVTOOLS-259 More Junit testcases for the JAXB application schema -- Thanks to BJ
Reed for the patch !!

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.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=649871&r1=649870&r2=649871&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
Sat Apr 19 19:55:19 2008
@@ -24,6 +24,7 @@
 import java.io.InputStream;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.SAXParser;
@@ -33,6 +34,21 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
+import org.apache.geronimo.jee.deployment.Artifact;
+import org.apache.geronimo.jee.deployment.Dependencies;
+import org.apache.geronimo.jee.deployment.Dependency;
+import org.apache.geronimo.jee.deployment.Environment;
+import org.apache.geronimo.jee.deployment.Gbean;
+import org.apache.geronimo.jee.deployment.Pattern;
+import org.apache.geronimo.jee.security.Description;
+import org.apache.geronimo.jee.security.DistinguishedName;
+import org.apache.geronimo.jee.security.LoginDomainPrincipal;
+import org.apache.geronimo.jee.security.Principal;
+import org.apache.geronimo.jee.security.RealmPrincipal;
+import org.apache.geronimo.jee.security.Role;
+import org.apache.geronimo.jee.security.RoleMappings;
+import org.apache.geronimo.jee.security.Security;
+import org.apache.geronimo.jee.security.SubjectInfo;
 import org.custommonkey.xmlunit.Diff;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
@@ -53,7 +69,7 @@
  *      <li>Unmarshalling and marshalling sequence
  *      <li>Namespace conversion
  *      <li>Element conversion (TODO)
- *      <li>Create a file (TODO)
+ *      <li>Create XML with all fields
  * </ol>
  * 
  * 
@@ -84,6 +100,9 @@
                          "application/geronimo-application-expected-6.xml");
     }
 
+    public void testCompleteXML() throws Exception {
+        buildFullXMLFromScratch("application/geronimo-application-expected-11.xml");
+    }
 
     /*------------------------------------------------------------------------*\
     |                                                                          |
@@ -207,6 +226,188 @@
         }
     }
 
+    private void buildFullXMLFromScratch (String fileExpected) throws Exception {
+        org.apache.geronimo.jee.application.ObjectFactory applicationFactory = new org.apache.geronimo.jee.application.ObjectFactory();
+        org.apache.geronimo.jee.deployment.ObjectFactory deploymentFactory = new org.apache.geronimo.jee.deployment.ObjectFactory();
+        org.apache.geronimo.jee.security.ObjectFactory securityFactory = new org.apache.geronimo.jee.security.ObjectFactory();
+        Application application = applicationFactory.createApplication();
+
+        // hard code everything to come up with a large XML with everything in it
+        application.setApplicationName("test-app-name");
+
+        // set the Environment
+        Environment environment = new Environment ();
+        Artifact artifact = new Artifact ();
+        artifact.setGroupId("org.apache.geronimo.testsuite");
+        artifact.setArtifactId("agent-ear");
+        artifact.setVersion("2.2-SNAPSHOT");
+        artifact.setType("ear");
+        environment.setModuleId(artifact);
+
+        Dependencies dependencies = new Dependencies ();
+        Dependency dependency = new Dependency ();
+        dependency.setGroupId("org.apache.geronimo.testsuite");
+        dependency.setArtifactId("agent-ds");
+        dependency.setVersion("2.2-SNAPSHOT");
+        dependency.setType("car");
+        dependencies.getDependency().add(dependency);
+        environment.setDependencies(dependencies);
+        application.setEnvironment(environment);
+
+        Module module = applicationFactory.createModule();
+        Path path = applicationFactory.createPath();
+        path.setId("module-altdd-path-id");
+        path.setValue("module-altdd-path-value");
+        module.setAltDd(path);
+//        module.setAny("module-any"); //TODO
+        path = applicationFactory.createPath();
+        path.setId("module-connector-path-id");
+        path.setValue("module-connector-path-value");
+        module.setConnector(path);
+        path = applicationFactory.createPath();
+        path.setId("module-ejb-path-id");
+        path.setValue("module-ejb-path-value");
+        module.setEjb(path);
+        path = applicationFactory.createPath();
+        path.setId("module-java-path-id");
+        path.setValue("module-java-path-value");
+        module.setJava(path);
+        path = applicationFactory.createPath();
+        path.setId("module-web-path-id");
+        path.setValue("module-web-path-value");
+        module.setWeb(path);
+        application.getModule().add(module);
+
+        ExtModule extModule = applicationFactory.createExtModule();
+        extModule.setInternalPath("extmodule-internalpath");
+//        module.setAny("module-any"); //TODO
+        path = applicationFactory.createPath();
+        path.setId("extmodule-connector-path-id");
+        path.setValue("extmodule-connector-path-value");
+        extModule.setConnector(path);
+        path = applicationFactory.createPath();
+        path.setId("extmodule-ejb-path-id");
+        path.setValue("extmodule-ejb-path-value");
+        extModule.setEjb(path);
+        path = applicationFactory.createPath();
+        path.setId("extmodule-java-path-id");
+        path.setValue("extmodule-java-path-value");
+        extModule.setJava(path);
+        path = applicationFactory.createPath();
+        path.setId("extmodule-web-path-id");
+        path.setValue("extmodule-web-path-value");
+        extModule.setWeb(path);
+        Pattern pattern = deploymentFactory.createPattern();
+        pattern.setArtifactId("extmodule-externalpath-artifactid");
+        pattern.setCustomFoo("extmodule-externalpath-customfoo");
+        pattern.setGroupId("extmodule-externalpath-groupid");
+        pattern.setModule("extmodule-externalpath-module");
+        pattern.setType("extmodule-externalpath-type");
+        pattern.setVersion("extmodule-externalpath-version");
+        extModule.setExternalPath(pattern);
+        application.getExtModule().add(extModule);
+
+        Gbean gbean = deploymentFactory.createGbean();
+        gbean.setClazz("gbean-class");
+        gbean.setName("gbean-name");
+        application.getService().add(deploymentFactory.createGbean(gbean));
+
+        // set the Security
+        // TODO: this whole block just gets us <ns2:security/> which can't be correct
+        // also, when adding the security to the application, the marshalling
+        // gives that the types aren't compatible.
+        Security security = securityFactory.createSecurity();
+        security.setDefaultRole ("security-role");
+        security.setDoasCurrentCaller(true);
+        security.setUseContextHandler(true);
+        pattern = deploymentFactory.createPattern();
+        pattern.setArtifactId("security-credentialstoreref-artifactid");
+        pattern.setCustomFoo("security-credentialstoreref-customfoo");
+        pattern.setGroupId("security-credentialstoreref-groupid");
+        pattern.setModule("security-credentialstoreref-module");
+        pattern.setType("security-credentialstoreref-type");
+        pattern.setVersion("security-credentialstoreref-version");
+        security.setCredentialStoreRef(pattern);
+        SubjectInfo subject = securityFactory.createSubjectInfo();
+        subject.setId("security-subjectinfo-id");
+        subject.setRealm("security-subjectinfo-realm");
+        Description description = securityFactory.createDescription();
+        description.setValue("security-subjectinfo-description");
+        subject.getDescription().add(description);
+        security.setDefaultSubject(subject);
+        RoleMappings roleMappings = securityFactory.createRoleMappings();
+        Role role = securityFactory.createRole();
+        role.setRoleName("security-role");
+        SubjectInfo subjectInfo = securityFactory.createSubjectInfo();
+        subjectInfo.setId("security-role-subjectinfo-id");
+        subjectInfo.setRealm("security-role-subjectinfo-realm");
+        description = securityFactory.createDescription();
+        description.setValue("security-role-subjectinfo-description");
+        subjectInfo.getDescription().add(description);
+        role.setRunAsSubject(subjectInfo);
+        description = securityFactory.createDescription();
+        description.setValue("security-role-description");
+        role.getDescription().add(description);
+        DistinguishedName distinguishedName = securityFactory.createDistinguishedName();
+        distinguishedName.setName("security-role-distinguishedname");
+        description = securityFactory.createDescription();
+        description.setValue("security-role-distinguished-name-description");
+        distinguishedName.getDescription().add(description);
+        role.getDistinguishedName().add(distinguishedName);
+        LoginDomainPrincipal loginDomainPrincipal = securityFactory.createLoginDomainPrincipal();
+        loginDomainPrincipal.setDomainName("security-role-logindomainprincipal-domainname");
+        loginDomainPrincipal.setName("security-role-logindomainprincipal-name");
+        loginDomainPrincipal.setClazz("security-role-logindomainprincipal-class");
+        description = securityFactory.createDescription();
+        description.setValue("security-role-logindomainprincipal-description");
+        loginDomainPrincipal.getDescription().add(description);
+        role.getLoginDomainPrincipal().add(loginDomainPrincipal);
+        Principal principal = securityFactory.createPrincipal();
+        principal.setName("security-role-principal-name");
+        principal.setClazz("security-role-principal-class");
+        description = securityFactory.createDescription();
+        description.setValue("security-role-principal-description");
+        principal.getDescription().add(description);
+        role.getPrincipal().add(principal);
+        RealmPrincipal realmPrincipal = securityFactory.createRealmPrincipal();
+        realmPrincipal.setName("security-role-realmprincipal-name");
+        realmPrincipal.setClazz("security-role-realmprincipal-class");
+        description = securityFactory.createDescription();
+        description.setValue("security-role-realmprincipal-description");
+        realmPrincipal.getDescription().add(description);
+        role.getRealmPrincipal().add(realmPrincipal);
+        roleMappings.getRole().add(role);
+        security.setRoleMappings(roleMappings);
+//        application.setSecurity(securityFactory.createSecurity(security));
+ 
+        JAXBElement<Application> jaxbElement = applicationFactory.createApplication(application);
+        
+        // 
+        // Marshall the output of the unmarshall
+        // 
+        JAXBContext jaxbContext = JAXBContext.newInstance( 
+                "org.apache.geronimo.jee.application:" +
+                "org.apache.geronimo.jee.deployment", getClass().getClassLoader() );
+        Marshaller marshaller = jaxbContext.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        marshaller.marshal(jaxbElement, baos);
+        String actual = new String(baos.toByteArray());
+
+        InputStream expectedInputStream = this.getClass().getClassLoader().getResourceAsStream(fileExpected);
+        String expected = readContent(expectedInputStream);
+
+        try {
+            Diff myDiff = new Diff(expected, actual);
+            assertTrue("Files are similar " + myDiff, myDiff.similar());
+        }
+        catch (AssertionFailedError e) {
+            System.out.println("Actual XML:\n" + actual + '\n');
+            System.out.println("[Expected XML: " + fileExpected + "]\n" + expected + '\n');
+            throw e;            
+        }
+    }
 
     private String readContent(InputStream in) throws IOException {
         StringBuffer sb = new StringBuffer();

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.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-expected-11.xml?rev=649871&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.xml
(added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.xml
Sat Apr 19 19:55:19 2008
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+    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$ -->
+
+<ns2:application xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ns2="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
application-name="test-app-name">
+    <environment>
+        <moduleId>
+            <groupId>org.apache.geronimo.testsuite</groupId>
+            <artifactId>agent-ear</artifactId>
+            <version>2.2-SNAPSHOT</version>
+            <type>ear</type>
+        </moduleId>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.geronimo.testsuite</groupId>
+                <artifactId>agent-ds</artifactId>
+                <version>2.2-SNAPSHOT</version>
+                <type>car</type>
+            </dependency>
+        </dependencies>
+    </environment>
+    <ns2:module>
+        <ns2:connector id="module-connector-path-id">module-connector-path-value</ns2:connector>
+        <ns2:ejb id="module-ejb-path-id">module-ejb-path-value</ns2:ejb>
+        <ns2:java id="module-java-path-id">module-java-path-value</ns2:java>
+        <ns2:web id="module-web-path-id">module-web-path-value</ns2:web>
+        <ns2:alt-dd id="module-altdd-path-id">module-altdd-path-value</ns2:alt-dd>
+    </ns2:module>
+    <ns2:ext-module>
+        <ns2:connector id="extmodule-connector-path-id">extmodule-connector-path-value</ns2:connector>
+        <ns2:ejb id="extmodule-ejb-path-id">extmodule-ejb-path-value</ns2:ejb>
+        <ns2:java id="extmodule-java-path-id">extmodule-java-path-value</ns2:java>
+        <ns2:web id="extmodule-web-path-id">extmodule-web-path-value</ns2:web>
+        <ns2:internal-path>extmodule-internalpath</ns2:internal-path>
+        <ns2:external-path>
+            <groupId>extmodule-externalpath-groupid</groupId>
+            <artifactId>extmodule-externalpath-artifactid</artifactId>
+            <version>extmodule-externalpath-version</version>
+            <module>extmodule-externalpath-module</module>
+            <type>extmodule-externalpath-type</type>
+            <name>extmodule-externalpath-customfoo</name>
+        </ns2:external-path>
+    </ns2:ext-module>
+    <gbean name="gbean-name" class="gbean-class"/>
+</ns2:application>
\ No newline at end of file

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.deployment.v21.jaxbmodel/src/test/resources/application/geronimo-application-expected-11.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message