[jboss-cvs] JBossAS SVN: r81486 - in trunk/testsuite: src/main/org/jboss/test/ejb3 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 24 08:52:12 EST 2008


Author: wolfc
Date: 2008-11-24 08:52:11 -0500 (Mon, 24 Nov 2008)
New Revision: 81486

Added:
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/MyStateless.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/QueueTestMDB.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/StatelessBean.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/unit/
   trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/unit/RunAsMDBUnitTestCase.java
   trunk/testsuite/src/resources/ejb3/
   trunk/testsuite/src/resources/ejb3/jbas6239/
   trunk/testsuite/src/resources/ejb3/jbas6239/roles.properties
   trunk/testsuite/src/resources/ejb3/jbas6239/test-destinations-service.xml
   trunk/testsuite/src/resources/ejb3/jbas6239/users.properties
Modified:
   trunk/testsuite/imports/sections/ejb3.xml
Log:
JBAS-6239: unit test

Modified: trunk/testsuite/imports/sections/ejb3.xml
===================================================================
--- trunk/testsuite/imports/sections/ejb3.xml	2008-11-24 12:46:33 UTC (rev 81485)
+++ trunk/testsuite/imports/sections/ejb3.xml	2008-11-24 13:52:11 UTC (rev 81486)
@@ -17,7 +17,19 @@
       </jar>
    </target>
    
-	<target name="_jars-ejb3" depends="jbas6161">
+   <target name="jbas6239" depends="compile">
+      <mkdir dir="${build.lib}" />
+      
+      <jar destfile="${build.lib}/jbas6239.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/ejb3/jbas6239/**" />
+         </fileset>
+         <fileset dir="${source.resources}/ejb3/jbas6239" includes="**">
+         </fileset>
+      </jar>
+   </target>
+   
+	<target name="_jars-ejb3" depends="jbas6161,jbas6239">
 		<mkdir dir="${build.lib}" />
 
 		<!-- A jar with a simple ejb3 session -->

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/MyStateless.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/MyStateless.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/MyStateless.java	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.ejb3.jbas6239;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MyStateless
+{
+   String getState();
+   
+   void setState(String state);
+}

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/QueueTestMDB.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/QueueTestMDB.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/QueueTestMDB.java	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.ejb3.jbas6239;
+
+import javax.annotation.Resource;
+import javax.annotation.security.RunAs;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+
+import org.jboss.ejb3.annotation.Depends;
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+   @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+   @ActivationConfigProperty(propertyName="destination", propertyValue="queue/mdbtest")
+})
+ at RunAs("TestRole")
+ at SecurityDomain(value="other",unauthenticatedPrincipal="user")
+ at Depends("jboss.mq.destination:name=mdbtest,service=Queue")
+public class QueueTestMDB implements MessageListener
+{
+   @Resource(mappedName="java:/ConnectionFactory")
+   private QueueConnectionFactory qFactory;
+   
+   @EJB
+   MyStateless bean;
+   
+   public void onMessage(Message message)
+   {
+      try
+      {
+         try
+         {
+            bean.setState(((TextMessage) message).getText());
+            sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID());
+         }
+         catch(Exception e)
+         {
+            sendReply((Queue) message.getJMSReplyTo(), message.getJMSMessageID(), e);
+         }
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   private void sendReply(Queue destination, String messageID) throws JMSException
+   {
+      QueueConnection conn = qFactory.createQueueConnection();
+      try
+      {
+         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         QueueSender sender = session.createSender(destination);
+         TextMessage message = session.createTextMessage("SUCCESS");
+         message.setJMSCorrelationID(messageID);
+         sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+   
+   private void sendReply(Queue destination, String messageID, Exception e) throws JMSException
+   {
+      QueueConnection conn = qFactory.createQueueConnection();
+      try
+      {
+         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         QueueSender sender = session.createSender(destination);
+         ObjectMessage message = session.createObjectMessage(e);
+         message.setJMSCorrelationID(messageID);
+         sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/StatelessBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/StatelessBean.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/StatelessBean.java	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.ejb3.jbas6239;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.annotation.SecurityDomain;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(MyStateless.class)
+ at SecurityDomain("other")
+public class StatelessBean implements MyStateless
+{
+   // static so it's shared by all
+   private static String state;
+   
+   @RolesAllowed("anyone")
+   public String getState()
+   {
+      return state;
+   }
+   
+   @RolesAllowed("TestRole")
+   public void setState(String state)
+   {
+      StatelessBean.state = state;
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/unit/RunAsMDBUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/unit/RunAsMDBUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/jbas6239/unit/RunAsMDBUnitTestCase.java	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.ejb3.jbas6239.unit;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Make sure the run-as on a MDB is picked up.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RunAsMDBUnitTestCase extends JBossTestCase
+{
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(RunAsMDBUnitTestCase.class, "jbas6239.jar");
+   }
+
+   public RunAsMDBUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected <T> T lookup(String name, Class<T> cls) throws Exception
+   {
+      return cls.cast(getInitialContext().lookup(name));
+   }
+   
+   public void testSendMessage() throws Exception
+   {
+      ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
+      Connection conn = connFactory.createConnection();
+      conn.start();
+      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue replyQueue = session.createTemporaryQueue();
+      TextMessage msg = session.createTextMessage("Hello world");
+      msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+      msg.setJMSReplyTo(replyQueue);
+      Queue queue = lookup("queue/mdbtest", Queue.class);
+      MessageProducer producer = session.createProducer(queue);
+      producer.send(msg);
+      MessageConsumer consumer = session.createConsumer(replyQueue);
+      Message replyMsg = consumer.receive(5000);
+      assertNotNull(replyMsg);
+      if(replyMsg instanceof ObjectMessage)
+      {
+         Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
+         throw e;
+      }
+      assertInstanceOf(replyMsg, TextMessage.class);
+      String actual = ((TextMessage) replyMsg).getText();
+      assertEquals("SUCCESS", actual);
+      
+      // TODO: check stateless.state
+      
+      consumer.close();
+      producer.close();
+      session.close();
+      conn.stop();
+   }
+   
+   public void testServerFound() throws Exception
+   {
+      serverFound();
+   }
+}

Added: trunk/testsuite/src/resources/ejb3/jbas6239/roles.properties
===================================================================
--- trunk/testsuite/src/resources/ejb3/jbas6239/roles.properties	                        (rev 0)
+++ trunk/testsuite/src/resources/ejb3/jbas6239/roles.properties	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,2 @@
+user=TestRole
+anyone=anyone
\ No newline at end of file

Added: trunk/testsuite/src/resources/ejb3/jbas6239/test-destinations-service.xml
===================================================================
--- trunk/testsuite/src/resources/ejb3/jbas6239/test-destinations-service.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/ejb3/jbas6239/test-destinations-service.xml	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+  <mbean code="org.jboss.mq.server.jmx.Queue"
+    name="jboss.mq.destination:service=Queue,name=mdbtest">
+    <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+  </mbean>
+</server>
\ No newline at end of file

Added: trunk/testsuite/src/resources/ejb3/jbas6239/users.properties
===================================================================
--- trunk/testsuite/src/resources/ejb3/jbas6239/users.properties	                        (rev 0)
+++ trunk/testsuite/src/resources/ejb3/jbas6239/users.properties	2008-11-24 13:52:11 UTC (rev 81486)
@@ -0,0 +1,2 @@
+user=password
+anyone=anyone
\ No newline at end of file




More information about the jboss-cvs-commits mailing list