[jboss-cvs] JBossAS SVN: r57944 - in trunk/ejb3: . src/resources/test src/resources/test/appclient src/test/org/jboss/ejb3/test src/test/org/jboss/ejb3/test/appclient src/test/org/jboss/ejb3/test/appclient/client src/test/org/jboss/ejb3/test/appclient/unit
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 31 08:04:30 EST 2006
Author: wolfc
Date: 2006-10-31 08:04:19 -0500 (Tue, 31 Oct 2006)
New Revision: 57944
Added:
trunk/ejb3/src/resources/test/appclient/
trunk/ejb3/src/resources/test/appclient/Manifest
trunk/ejb3/src/resources/test/appclient/application-client.xml
trunk/ejb3/src/resources/test/appclient/application.xml
trunk/ejb3/src/resources/test/appclient/jboss-client.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/client/
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/
trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java
Modified:
trunk/ejb3/build-test.xml
Log:
EJBTHREE-718: unit test
Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/build-test.xml 2006-10-31 13:04:19 UTC (rev 57944)
@@ -724,6 +724,37 @@
</jar>
</target>
+ <target name="appclient"
+ description="Builds appclient-test.ear."
+ depends="compile-classes">
+
+ <mkdir dir="${build.lib}"/>
+
+ <jar jarfile="${build.lib}/appclient-test-client.jar" manifest="${resources}/test/appclient/Manifest">
+ <zipfileset prefix="META-INF" dir="${resources}/test/appclient">
+ <include name="application-client.xml"/>
+ <include name="jboss-client.xml"/>
+ </zipfileset>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/appclient/HelloWorldService.class"/>
+ <include name="org/jboss/ejb3/test/appclient/client/HelloWorldClient.class"/>
+ </fileset>
+ </jar>
+
+ <jar jarfile="${build.lib}/appclient-test.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/appclient/*.class"/>
+ </fileset>
+ </jar>
+
+ <ear appxml="${resources}/test/appclient/application.xml" earfile="${build.lib}/appclient-test.ear">
+ <fileset dir="${build.lib}">
+ <include name="appclient-test-client.jar"/>
+ <include name="appclient-test.jar"/>
+ </fileset>
+ </ear>
+ </target>
+
<target name="asynchronous"
description="Builds all jar files."
depends="compile-classes">
Added: trunk/ejb3/src/resources/test/appclient/Manifest
===================================================================
--- trunk/ejb3/src/resources/test/appclient/Manifest 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/resources/test/appclient/Manifest 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1 @@
+Main-Class: org.jboss.ejb3.test.appclient.client.HelloWorldClient
\ No newline at end of file
Added: trunk/ejb3/src/resources/test/appclient/application-client.xml
===================================================================
--- trunk/ejb3/src/resources/test/appclient/application-client.xml 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/resources/test/appclient/application-client.xml 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application-client xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/javaee/application-client_5.xsd"
+ version="5">
+ <display-name>appclient-test-client</display-name>
+ <description>application client unit test</description>
+
+ <env-entry>
+ <env-entry-name>msg</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>how are you?</env-entry-value>
+ </env-entry>
+
+ <resource-env-ref>
+ <resource-env-ref-name>messageReplier</resource-env-ref-name>
+ <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+ </resource-env-ref>
+
+ <post-construct>
+ <lifecycle-callback-method>postConstruct</lifecycle-callback-method>
+ </post-construct>
+
+ <pre-destroy>
+ <lifecycle-callback-method>preDestroy</lifecycle-callback-method>
+ </pre-destroy>
+
+ <callback-handler>org.jboss.ejb3.test.applicationclient.client.TestCallbackHandler</callback-handler>
+</application-client>
Added: trunk/ejb3/src/resources/test/appclient/application.xml
===================================================================
--- trunk/ejb3/src/resources/test/appclient/application.xml 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/resources/test/appclient/application.xml 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE application PUBLIC
+ "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
+ "http://java.sun.com/dtd/application_1_3.dtd">
+
+<application>
+ <display-name>EJB3 appclient test</display-name>
+
+ <module>
+ <ejb>appclient-test.jar</ejb>
+ </module>
+ <module>
+ <java>appclient-test-client.jar</java>
+ </module>
+</application>
Added: trunk/ejb3/src/resources/test/appclient/jboss-client.xml
===================================================================
--- trunk/ejb3/src/resources/test/appclient/jboss-client.xml 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/resources/test/appclient/jboss-client.xml 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss-client PUBLIC "-//JBoss//DTD Application Client 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd">
+
+<jboss-client>
+ <jndi-name>applicationclient_test</jndi-name>
+
+ <resource-env-ref>
+ <resource-env-ref-name>messageReplier</resource-env-ref-name>
+ <jndi-name>queue/messageReplier</jndi-name>
+ </resource-env-ref>
+</jboss-client>
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldBean.java 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.appclient;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(HelloWorldService.class)
+public class HelloWorldBean implements HelloWorldService
+{
+ public String sayHelloTo(String name)
+ {
+ return "Hi " + name;
+ }
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/HelloWorldService.java 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.appclient;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface HelloWorldService
+{
+ String sayHelloTo(String name);
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/MessageReplierBean.java 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.appclient;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.jboss.logging.Logger;
+
+/**
+ * This message bean will just reply the message.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue="queue/messageReplier")
+})
+public class MessageReplierBean implements MessageListener
+{
+ private static final Logger log = Logger.getLogger(MessageReplierBean.class);
+
+ @Resource(mappedName="java:ConnectionFactory")
+ private ConnectionFactory connectionFactory;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ if(message.getJMSReplyTo() != null)
+ {
+ Destination destination = message.getJMSReplyTo();
+
+ Connection conn = connectionFactory.createConnection();
+ try
+ {
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(destination);
+ producer.send(destination, message);
+ producer.close();
+ session.close();
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+ else
+ log.info("no reply to specified");
+ }
+ catch(JMSException e)
+ {
+ throw new EJBException(e);
+ }
+ }
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/client/HelloWorldClient.java 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.appclient.client;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.ejb3.test.appclient.HelloWorldService;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class HelloWorldClient
+{
+ @EJB
+ private static HelloWorldService helloWorldService;
+
+ @Resource(name="msg")
+ private static String msg;
+
+ private static String result;
+
+ @Resource(mappedName="ConnectionFactory")
+ private static ConnectionFactory connectionFactory;
+
+ @Resource(name="messageReplier")
+ private static Destination destination;
+
+ public static String getResult()
+ {
+ return result;
+ }
+
+ public static void main(String args[])
+ {
+ String name = "unspecified";
+ if(args.length > 0)
+ name = args[0];
+
+ if(helloWorldService == null)
+ throw new NullPointerException("helloWorldService is null");
+
+ if(msg == null)
+ throw new NullPointerException("msg is null");
+
+ result = helloWorldService.sayHelloTo(name) + ", " + msg;
+
+ testMDB();
+ }
+
+ public static void testMDB()
+ {
+ if(connectionFactory == null)
+ throw new NullPointerException("connectionFactory is null");
+
+ if(destination == null)
+ throw new NullPointerException("destination is null");
+
+ try
+ {
+ Connection conn = connectionFactory.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Queue replyTo = session.createTemporaryQueue();
+ TextMessage msg = session.createTextMessage("Hello world");
+ msg.setJMSReplyTo(replyTo);
+
+ MessageConsumer consumer = session.createConsumer(replyTo);
+ conn.start();
+
+ MessageProducer producer = session.createProducer(destination);
+ producer.send(destination, msg);
+
+ TextMessage reply = (TextMessage) consumer.receive(2000);
+ System.out.println("reply = " + reply.getText());
+
+ producer.close();
+ conn.stop();
+ consumer.close();
+ session.close();
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java 2006-10-31 12:35:43 UTC (rev 57943)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/appclient/unit/AppClientUnitTestCase.java 2006-10-31 13:04:19 UTC (rev 57944)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.appclient.unit;
+
+import java.net.URL;
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.client.ClientLauncher;
+import org.jboss.ejb3.metamodel.ApplicationClientDD;
+import org.jboss.ejb3.test.appclient.client.HelloWorldClient;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AppClientUnitTestCase extends JBossTestCase
+{
+ public AppClientUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void test1() throws Exception
+ {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("appclient/application-client.xml");
+ URL jbossClientURL = Thread.currentThread().getContextClassLoader().getResource("appclient/jboss-client.xml");
+ ApplicationClientDD xml = ClientLauncher.loadXML(url, jbossClientURL);
+
+ String mainClassName = HelloWorldClient.class.getName();
+ String applicationClientName = "applicationclient_test"; // must match JNDI name in jboss-client.xml or display-name in application-client.xml
+ String name = new Date().toString();
+ String args[] = { name };
+
+ ClientLauncher.launch(xml, mainClassName, applicationClientName, args);
+
+ String actual = HelloWorldClient.getResult();
+ String expected = "Hi " + name + ", how are you?";
+ assertEquals(expected, actual);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(AppClientUnitTestCase.class, "appclient-test.ear");
+ }
+}
More information about the jboss-cvs-commits
mailing list