[jboss-cvs] JBossAS SVN: r72361 - projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 17 10:23:32 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-04-17 10:23:32 -0400 (Thu, 17 Apr 2008)
New Revision: 72361

Added:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyConsumer.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyProducer.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceManagement.java
Modified:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java
Log:
[JBMETA-20] Add test showing that @Service and @Consumer are not recognised

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java	2008-04-17 14:20:34 UTC (rev 72360)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/AnnotationEjb3UnitTestCase.java	2008-04-17 14:23:32 UTC (rev 72361)
@@ -41,8 +41,10 @@
 import org.jboss.metadata.common.ejb.IEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBoss50DTDMetaData;
 import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossConsumerBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossServiceBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.metadata.ejb.spec.ActivationConfigMetaData;
 import org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData;
@@ -321,6 +323,95 @@
       assertEquals("java:/mdbs/MailMDB", bean.getMappedName());
    }
 
+   private void assertMyServiceBean(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      assertTrue(enterpriseBean instanceof JBossServiceBeanMetaData);
+      
+      //TODO test the different values. This bean is based on MyStatelessSessionBean
+      JBossServiceBeanMetaData bean = (JBossServiceBeanMetaData) enterpriseBean;
+      assertEquals(SessionType.Stateless, bean.getSessionType());
+      assertEquals(MyServiceBean.class.getName(), bean.getEjbClass());
+      assertEquals("MyServiceBean", bean.getEjbName());
+      
+      assertNotNull("bean has no business locals", bean.getBusinessLocals());
+      assertEquals(1, bean.getBusinessLocals().size());
+      assertTrue(bean.getBusinessLocals().contains(MyStatelessLocal.class.getName()));
+      
+      assertNotNull("bean has no container transactions", bean.getContainerTransactions());
+      Iterator<ContainerTransactionMetaData> it = bean.getContainerTransactions().iterator();
+      ContainerTransactionMetaData tx1 = it.next();
+      assertEquals(TransactionAttributeType.NEVER, tx1.getTransAttribute());
+      // TODO: methods
+      ContainerTransactionMetaData tx2 = it.next();
+      assertEquals(TransactionAttributeType.MANDATORY, tx2.getTransAttribute());
+      MethodsMetaData tx2Methods = tx2.getMethods();
+      String[] params = {};
+      tx2Methods.matches("transactionAttributeMandatory", params, null);
+
+      // @EJB
+      AnnotatedEJBReferencesMetaData ejbRefs = bean.getAnnotatedEjbReferences();
+      assertEquals(2, ejbRefs.size());
+      AnnotatedEJBReferenceMetaData injectedField = ejbRefs.get("injectedField");
+      assertNotNull(injectedField);
+      assertEquals(MyStatelessLocal.class, injectedField.getBeanInterface());
+      AnnotatedEJBReferenceMetaData injectedFieldWithOverridenName = ejbRefs.get("overrideName");
+      assertNotNull(injectedFieldWithOverridenName);
+      assertEquals(MyStatelessLocal.class, injectedFieldWithOverridenName.getBeanInterface());
+      // @PostConstruct
+      LifecycleCallbacksMetaData postConstructs = bean.getPostConstructs();
+      assertNotNull(postConstructs);
+      assertEquals(1, postConstructs.size());
+      LifecycleCallbackMetaData postConstruct = postConstructs.get(0);
+      assertEquals("setUp", postConstruct.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), postConstruct.getClassName());
+      // @PreDestroy
+      LifecycleCallbacksMetaData preDestroys = bean.getPreDestroys();
+      assertNotNull(preDestroys);
+      assertEquals(1, preDestroys.size());
+      LifecycleCallbackMetaData preDestroy = preDestroys.get(0);
+      assertEquals("tearDown", preDestroy.getMethodName());
+      assertEquals(MyStatelessBean.class.getName(), preDestroy.getClassName());
+
+      // @RunAs
+      SecurityIdentityMetaData identity = bean.getSecurityIdentity();
+      assertNotNull(identity);
+      RunAsMetaData runAs = identity.getRunAs();
+      assertNotNull(runAs);
+      assertEquals("InternalUser", runAs.getRoleName());
+
+      // @AroundInvoke
+      AroundInvokesMetaData invokes = bean.getAroundInvokes();
+      assertNotNull(invokes);
+      assertEquals(1, invokes.size());
+      AroundInvokeMetaData aroundInvoke = invokes.get(0);
+      assertEquals(MyStatelessBean.class.getName(), aroundInvoke.getClassName());
+      assertEquals("intercept", aroundInvoke.getMethodName());
+   }
+
+   private void assertMyConsumer(IEnterpriseBeanMetaData enterpriseBean)
+   {
+      //TODO test the different values. This bean is based on MyMDB
+      JBossConsumerBeanMetaData bean = (JBossConsumerBeanMetaData) enterpriseBean;
+      assertEquals(MyConsumer.class.getName(), bean.getEjbClass());
+      assertEquals("MyConsumer", bean.getEjbName());
+      //assertEquals(false, bean.isJMS());
+      //assertEquals(IMailListener.class.getName(), bean.getMessagingType());
+      //ActivationConfigMetaData config = bean.getActivationConfig();
+      ActivationConfigMetaData expected = new ActivationConfigMetaData();
+      ActivationConfigPropertiesMetaData props = new ActivationConfigPropertiesMetaData();
+      ActivationConfigPropertyMetaData p1 = new ActivationConfigPropertyMetaData();
+      p1.setName("p1");
+      p1.setValue("v1");
+      props.add(p1);
+      ActivationConfigPropertyMetaData p2 = new ActivationConfigPropertyMetaData();
+      p2.setName("p2");
+      p2.setValue("v2");
+      props.add(p2);
+      expected.setActivationConfigProperties(props);
+      //assertEquals(expected, config);
+      //assertEquals("java:/mdbs/MailMDB", bean.getMappedName());
+   }
+
    private Collection<Class<?>> loadClassesFromCurrentClassDir()
    {
       return loadClassesFromRelativeClassDir(".");
@@ -504,6 +595,35 @@
       }      
    }
 
+   public void testEJBExtensions()
+   {
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      
+      Collection<Class<?>> classes = loadClassesFromCurrentClassDir();
+      System.out.println("Processing classes: "+classes);
+
+      //enableTrace("org.jboss.metadata.annotation.creator");
+      EjbJar30Creator creator = new EjbJar30Creator(finder);
+      
+      EjbJar30MetaData metaData = creator.create(classes);
+      
+      assertTrue(metaData.isEJB3x());
+      assertEquals("3.0", metaData.getVersion());
+      
+      assertNotNull("no beans defined", metaData.getEnterpriseBeans());
+      assertNotNull("no assembly descriptor defined", metaData.getAssemblyDescriptor());
+      
+      // There is a bug in IdMetaDataImpl.hashCode which isn't unique when id is not set.
+      for(ContainerTransactionMetaData transaction : metaData.getAssemblyDescriptor().getContainerTransactions())
+      {
+         System.out.println(transaction);
+      }
+      
+      assertEquals(8, metaData.getEnterpriseBeans().size());
+      assertMyServiceBean(metaData.getEnterpriseBean("MyService"));
+      assertMyConsumer(metaData.getEnterpriseBean("MyConsumer"));
+   }
+   
    /**
     * Test merging annotation and xml based metadata
     * @throws Exception

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyConsumer.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyConsumer.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyConsumer.java	2008-04-17 14:23:32 UTC (rev 72361)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.metadata.annotation.ejb3;
+
+import javax.ejb.ActivationConfigProperty;
+
+import org.jboss.ejb3.annotation.Consumer;
+import org.jboss.ejb3.annotation.Producer;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Consumer(
+      name="MyConsumer",
+      activationConfig={
+            @ActivationConfigProperty(propertyName="prop1", propertyValue="value1"),
+            @ActivationConfigProperty(propertyName="prop2", propertyValue="value2")
+      }
+)
+ at Producer(producer=MyProducer.class)
+public class MyConsumer implements MyProducer 
+{
+   public void test() {}
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyProducer.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyProducer.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyProducer.java	2008-04-17 14:23:32 UTC (rev 72361)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.metadata.annotation.ejb3;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MyProducer
+{
+   void test();
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceBean.java	2008-04-17 14:23:32 UTC (rev 72361)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.test.metadata.annotation.ejb3;
+
+import java.net.URL;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.annotation.security.DeclareRoles;
+import javax.annotation.security.DenyAll;
+import javax.annotation.security.PermitAll;
+import javax.annotation.security.RolesAllowed;
+import javax.annotation.security.RunAs;
+import javax.ejb.EJB;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.jms.Queue;
+import javax.sql.DataSource;
+
+import org.jboss.ejb3.annotation.Management;
+import org.jboss.ejb3.annotation.Service;
+
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 67999 $
+ */
+ at SuppressWarnings("unused")
+ at Service(objectName="test:service=mine", name="MyService")
+ at Management(Management.class)
+ at TransactionAttribute(TransactionAttributeType.NEVER)
+ at Resources({
+   @Resource(description="url-resource-ref", name="googleHome", type=java.net.URL.class, mappedName="http://www.google.com"),
+   @Resource(description="DataSource-resource-ref", name="jdbc/ds", type=DataSource.class, mappedName="java:/DefaultDS")
+})
+ at DeclareRoles(value={"Role1","Role2"})
+ at RunAs("InternalUser")
+ at Interceptors(TestClassInterceptor.class)
+ at ExcludeDefaultInterceptors
+public class MyServiceBean implements MyServiceManagement
+{
+   @EJB
+   private MyStatelessLocal injectedField;
+   @Resource(description="SessionContext-resource-env-ref")
+   private SessionContext context;
+
+   @Resource(description="string-env-entry")
+   private String sfield;
+   private URL homePage;
+   private URL googleHome;
+   private Queue mailQueue;
+   private double pi;
+
+   @EJB(name="overrideName")
+   private MyStatelessLocal injectedFieldWithOverridenName;
+   
+   @TransactionAttribute(TransactionAttributeType.MANDATORY)
+   public void transactionAttributeMandatory()
+   {
+      
+   }
+
+   public URL getHomePage()
+   {
+      return homePage;
+   }
+   @Resource(description="url-resource-ref2")
+   public void setHomePage(URL homePage)
+   {
+      this.homePage = homePage;
+   }
+
+   public Queue getMailQueue()
+   {
+      return mailQueue;
+   }
+   @Resource(description="message-destination-ref")
+   public void setMailQueue(Queue mailQueue)
+   {
+      this.mailQueue = mailQueue;
+   }
+
+   public double getPi()
+   {
+      return pi;
+   }
+   @Resource(description="pi-env-entry", mappedName="3.14159")
+   public void setPi(double pi)
+   {
+      this.pi = pi;
+   }
+
+   @PostConstruct
+   public void setUp()
+   {
+      
+   }
+   @PreDestroy
+   public void tearDown()
+   {
+   }
+
+   @DenyAll
+   public void denyAll()
+   {      
+   }
+   
+   @DenyAll
+   public void excluded()
+   {      
+   }
+
+   @PermitAll
+   public void permitAll()
+   {
+   }
+
+   @RolesAllowed({"AccessRole1", "AccessRole2"})
+   public void rolesAllowed()
+   {
+   }
+
+   @AroundInvoke
+   public Object intercept(InvocationContext ctx) throws Exception
+   {
+      System.out.println("**** intercept ****" + ctx.getMethod().getName());
+      return ctx.proceed();
+   }
+
+   @ExcludeClassInterceptors
+   @ExcludeDefaultInterceptors
+   @Interceptors(TestMethodInterceptor.class)
+   public Object intercept2(InvocationContext ctx) throws Exception
+   {
+      System.out.println("**** intercept2 ****" + ctx.getMethod().getName());
+      return ctx.proceed();
+   }
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceManagement.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceManagement.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/annotation/ejb3/MyServiceManagement.java	2008-04-17 14:23:32 UTC (rev 72361)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.test.metadata.annotation.ejb3;
+
+import javax.ejb.Local;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 65638 $
+ */
+public interface MyServiceManagement
+{
+   
+}




More information about the jboss-cvs-commits mailing list