ammulder 2003/09/29 09:00:49
Added: modules/core/src/test/org/apache/geronimo/xml/deployment
EjbJarLoaderTest.java GeronimoEjbJarLoaderTest.java
modules/core/src/test-data/xml/deployment simple-ejb-jar.xml
simple-geronimo-ejb-jar.xml
Log:
Starter unit tests for the EJB DD POJOs
Revision Changes Path
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/EjbJarLoaderTest.java
Index: EjbJarLoaderTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.File;
import java.io.FileReader;
import junit.framework.TestCase;
import org.apache.geronimo.deployment.model.j2ee.EJBRef;
import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
import org.apache.geronimo.deployment.model.j2ee.ResourceEnvRef;
import org.apache.geronimo.deployment.model.j2ee.Description;
import org.apache.geronimo.deployment.model.j2ee.DisplayName;
import org.apache.geronimo.deployment.model.ejb.EjbJar;
import org.apache.geronimo.deployment.model.ejb.EjbJarDocument;
import org.apache.geronimo.deployment.model.ejb.EnterpriseBeans;
import org.apache.geronimo.deployment.model.ejb.Session;
import org.w3c.dom.Document;
/**
* Tests basic EJB JAR DD loading (not very comprehensive)
*
* @version $Revision: 1.1 $ $Date: 2003/09/29 16:00:49 $
*/
public class EjbJarLoaderTest extends TestCase {
private File docDir;
private EjbJarLoader loader;
public void testSimpleLoad() throws Exception {
File f = new File(docDir, "simple-ejb-jar.xml");
Document xmlDoc = LoaderUtil.parseXML(new FileReader(f));
EjbJarDocument doc = loader.load(xmlDoc);
EjbJar jar = doc.getEjbJar();
checkEjbJar(jar, "example");
}
static void checkEjbJar(EjbJar jar, String expectedEnvValue) {
assertEquals("2.1", jar.getVersion());
checkDescription("This is a test EJB JAR DD for JSR-88
purposes",jar.getDescription());
checkDisplayName("Test EJB JAR",jar.getDisplayName());
EnterpriseBeans beans = jar.getEnterpriseBeans();
Session[] session = beans.getSession();
assertEquals(2, session.length);
assertEquals("Stateless", session[0].getSessionType());
assertEquals("Stateful", session[1].getSessionType());
checkStateless(session[0], expectedEnvValue);
checkStateful(session[1]);
}
private static void checkStateless(Session session, String
expectedEnvValue) {
checkDescription("This is a sample stateless session bean",
session.getDescription());
checkDisplayName("Stateless Session Bean", session.getDisplayName());
assertEquals("StatelessTest", session.getEJBName());
assertEquals("org.apache.geronimo.enterprise.deploy.test.StatelessHome",
session.getHome());
assertEquals("org.apache.geronimo.enterprise.deploy.test.Stateless",
session.getRemote());
assertEquals("org.apache.geronimo.enterprise.deploy.test.StatelessBean",
session.getEJBClass());
assertEquals("Container", session.getTransactionType());
EnvEntry[] envs = session.getEnvEntry();
assertEquals(1, envs.length);
EnvEntry envEntry = envs[0];
assertEquals("Variable 1", envEntry.getEnvEntryName());
assertEquals("java.lang.String", envEntry.getEnvEntryType());
assertEquals(expectedEnvValue, envEntry.getEnvEntryValue());
ResourceEnvRef[] resEnvRefs = session.getResourceEnvRef();
assertEquals(1, resEnvRefs.length);
ResourceEnvRef resEnvRef = resEnvRefs[0];
assertEquals("jdbc/StatelessDatabase",
resEnvRef.getResourceEnvRefName());
assertEquals("javax.sql.DataSource",
resEnvRef.getResourceEnvRefType());
}
private static void checkStateful(Session session) {
checkDescription("This is a sample stateful session bean",
session.getDescription());
checkDisplayName("Stateful Session Bean", session.getDisplayName());
assertEquals("StatefulTest", session.getEJBName());
assertEquals("org.apache.geronimo.enterprise.deploy.test.StatefulHome",
session.getHome());
assertEquals("org.apache.geronimo.enterprise.deploy.test.Stateful",
session.getRemote());
assertEquals("org.apache.geronimo.enterprise.deploy.test.StatefulBean",
session.getEJBClass());
assertEquals("Container", session.getTransactionType());
EJBRef[] ejbRefs = session.getEJBRef();
assertEquals(1, ejbRefs.length);
EJBRef ejbRef = ejbRefs[0];
assertEquals("ejb/MyStateless", ejbRef.getEJBRefName());
assertEquals("Session", ejbRef.getEJBRefType());
assertEquals("org.apache.geronimo.enterprise.deploy.test.StatelessHome",
ejbRef.getHome());
assertEquals("org.apache.geronimo.enterprise.deploy.test.Stateless",
ejbRef.getRemote());
assertEquals("Stateless", ejbRef.getEJBLink());
ResourceEnvRef[] resEnvRefs = session.getResourceEnvRef();
assertEquals(1, resEnvRefs.length);
ResourceEnvRef resEnvRef = resEnvRefs[0];
assertEquals("jdbc/StatefulDatabase",
resEnvRef.getResourceEnvRefName());
assertEquals("javax.sql.DataSource",
resEnvRef.getResourceEnvRefType());
}
private static void checkDescription(String s, Description[] description)
{
assertEquals(1, description.length);
assertEquals(s, description[0].getContent());
}
private static void checkDisplayName(String s, DisplayName[] name) {
assertEquals(1, name.length);
assertEquals(s, name[0].getContent());
}
protected void setUp() throws Exception {
docDir = new File("src/test-data/xml/deployment");
loader = new EjbJarLoader();
}
}
1.1
incubator-geronimo/modules/core/src/test/org/apache/geronimo/xml/deployment/GeronimoEjbJarLoaderTest.java
Index: GeronimoEjbJarLoaderTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.xml.deployment;
import java.io.File;
import java.io.FileReader;
import junit.framework.TestCase;
import org.w3c.dom.Document;
import
org.apache.geronimo.deployment.model.geronimo.ejb.GeronimoEjbJarDocument;
import org.apache.geronimo.deployment.model.geronimo.ejb.EjbJar;
import org.apache.geronimo.deployment.model.geronimo.ejb.EnterpriseBeans;
import org.apache.geronimo.deployment.model.geronimo.ejb.Session;
import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceEnvRef;
import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
/**
* Tests basic Geronimo EJB JAR DD loading (not very comprehensive)
*
* @version $Revision: 1.1 $ $Date: 2003/09/29 16:00:49 $
*/
public class GeronimoEjbJarLoaderTest extends TestCase {
private File docDir;
private GeronimoEjbJarLoader loader;
public void testSimpleLoad() throws Exception {
File f = new File(docDir, "simple-geronimo-ejb-jar.xml");
Document xmlDoc = LoaderUtil.parseXML(new FileReader(f));
GeronimoEjbJarDocument doc = loader.load(xmlDoc);
EjbJar jar = doc.getEjbJar();
EjbJarLoaderTest.checkEjbJar(jar, "OverrideExample");
EnterpriseBeans beans = jar.getGeronimoEnterpriseBeans();
Session[] session = beans.getGeronimoSession();
assertEquals(2, session.length);
assertEquals("Stateless", session[0].getSessionType());
assertEquals("Stateful", session[1].getSessionType());
checkStateless(session[0]);
checkStateful(session[1]);
}
private void checkStateless(Session session) {
assertEquals("StatelessTest", session.getEJBName());
assertEquals("StatelessTestJNDI", session.getJndiName());
EnvEntry[] envs = session.getEnvEntry();
assertEquals(1, envs.length);
EnvEntry envEntry = envs[0];
assertEquals("Variable 1", envEntry.getEnvEntryName());
assertEquals("OverrideExample", envEntry.getEnvEntryValue());
ResourceEnvRef[] resEnvRefs = session.getGeronimoResourceEnvRef();
assertEquals(1, resEnvRefs.length);
ResourceEnvRef resEnvRef = resEnvRefs[0];
assertEquals("jdbc/StatelessDatabase",
resEnvRef.getResourceEnvRefName());
assertEquals("java:jdbc/MyDatabase", resEnvRef.getJndiName());
}
private void checkStateful(Session session) {
assertEquals("StatefulTest", session.getEJBName());
assertEquals("StatefulTestJNDI", session.getJndiName());
EjbRef[] ejbRefs = session.getGeronimoEJBRef();
assertEquals(1, ejbRefs.length);
EjbRef ejbRef = ejbRefs[0];
assertEquals("ejb/MyStateless", ejbRef.getEJBRefName());
assertNull(ejbRef.getJndiName());
ResourceEnvRef[] resEnvRefs = session.getGeronimoResourceEnvRef();
assertEquals(1, resEnvRefs.length);
ResourceEnvRef resEnvRef = resEnvRefs[0];
assertEquals("jdbc/StatefulDatabase",
resEnvRef.getResourceEnvRefName());
assertTrue("resEnvRef does not have an empty JNDI name!",
resEnvRef.getJndiName() == null || resEnvRef.getJndiName().equals(""));
}
protected void setUp() throws Exception {
docDir = new File("src/test-data/xml/deployment");
System.err.println("Current directory is
"+System.getProperty("user.dir"));
loader = new GeronimoEjbJarLoader();
}
}
1.1
incubator-geronimo/modules/core/src/test-data/xml/deployment/simple-ejb-jar.xml
Index: simple-ejb-jar.xml
===================================================================
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version="2.1">
<description>This is a test EJB JAR DD for JSR-88 purposes</description>
<display-name>Test EJB JAR</display-name>
<enterprise-beans>
<session>
<description>This is a sample stateless session bean</description>
<display-name>Stateless Session Bean</display-name>
<ejb-name>StatelessTest</ejb-name>
<home>org.apache.geronimo.enterprise.deploy.test.StatelessHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateless</remote>
<ejb-class>org.apache.geronimo.enterprise.deploy.test.StatelessBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>Variable 1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>example</env-entry-value>
</env-entry>
<resource-env-ref>
<resource-env-ref-name>jdbc/StatelessDatabase</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
</session>
<session>
<description>This is a sample stateful session bean</description>
<display-name>Stateful Session Bean</display-name>
<ejb-name>StatefulTest</ejb-name>
<home>org.apache.geronimo.enterprise.deploy.test.StatefulHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateful</remote>
<ejb-class>org.apache.geronimo.enterprise.deploy.test.StatefulBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/MyStateless</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>org.apache.geronimo.enterprise.deploy.test.StatelessHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateless</remote>
<ejb-link>Stateless</ejb-link>
</ejb-ref>
<resource-env-ref>
<resource-env-ref-name>jdbc/StatefulDatabase</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
</session>
</enterprise-beans>
</ejb-jar>
1.1
incubator-geronimo/modules/core/src/test-data/xml/deployment/simple-geronimo-ejb-jar.xml
Index: simple-geronimo-ejb-jar.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ger="http://geronimo.apache.org/xml/schema/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://geronimo.apache.org/xml/schema/1.0/j2ee14/geronimo-ejb-jar.xsd"
version="2.1">
<description>This is a test EJB JAR DD for JSR-88 purposes</description>
<display-name>Test EJB JAR</display-name>
<enterprise-beans>
<session>
<description>This is a sample stateless session bean</description>
<display-name>Stateless Session Bean</display-name>
<ejb-name>StatelessTest</ejb-name>
<home>org.apache.geronimo.enterprise.deploy.test.StatelessHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateless</remote>
<ejb-class>org.apache.geronimo.enterprise.deploy.test.StatelessBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>Variable 1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>OverrideExample</env-entry-value>
</env-entry>
<resource-env-ref>
<resource-env-ref-name>jdbc/StatelessDatabase</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
<ger:jndi-name>java:jdbc/MyDatabase</ger:jndi-name>
</resource-env-ref>
<jndi-name>StatelessTestJNDI</jndi-name>
</session>
<session>
<description>This is a sample stateful session bean</description>
<display-name>Stateful Session Bean</display-name>
<ejb-name>StatefulTest</ejb-name>
<home>org.apache.geronimo.enterprise.deploy.test.StatefulHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateful</remote>
<ejb-class>org.apache.geronimo.enterprise.deploy.test.StatefulBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/MyStateless</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>org.apache.geronimo.enterprise.deploy.test.StatelessHome</home>
<remote>org.apache.geronimo.enterprise.deploy.test.Stateless</remote>
<ejb-link>Stateless</ejb-link>
</ejb-ref>
<resource-env-ref>
<resource-env-ref-name>jdbc/StatefulDatabase</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
<ger:jndi-name></ger:jndi-name>
</resource-env-ref>
<jndi-name>StatefulTestJNDI</jndi-name>
</session>
</enterprise-beans>
</ejb-jar>