Author: dblevins
Date: Sat Jul 21 02:43:39 2012
New Revision: 1364034
URL: http://svn.apache.org/viewvc?rev=1364034&view=rev
Log:
OPENEJB-1876 - <ejb-jar id="foo"/> id ignored when ejb-jar contains no child
elements
OPENEJB-1471 - Meta: @MessageDriven
OPENEJB-1483 - Meta: @Stateless
OPENEJB-1479 - Meta: @Singleton
OPENEJB-1481 - Meta: @Stateful
OPENEJB-1488 - Meta: @ManagedBean
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbModuleIdTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/ManagedBeanMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MessageDrivenMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/SingletonMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatelessMetaTest.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StartupMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulTimeoutMetaTest.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Sat Jul 21 02:43:39 2012
@@ -4787,7 +4787,8 @@ public class AnnotationDeployer implemen
private <A extends Annotation> A getInheritableAnnotation(Class clazz,
Class<A> annotationClass) {
if (clazz == null || clazz.equals(Object.class)) return null;
- Annotation annotation = clazz.getAnnotation(annotationClass);
+ final MetaAnnotatedClass meta = new MetaAnnotatedClass(clazz);
+ Annotation annotation = meta.getAnnotation(annotationClass);
if (annotation != null) {
return (A) annotation;
}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
Sat Jul 21 02:43:39 2012
@@ -17,17 +17,21 @@
package org.apache.openejb.config;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.openejb.loader.SystemInstance;
import org.apache.xbean.finder.Annotated;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.IAnnotationFinder;
+import org.apache.xbean.finder.archive.Archive;
import org.apache.xbean.finder.archive.ClassesArchive;
import org.apache.xbean.finder.archive.ClasspathArchive;
@@ -54,12 +58,7 @@ public class FinderFactory {
if (module instanceof WebModule) {
WebModule webModule = (WebModule) module;
final AnnotationFinder annotationFinder = new AnnotationFinder(new
WebappAggregatedArchive(webModule, webModule.getScannableUrls()));
- if (annotationFinder.hasMetaAnnotations()) {
- annotationFinder.enableMetaAnnotations();
- }
- if (enableFindSubclasses()) {
- annotationFinder.enableFindSubclasses();
- }
+ enableFinderOptions(annotationFinder);
finder = annotationFinder;
} else if (module instanceof ConnectorModule) {
ConnectorModule connectorModule = (ConnectorModule) module;
@@ -81,9 +80,13 @@ public class FinderFactory {
}
if (module instanceof Module) {
- finder = new AnnotationFinder(new
ConfigurableClasspathArchive((Module) module, url)).link();
+ final AnnotationFinder annotationFinder = new
AnnotationFinder(new DebugArchive(new ConfigurableClasspathArchive((Module)
module, url)));
+ enableFinderOptions(annotationFinder);
+ finder = annotationFinder.link();
} else {
- finder = new AnnotationFinder(new
ConfigurableClasspathArchive(module.getClassLoader(), url)).link();
+ final AnnotationFinder annotationFinder = new
AnnotationFinder(new DebugArchive(new
ConfigurableClasspathArchive(module.getClassLoader(), url)));
+ enableFinderOptions(annotationFinder);
+ finder = annotationFinder.link();
}
} else {
finder = new AnnotationFinder(new ClassesArchive()).link();
@@ -92,6 +95,44 @@ public class FinderFactory {
return new ModuleLimitedFinder(finder);
}
+ private static class DebugArchive implements Archive {
+ private final Archive archive;
+
+ private DebugArchive(Archive archive) {
+ this.archive = archive;
+ }
+
+ @Override
+ public Iterator<Entry> iterator() {
+ return archive.iterator();
+ }
+
+ @Override
+ public InputStream getBytecode(String s) throws IOException,
ClassNotFoundException {
+ return archive.getBytecode(s);
+ }
+
+ @Override
+ public Class<?> loadClass(String s) throws ClassNotFoundException {
+ try {
+ return archive.loadClass(s);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+ }
+ private AnnotationFinder enableFinderOptions(AnnotationFinder
annotationFinder) {
+ annotationFinder.enableMetaAnnotations();
+ if (annotationFinder.hasMetaAnnotations()) {
+ }
+ if (enableFindSubclasses()) {
+ annotationFinder.enableFindSubclasses();
+ }
+
+ return annotationFinder;
+ }
+
private static boolean enableFindSubclasses() {
return isJaxRsInstalled() &&
SystemInstance.get().getOptions().get(TOMEE_JAXRS_DEPLOY_UNDECLARED_PROP,
false);
}
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Sat Jul 21 02:43:39 2012
@@ -541,7 +541,10 @@ public class ReadDescriptors implements
public static EjbJar readEjbJar(final InputStream is) throws
OpenEJBException {
try {
final String content = IO.slurp(is);
- if (isEmptyEjbJar(new ByteArrayInputStream(content.getBytes())))
return new EjbJar();
+ if (isEmptyEjbJar(new ByteArrayInputStream(content.getBytes()))) {
+ final String id = getId(new
ByteArrayInputStream(content.getBytes()));
+ return new EjbJar(id);
+ }
return (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class, new
ByteArrayInputStream(content.getBytes()));
} catch (SAXException e) {
throw new OpenEJBException("Cannot parse the ejb-jar.xml"); //
file: " + url.toExternalForm(), e);
@@ -603,6 +606,33 @@ public class ReadDescriptors implements
}
}
+ private static String getId(final InputStream is) {
+ final String[] id = {null};
+
+ try {
+ final LengthInputStream in = new LengthInputStream(is);
+ InputSource inputSource = new InputSource(in);
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setValidating(false);
+ SAXParser parser = factory.newSAXParser();
+
+ parser.parse(inputSource, new DefaultHandler() {
+ public void startElement(String uri, String localName, String
qName, Attributes att) throws SAXException {
+ id[0] = att.getValue("id");
+ }
+
+ public InputSource resolveEntity(String publicId, String
systemId) throws IOException, SAXException {
+ return new InputSource(new ByteArrayInputStream(new
byte[0]));
+ }
+ });
+ } catch (Exception e) {
+ }
+
+ return id[0];
+ }
+
public static Webservices readWebservices(URL url) throws OpenEJBException
{
Webservices webservices;
try {
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
Sat Jul 21 02:43:39 2012
@@ -302,10 +302,10 @@ public class ApplicationComposer extends
final InjectionProcessor processor = new
InjectionProcessor(testInstance, context.getInjections(),
context.getJndiContext());
processor.createInstance();
- load("org.apache.webbeans.component.AbstractOwbBean");
- load("sun.security.pkcs11.SunPKCS11");
- load("sun.security.pkcs11.SunPKCS11$Descriptor");
- load("sun.security.pkcs11.wrapper.PKCS11Exception");
+//
load("org.apache.webbeans.component.AbstractOwbBean");
+// load("sun.security.pkcs11.SunPKCS11");
+// load("sun.security.pkcs11.SunPKCS11$Descriptor");
+// load("sun.security.pkcs11.wrapper.PKCS11Exception");
try {
OWBInjector beanInjector = new
OWBInjector(appContext.getWebBeansContext());
beanInjector.inject(testInstance);
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbModuleIdTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbModuleIdTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbModuleIdTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/EjbModuleIdTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.config;
+
+import junit.framework.Assert;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.Archives;
+import org.junit.Test;
+
+import javax.ejb.Singleton;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * OPENEJB-1442
+ *
+ * @version $Rev$ $Date$
+ */
+public class EjbModuleIdTest extends Assert {
+
+ @Test
+ public void testDefault() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar/>");
+
+ final File file = Archives.jarArchive(map, "test", OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals(file.getName().substring(0, file.getName().length() - 4),
ejbJarInfo.moduleName);
+ }
+
+ @Test
+ public void testId() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"orange\"/>");
+
+ final File file = Archives.jarArchive(map, "test", OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals("orange", ejbJarInfo.moduleName);
+ }
+
+ @Test
+ public void testModuleName() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml",
"<ejb-jar><module-name>orange</module-name></ejb-jar>");
+
+ final File file = Archives.jarArchive(map, "test", OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals("orange", ejbJarInfo.moduleName);
+ }
+
+
+ @Test
+ public void testModuleNameAndId() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar
id=\"orangeId\"><module-name>orangeName</module-name></ejb-jar>");
+
+ final File file = Archives.jarArchive(map, "test", OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals("orangeName", ejbJarInfo.moduleName);
+ }
+
+ /**
+ * OPENEJB-1555
+ * @throws Exception
+ */
+ @Test
+ public void testSystemProperty() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar
id=\"orangeId\"><module-name>orangeName</module-name></ejb-jar>");
+
+ final File file = Archives.jarArchive(map, "test", OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+
+ SystemInstance.get().setProperty(file.getName() + ".moduleId",
"orangeSystem");
+
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals("orangeSystem", ejbJarInfo.moduleName);
+ }
+
+ /**
+ * OPENEJB-1366
+ * @throws Exception
+ */
+ @Test
+ public void testInvalidNames() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar/>");
+
+ final List<String> dirs = new ArrayList<String>();
+ dirs.add("orangeDir");
+ dirs.add("classes"); // invalid
+ dirs.add("test-classes"); // invalid
+ dirs.add("target"); // invalid
+ dirs.add("build"); // invalid
+ dirs.add("dist"); // invalid
+ dirs.add("bin"); // invalid
+
+ final File file = Archives.fileArchive(map, dirs, OrangeBean.class);
+
+ final Assembler assembler = new Assembler();
+ final ConfigurationFactory factory = new ConfigurationFactory();
+ final AppInfo appInfo = factory.configureApplication(file);
+ final EjbJarInfo ejbJarInfo = appInfo.ejbJars.get(0);
+
+ assertEquals("orangeDir", ejbJarInfo.moduleName);
+ }
+
+
+ @Singleton
+ public static class OrangeBean {
+
+ }
+}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/ManagedBeanMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/ManagedBeanMetaTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/ManagedBeanMetaTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/ManagedBeanMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.meta;
+
+import org.junit.runner.RunWith;
+
+import javax.annotation.ManagedBean;
+import javax.ejb.LocalBean;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@RunWith(MetaRunner.class)
+public class ManagedBeanMetaTest {
+
+ @MetaTest(expected = ExpectedBean.class, actual = ActualBean.class)
+ public void test() {
+ }
+
+
+ @ManagedBean
+ @Metatype
+ @Target({ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface ContainerControlled {
+ }
+
+ /**
+ * Standard bean
+ */
+ @ManagedBean
+ @LocalBean
+ public static class ExpectedBean implements Bean {
+ }
+
+ /**
+ * Meta bean
+ */
+ @ContainerControlled
+ @LocalBean
+ public static class ActualBean implements Bean {
+ }
+
+
+ public static interface Bean {
+ }
+
+}
\ No newline at end of file
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MessageDrivenMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MessageDrivenMetaTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MessageDrivenMetaTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MessageDrivenMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.meta;
+
+import org.junit.runner.RunWith;
+
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@RunWith(MetaRunner.class)
+public class MessageDrivenMetaTest {
+
+ @MetaTest(expected = ExpectedBean.class, actual = ActualBean.class)
+ public void test() {
+ }
+
+
+ @MessageDriven
+ @Metatype
+ @Target({ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface MessageConsumer {
+ }
+
+ /**
+ * Standard bean
+ */
+ @MessageDriven
+ public static class ExpectedBean implements MessageListener {
+ @Override
+ public void onMessage(Message message) {
+ }
+ }
+
+ /**
+ * Meta bean
+ */
+ @MessageConsumer
+ public static class ActualBean implements MessageListener {
+ @Override
+ public void onMessage(Message message) {
+ }
+ }
+}
\ No newline at end of file
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MetaTest.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MetaTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/MetaTest.java
Sat Jul 21 02:43:39 2012
@@ -22,6 +22,8 @@ import org.apache.openejb.assembler.clas
import org.apache.openejb.assembler.classic.ContainerSystemInfo;
import org.apache.openejb.assembler.classic.FacilitiesInfo;
import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
import org.apache.openejb.config.AppModule;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.EjbModule;
@@ -36,18 +38,27 @@ import org.apache.openejb.jee.StatefulBe
import org.apache.openejb.jee.StatelessBean;
import org.apache.openejb.jee.oejb3.OpenejbJar;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.Archives;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.MetaAnnotatedClass;
+import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import javax.xml.bind.JAXBException;
+import java.io.File;
+import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import static junit.framework.Assert.assertEquals;
+import static
org.apache.openejb.config.DeploymentFilterable.DEPLOYMENTS_CLASSPATH_PROPERTY;
/**
* @version $Rev$ $Date$
@@ -77,7 +88,17 @@ public @interface MetaTest {
public void evaluate() throws Throwable {
MetaTest annotation = testMethod.getAnnotation(MetaTest.class);
+ if (isSpecificBeanType(annotation)) {
+ testOnce(annotation);
+
+ } else {
+
+ testAsAllBeanTypes(annotation);
+ }
+ }
+
+ private void testAsAllBeanTypes(MetaTest annotation) throws Throwable {
Class<? extends EnterpriseBean>[] classes = annotation.types();
// for some reason these defaults do not work in the annotation
@@ -115,9 +136,97 @@ public @interface MetaTest {
}
}
+ private void testOnce(MetaTest annotation) throws Throwable {
+
+ try {
+
+ SystemInstance.reset();
+
SystemInstance.get().setProperty(DEPLOYMENTS_CLASSPATH_PROPERTY, "false");
+
+ Assembler assembler = new Assembler();
+ ConfigurationFactory factory = new ConfigurationFactory();
+
assembler.createTransactionManager(factory.configureService(TransactionServiceInfo.class));
+
assembler.createSecurityService(factory.configureService(SecurityServiceInfo.class));
+
+ final ArrayList<File> files = new ArrayList<File>();
+
+ { // expected archive
+ final HashMap map = new HashMap();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar
id=\"expected\"/>");
+ files.add(Archives.jarArchive(map, "expected",
annotation.expected()));
+ }
+
+ { // actual archive
+ final HashMap map = new HashMap();
+ map.put("META-INF/ejb-jar.xml", "<ejb-jar
id=\"actual\"/>");
+ files.add(Archives.jarArchive(map, "actual",
getClasses(annotation)));
+ }
+
+ final AppModule app =
factory.loadApplication(this.getClass().getClassLoader(), "test", files);
+
+ OpenEjbConfiguration conf = factory.getOpenEjbConfiguration();
+
+ factory.configureApplication(app);
+
+ EjbJar expected = getDescriptor(app, "expected");
+ EjbJar actual = getDescriptor(app, "actual");
+ final String expectedXml = toString(expected);
+ final String actualXml = toString(actual).replaceAll("Actual",
"Expected").replaceAll("actual", "expected");
+ assertEquals(expectedXml, actualXml);
+ } catch (Exception e) {
+ throw new AssertionError().initCause(e);
+ }
+ }
+
+ private Class[] getClasses(MetaTest annotation) {
+ final Class clazz = annotation.actual();
+
+ final List<Class> classes = new ArrayList<Class>();
+
+ getClasses(clazz, classes);
+
+ return classes.toArray(new Class[]{});
+ }
+
+ private void getClasses(Class clazz, List<Class> classes) {
+ if (classes.contains(clazz)) return;
+ classes.add(clazz);
+
+ final Annotation[] annotations = clazz.getAnnotations();
+ for (Annotation ann : annotations) {
+ final Class<? extends Annotation> type = ann.annotationType();
+ final String name = type.getName();
+ if (name.startsWith("javax.")) continue;
+ if (name.startsWith("java.")) continue;
+
+ getClasses(type, classes);
+ }
+ }
+
+ private EjbJar getDescriptor(AppModule app, String name) {
+ for (EjbModule ejbModule : app.getEjbModules()) {
+ if (name.equals(ejbModule.getModuleId())) {
+ return ejbModule.getEjbJar();
+ }
+ }
+ throw new RuntimeException("Test setup failed, no such module: " +
name);
+ }
+
+ private boolean isSpecificBeanType(MetaTest annotation) {
+ Class<? extends Annotation>[] annotations = new
Class[]{javax.ejb.Singleton.class, javax.ejb.Stateless.class,
javax.ejb.Stateful.class, javax.ejb.MessageDriven.class};
+ for (Class<? extends Annotation> compDef : annotations) {
+ if (annotation.expected().isAnnotationPresent(compDef)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private ConfigurationFactory factory() {
try {
SystemInstance.reset();
+
SystemInstance.get().setProperty(DEPLOYMENTS_CLASSPATH_PROPERTY, "false");
Assembler assembler = new Assembler();
ConfigurationFactory factory = new ConfigurationFactory();
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/SingletonMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/SingletonMetaTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/SingletonMetaTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/SingletonMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.meta;
+
+import org.junit.runner.RunWith;
+
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@RunWith(MetaRunner.class)
+public class SingletonMetaTest {
+
+ @MetaTest(expected = ExpectedBean.class, actual = ActualBean.class)
+ public void test() {
+ }
+
+
+ @Singleton
+ @Metatype
+ @Target({ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface JustOne {
+ }
+
+ /**
+ * Standard bean
+ */
+ @Singleton
+ public static class ExpectedBean implements Bean {
+ }
+
+ /**
+ * Meta bean
+ */
+ @JustOne
+ public static class ActualBean implements Bean {
+ }
+
+
+ public static interface Bean {
+ }
+
+}
\ No newline at end of file
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StartupMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StartupMetaTest.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StartupMetaTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StartupMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -16,7 +16,6 @@
*/
package org.apache.openejb.meta;
-import org.junit.Test;
import org.junit.runner.RunWith;
import javax.ejb.Startup;
@@ -46,8 +45,7 @@ public class StartupMetaTest {
/**
* Standard bean
*/
-// TODO
-// @Startup
+ @Startup
public static class ExpectedBean implements Bean {
}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulMetaTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulMetaTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.meta;
+
+import org.junit.runner.RunWith;
+
+import javax.ejb.Stateful;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@RunWith(MetaRunner.class)
+public class StatefulMetaTest {
+
+ @MetaTest(expected = ExpectedBean.class, actual = ActualBean.class)
+ public void test() {
+ }
+
+
+ @Stateful
+ @Metatype
+ @Target({ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface Dedicated {
+ }
+
+ /**
+ * Standard bean
+ */
+ @Stateful
+ public static class ExpectedBean implements Bean {
+ }
+
+ /**
+ * Meta bean
+ */
+ @Dedicated
+ public static class ActualBean implements Bean {
+ }
+
+
+ public static interface Bean {
+ }
+
+}
\ No newline at end of file
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulTimeoutMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulTimeoutMetaTest.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulTimeoutMetaTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatefulTimeoutMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -45,8 +45,7 @@ public class StatefulTimeoutMetaTest {
/**
* Standard bean
*/
-// TODO
-// @StatefulTimeout(value = -1)
+ @StatefulTimeout(value = -1)
public static class ExpectedBean implements Bean {
}
Added:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatelessMetaTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatelessMetaTest.java?rev=1364034&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatelessMetaTest.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/meta/StatelessMetaTest.java
Sat Jul 21 02:43:39 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.meta;
+
+import org.junit.runner.RunWith;
+
+import javax.ejb.Stateless;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@RunWith(MetaRunner.class)
+public class StatelessMetaTest {
+
+ @MetaTest(expected = ExpectedBean.class, actual = ActualBean.class)
+ public void test() {
+ }
+
+
+ @Stateless
+ @Metatype
+ @Target({ElementType.TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface Pooled {
+ }
+
+ /**
+ * Standard bean
+ */
+ @Stateless
+ public static class ExpectedBean implements Bean {
+ }
+
+ /**
+ * Meta bean
+ */
+ @Pooled
+ public static class ActualBean implements Bean {
+ }
+
+
+ public static interface Bean {
+ }
+
+}
\ No newline at end of file
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java?rev=1364034&r1=1364033&r2=1364034&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java
Sat Jul 21 02:43:39 2012
@@ -16,6 +16,7 @@
*/
package org.apache.openejb.util;
+import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
import java.io.BufferedInputStream;
@@ -25,7 +26,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -44,12 +48,22 @@ public class Archives {
}
public static File fileArchive(Map<String, String> entries, Class...
classes) throws IOException {
+ return fileArchive(entries, Collections.EMPTY_LIST, classes);
+ }
+
+ public static File fileArchive(Map<String, String> entries, final
List<String> parts, Class... classes) throws IOException {
ClassLoader loader = Archives.class.getClassLoader();
File classpath = File.createTempFile("test", "archive");
+ Files.deleteOnExit(classpath);
assertTrue(classpath.delete());
assertTrue(classpath.mkdirs());
+
+ for (String part : parts) {
+ classpath = new File(classpath, part);
+ }
+
System.out.println("Archive file path:" +
classpath.getCanonicalPath());
for (Class clazz : classes) {
@@ -92,6 +106,7 @@ public class Archives {
ClassLoader loader = Archives.class.getClassLoader();
File classpath = File.createTempFile(archiveNamePrefix, ".jar");
+ classpath.deleteOnExit();
// Create the ZIP file
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(classpath)));