[jboss-cvs] JBossAS SVN: r67257 - in projects/metadata/trunk/src/test: resources/org/jboss/test/metadata/ejb and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 19 12:25:27 EST 2007


Author: anil.saldhana at jboss.com
Date: 2007-11-19 12:25:27 -0500 (Mon, 19 Nov 2007)
New Revision: 67257

Added:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessBean.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessInterface.java
   projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/EjbJar3xCTSRunAsConfig.xml
   projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/JBoss42_testRunAsMerge.xml
Modified:
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar3xUnitTestCase.java
   projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJarJBossMergeEverythingUnitTestCase.java
Log:
test runas from ejb3 annotations and jboss.xml customization

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessBean.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessBean.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessBean.java	2007-11-19 17:25:27 UTC (rev 67257)
@@ -0,0 +1,44 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., 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.ejb;
+
+import javax.annotation.security.RunAs;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+//$Id$
+
+/**
+ *  A basic ejb3 bean
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Nov 19, 2007 
+ *  @version $Revision$
+ */
+ at Stateless
+ at Remote
+ at RunAs("Manager")
+public class BusinessBean
+{
+   public void noop()
+   {   
+   } 
+}

Added: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessInterface.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessInterface.java	                        (rev 0)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/BusinessInterface.java	2007-11-19 17:25:27 UTC (rev 67257)
@@ -0,0 +1,35 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, JBoss Inc., 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.ejb;
+
+//$Id$
+
+/**
+ *  Some interface
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  Nov 19, 2007 
+ *  @version $Revision$
+ */
+public interface BusinessInterface
+{
+   public void noop(); 
+}

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar3xUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar3xUnitTestCase.java	2007-11-19 17:02:14 UTC (rev 67256)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJar3xUnitTestCase.java	2007-11-19 17:25:27 UTC (rev 67257)
@@ -51,10 +51,10 @@
 import org.jboss.metadata.javaee.spec.DescriptionImpl;
 import org.jboss.metadata.javaee.spec.DisplayNameImpl;
 import org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData;
-import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
-import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
 import org.jboss.metadata.javaee.spec.IconImpl;
 import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.jboss.metadata.javaee.spec.ServiceReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ServiceReferencesMetaData;
 import org.jboss.test.metadata.javaee.AbstractJavaEEMetaDataTest;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
 
@@ -261,5 +261,4 @@
       assertTrue(businessRemotesMetaData.size()==2);
       assertTrue(businessLocalsMetaData.size()==2);
    }
-
 }

Modified: projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJarJBossMergeEverythingUnitTestCase.java
===================================================================
--- projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJarJBossMergeEverythingUnitTestCase.java	2007-11-19 17:02:14 UTC (rev 67256)
+++ projects/metadata/trunk/src/test/java/org/jboss/test/metadata/ejb/EjbJarJBossMergeEverythingUnitTestCase.java	2007-11-19 17:25:27 UTC (rev 67257)
@@ -21,24 +21,38 @@
 */
 package org.jboss.test.metadata.ejb;
 
+import java.io.File;
+import java.io.FilenameFilter;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+
 import junit.framework.Test;
 
+import org.jboss.metadata.annotation.creator.ejb.EjbJar30Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50DTDMetaData;
 import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.metadata.ejb.spec.EjbJar21MetaData;
 import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
 import org.jboss.metadata.ejb.spec.EjbJar3xMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
-import org.jboss.test.metadata.javaee.AbstractJavaEEEverythingTest.Mode;
+import org.jboss.metadata.ejb.spec.EjbJarMetaData;
+import org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData;
 import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
 
 /**
- * 
- * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * Tests the merge of ejb-jar.xml and jboss.xml
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a> 
+ * @author Anil.Saldhana at jboss.com
  * @version $Revision: 1.1 $
  */
 public class EjbJarJBossMergeEverythingUnitTestCase
@@ -54,6 +68,7 @@
       DefaultSchemaResolver resolver = new DefaultSchemaResolver();
       resolver.addClassBindingForLocation("ejb-jar_2_1.xsd", EjbJar21MetaData.class);
       resolver.addClassBindingForLocation("ejb-jar_3_0.xsd", EjbJar30MetaData.class);
+      resolver.addClassBindingForLocation("jboss_4_2.dtd", JBoss50DTDMetaData.class);
       resolver.addClassBindingForLocation("jboss_5_0.xsd", JBoss50MetaData.class);
       // 
       resolver.addClassBinding("http://www.jboss.com/xml/ns/javaee", JBoss50MetaData.class);
@@ -120,4 +135,82 @@
       JBossSessionBeanMetaData jejb = (JBossSessionBeanMetaData) ejb;
       ejbJar.assertFullSessionBean("session1", jejb, Mode.JBOSS);
    }
-}
+   
+   /**
+    * Tests the merge of EJB3 beans defining RunAs annotations internally
+    * with a ejb-jar.xml and a jboss.xml customization
+    * @throws Exception
+    */
+   public void testRunAsMerge() throws Exception 
+   {
+      //Parse the EJB3 Beans to get the EJB3 MetaData 
+      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 ejb3MetaData = creator.create(classes);
+      
+      assertTrue(ejb3MetaData.isEJB3x());
+      assertEquals("3.0", ejb3MetaData.getVersion());
+      
+      //Parse the ejb-jar.xml
+      EjbJarMetaData specResult = unmarshal("EjbJar3xCTSRunAsConfig.xml", 
+            EjbJarMetaData.class, null);
+      
+      //Parse a jboss-xml customization
+      JBossMetaData jbossxmlMetaData = unmarshal("JBoss42_testRunAsMerge.xml", 
+            JBossMetaData.class, null);
+      JBossMetaData merged = new JBossMetaData();
+      //Merge the EJB30 metadata first
+      merged.merge(ejb3MetaData, specResult);
+      //Merge the JBoss metadata
+      merged.merge(jbossxmlMetaData, specResult);
+
+      EnterpriseBeansMetaData ebsmd = specResult.getEnterpriseBeans(); 
+      assertNotNull(ebsmd);  
+      assertNotNull(specResult.getEnterpriseBean("BusinessBean")); 
+   }
+
+   private Collection<Class> loadClassesFromCurrentClassDir()
+   {
+      // In real life the deployer will pass probably pass a class scanner
+      Collection<Class> classes = new ArrayList<Class>();
+      URL currentClassDirURL = getClass().getResource(".");
+      File currentDir;
+      try
+      {
+         currentDir = new File(currentClassDirURL.toURI());
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+      String classFileNames[] = currentDir.list(new FilenameFilter() {
+         public boolean accept(File dir, String name)
+         {
+            return name.endsWith(".class");
+         }
+      });
+      if(classFileNames == null)
+         throw new RuntimeException("list failed");
+      
+      Arrays.sort(classFileNames);
+      
+      for(String classFileName : classFileNames)
+      {
+         String className = getClass().getPackage().getName() + "." + classFileName.substring(0, classFileName.length() - 6);
+         try
+         {
+            classes.add(Class.forName(className));
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      return classes;
+   } 
+}
\ No newline at end of file

Added: projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/EjbJar3xCTSRunAsConfig.xml
===================================================================
--- projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/EjbJar3xCTSRunAsConfig.xml	                        (rev 0)
+++ projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/EjbJar3xCTSRunAsConfig.xml	2007-11-19 17:25:27 UTC (rev 67257)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<ejb-jar version="3.0" 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/javaee 
+  http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"> 
+  <enterprise-beans>
+    <session>
+      <ejb-name>BusinessBean</ejb-name>
+      <business-remote>org.jboss.test.metadata.ejb.BusinessInterface</business-remote>
+      <ejb-class>org.jboss.test.metadata.ejb.BusinessBean</ejb-class>
+    </session> 
+  </enterprise-beans>
+</ejb-jar> 
\ No newline at end of file

Added: projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/JBoss42_testRunAsMerge.xml
===================================================================
--- projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/JBoss42_testRunAsMerge.xml	                        (rev 0)
+++ projects/metadata/trunk/src/test/resources/org/jboss/test/metadata/ejb/JBoss42_testRunAsMerge.xml	2007-11-19 17:25:27 UTC (rev 67257)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.2//EN" 
+              "http://www.jboss.org/j2ee/dtd/jboss_4_2.dtd">
+
+<jboss>
+  <security-domain>java:/jaas/cts</security-domain>
+  <missing-method-permissions-excluded-mode>false</missing-method-permissions-excluded-mode>
+  <webservices/>
+  <enterprise-beans>
+    <session>
+      <ejb-name>BusinessBean</ejb-name>
+      <jndi-name>jacc_mr_BusinessBean</jndi-name>
+      <call-by-value>true</call-by-value>
+      <security-identity>
+        <run-as-principal>javajoe</run-as-principal>
+      </security-identity>
+      <ior-security-config>
+        <transport-config>
+          <integrity>supported</integrity>
+          <confidentiality>supported</confidentiality>
+          <establish-trust-in-target>supported</establish-trust-in-target>
+          <establish-trust-in-client>supported</establish-trust-in-client>
+        </transport-config>
+        <as-context>
+          <auth-method>username_password</auth-method>
+          <realm>default</realm>
+          <required>true</required>
+        </as-context>
+        <sas-context>
+          <caller-propagation>supported</caller-propagation>
+        </sas-context>
+      </ior-security-config>
+    </session>
+   </enterprise-beans>
+  <assembly-descriptor>
+    <security-role>
+      <role-name>Administrator</role-name>
+      <principal-name>j2ee</principal-name>
+    </security-role>
+    <security-role>
+      <role-name>Manager</role-name>
+      <principal-name>javajoe</principal-name>
+    </security-role>
+    <security-role>
+      <role-name>Employee</role-name>
+      <principal-name>javajoe</principal-name>
+      <principal-name>j2ee</principal-name>
+    </security-role>
+  </assembly-descriptor>
+</jboss> 
\ No newline at end of file




More information about the jboss-cvs-commits mailing list