[jboss-svn-commits] JBoss Common SVN: r4529 - in arquillian/trunk/containers: weld-ee-embedded and 20 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jun 15 13:32:24 EDT 2010
Author: aslak
Date: 2010-06-15 13:32:23 -0400 (Tue, 15 Jun 2010)
New Revision: 4529
Added:
arquillian/trunk/containers/weld-ee-embedded/
arquillian/trunk/containers/weld-ee-embedded/pom.xml
arquillian/trunk/containers/weld-ee-embedded/src/
arquillian/trunk/containers/weld-ee-embedded/src/main/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEETestEnricher.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/AbstractMockDeployment.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockBeanDeploymentArchive.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockDeployment.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEELifecycle.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjBServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbDescriptor.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbInjectionServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockHttpSession.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockJpaServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockLifecycle.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceLoader.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockSecurityServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletContext.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletLifecycle.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockTransactionServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidationServices.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidator.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/el/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/el/EL.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkWrapClassLoader.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchive.java
arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchiveImpl.java
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive
arquillian/trunk/containers/weld-ee-embedded/src/test/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationEARTestCase.java
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationJARTestCase.java
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationWARTestCase.java
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/
arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java
arquillian/trunk/containers/weld-ee-embedded/src/test/resources/
Modified:
arquillian/trunk/containers/pom.xml
Log:
ARQ-180 Added a Weld Embedded Container with Mocked EE services.
Modified: arquillian/trunk/containers/pom.xml
===================================================================
--- arquillian/trunk/containers/pom.xml 2010-06-15 12:27:57 UTC (rev 4528)
+++ arquillian/trunk/containers/pom.xml 2010-06-15 17:32:23 UTC (rev 4529)
@@ -32,6 +32,7 @@
<module>jbossas-embedded-60</module>
<module>glassfish-embedded-30</module>
<module>weld-embedded</module>
+ <module>weld-ee-embedded</module>
<module>openejb</module>
<module>reloaded</module>
<module>openwebbeans-embedded</module>
Added: arquillian/trunk/containers/weld-ee-embedded/pom.xml
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/pom.xml (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/pom.xml 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!-- Parent -->
+ <parent>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-build</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-ee-embedded</artifactId>
+ <name>Arquillian Container Weld EE Embedded</name>
+ <description>Weld EE Embedded Container integration for the Arquillian Project</description>
+
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.weld_core>1.0.1-SP1</version.weld_core>
+
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- org.jboss.weld -->
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core-bom</artifactId>
+ <version>${version.weld_core}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!--
+ org.jboss.arquillian
+ -->
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.protocol</groupId>
+ <artifactId>arquillian-protocol-local</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.packager</groupId>
+ <artifactId>arquillian-packager-applicationarchive</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.testenricher</groupId>
+ <artifactId>arquillian-testenricher-cdi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!--
+ org.jboss.weld
+ -->
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>2.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.web</groupId>
+ <artifactId>el-impl</artifactId>
+ <version>2.1.2-b04</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec.javax.servlet</groupId>
+ <artifactId>jboss-servlet-api_3.0_spec</artifactId>
+ <version>1.0.0.Beta2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/RequestLifeCycleController.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import java.util.UUID;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * SessionLifeCycleController
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class RequestLifeCycleController implements EventHandler<Event>
+{
+ private Class<? extends Event> endRequestEvent;
+
+ public RequestLifeCycleController(Class<? extends Event> endRequestEvent)
+ {
+ if(endRequestEvent == null)
+ {
+ throw new IllegalArgumentException("EndSessionEvent must be specified");
+ }
+ this.endRequestEvent = endRequestEvent;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ if(manager == null)
+ {
+ throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
+ }
+ ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
+
+ String requestId = UUID.randomUUID().toString();
+ BeanStore beanStore = new ConcurrentHashMapBeanStore();
+
+ lifeCycle.beginRequest(requestId, beanStore);
+
+ context.register(endRequestEvent, new DestoryRequest(requestId, beanStore));
+ }
+
+ /**
+ * DestorySession
+ *
+ * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ private static class DestoryRequest implements EventHandler<Event> {
+
+ private String requestId;
+ private BeanStore beanStore;
+
+ public DestoryRequest(String requestId, BeanStore beanStore)
+ {
+ this.requestId = requestId;
+ this.beanStore = beanStore;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ manager.getServices().get(ContextLifecycle.class).endRequest(requestId, beanStore);
+ }
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/SessionLifeCycleController.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import java.util.UUID;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.event.Event;
+import org.jboss.arquillian.spi.event.suite.EventHandler;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * SessionLifeCycleController
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class SessionLifeCycleController implements EventHandler<Event>
+{
+ private Class<? extends Event> endSessionEvent;
+
+ public SessionLifeCycleController(Class<? extends Event> endSessionEvent)
+ {
+ if(endSessionEvent == null)
+ {
+ throw new IllegalArgumentException("EndSessionEvent must be specified");
+ }
+ this.endSessionEvent = endSessionEvent;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ if(manager == null)
+ {
+ throw new IllegalStateException("No " + WeldManager.class.getName() + " found in context");
+ }
+ ContextLifecycle lifeCycle = manager.getServices().get(ContextLifecycle.class);
+
+ String sessionId = UUID.randomUUID().toString();
+ BeanStore beanStore = new ConcurrentHashMapBeanStore();
+
+ lifeCycle.restoreSession(sessionId, beanStore);
+ context.register(endSessionEvent, new DestorySession(sessionId, beanStore));
+ }
+
+ /**
+ * DestorySession
+ *
+ * @author <a href="mailto:aknutsen at redhat.org">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ private static class DestorySession implements EventHandler<Event> {
+
+ private String sessionId;
+ private BeanStore beanStore;
+
+ public DestorySession(String sessionId, BeanStore beanStore)
+ {
+ this.sessionId = sessionId;
+ this.beanStore = beanStore;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.spi.event.EventHandler#callback(org.jboss.arquillian.spi.Context, java.lang.Object)
+ */
+ public void callback(Context context, Event event) throws Exception
+ {
+ WeldManager manager = context.get(WeldManager.class);
+ manager.getServices().get(ContextLifecycle.class).endSession(sessionId, beanStore);
+ }
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockConfiguration.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import org.jboss.arquillian.spi.ContainerConfiguration;
+import org.jboss.arquillian.spi.ContainerProfile;
+
+/**
+ * WeldSEConfiguration
+ *
+ * @author <a href="mailto:aknutsen at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldEEMockConfiguration implements ContainerConfiguration
+{
+
+ public ContainerProfile getContainerProfile()
+ {
+ return ContainerProfile.STANDALONE;
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEEMockContainer.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import org.jboss.arquillian.protocol.local.LocalMethodExecutor;
+import org.jboss.arquillian.spi.Configuration;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.spi.event.container.BeforeUnDeploy;
+import org.jboss.arquillian.spi.event.suite.After;
+import org.jboss.arquillian.spi.event.suite.Before;
+import org.jboss.arquillian.spi.event.suite.BeforeClass;
+import org.jboss.arquillian.weldee.mock.MockEELifecycle;
+import org.jboss.arquillian.weldee.mock.TestContainer;
+import org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.weld.bootstrap.WeldBootstrap;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * WeldEEMockConainer
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldEEMockContainer implements DeployableContainer
+{
+ public void setup(Context context, Configuration configuration)
+ {
+ }
+
+ public void start(Context context) throws LifecycleException
+ {
+ }
+
+ public ContainerMethodExecutor deploy(Context context, Archive<?> archive) throws DeploymentException
+ {
+ MockEELifecycle lifecycle = new MockEELifecycle(
+ archive.as(ShrinkwrapBeanDeploymentArchive.class));
+
+ TestContainer container = new TestContainer(lifecycle);
+ container.startContainer();
+
+ context.add(TestContainer.class, container);
+ context.add(WeldBootstrap.class, lifecycle.getBootstrap());
+ context.add(WeldManager.class, container.getBeanManager());
+
+ context.register(BeforeClass.class, new SessionLifeCycleController(BeforeUnDeploy.class));
+ context.register(Before.class, new RequestLifeCycleController(After.class));
+
+ return new LocalMethodExecutor();
+ }
+
+ public void undeploy(Context context, Archive<?> archive) throws DeploymentException
+ {
+ TestContainer container = context.get(TestContainer.class);
+ if(container != null)
+ {
+ container.stopContainer();
+ }
+ }
+
+ public void stop(Context context) throws LifecycleException
+ {
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEETestEnricher.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEETestEnricher.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/WeldEETestEnricher.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ * WeldSETestEnricher
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldEETestEnricher extends CDIInjectionEnricher
+{
+ @Override
+ protected BeanManager lookupBeanManager(Context context)
+ {
+ return context.get(WeldManager.class);
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/AbstractMockDeployment.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/AbstractMockDeployment.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/AbstractMockDeployment.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+
+public abstract class AbstractMockDeployment implements Deployment
+{
+
+ private final List<BeanDeploymentArchive> beanDeploymentArchives;
+ private final ServiceRegistry services;
+
+ public AbstractMockDeployment(BeanDeploymentArchive... beanDeploymentArchives)
+ {
+ this.services = new SimpleServiceRegistry();
+ this.beanDeploymentArchives = new ArrayList<BeanDeploymentArchive>(Arrays.asList(beanDeploymentArchives));
+ }
+
+ public List<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return beanDeploymentArchives;
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
+
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockBeanDeploymentArchive.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockBeanDeploymentArchive.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockBeanDeploymentArchive.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.EnterpriseBean;
+import javax.ejb.MessageDriven;
+import javax.ejb.Singleton;
+import javax.ejb.Stateful;
+import javax.ejb.Stateless;
+
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+
+/**
+ * @author pmuir
+ *
+ */
+public class MockBeanDeploymentArchive implements BeanDeploymentArchive
+{
+
+
+ private Collection<Class<?>> beanClasses;
+ private Collection<URL> beansXmlFiles;
+ private List<EjbDescriptor<?>> ejbs;
+ private final ServiceRegistry services;
+ private final Collection<BeanDeploymentArchive> bdas;
+ private final String id;
+
+ public MockBeanDeploymentArchive()
+ {
+ this("test");
+ }
+
+ public MockBeanDeploymentArchive(String id, Class<?> ... classes)
+ {
+ this.services = new SimpleServiceRegistry();
+ this.beanClasses = Arrays.asList(classes);
+ this.beansXmlFiles = new HashSet<URL>();
+ this.bdas = new HashSet<BeanDeploymentArchive>();
+ this.id = id;
+ }
+
+ public Collection<Class<?>> getBeanClasses()
+ {
+ return beanClasses;
+ }
+
+ public void setBeanClasses(Collection<Class<?>> beanClasses)
+ {
+ this.beanClasses = beanClasses;
+ ejbs = new ArrayList<EjbDescriptor<?>>();
+ for (Class<?> ejbClass : discoverEjbs(getBeanClasses()))
+ {
+ ejbs.add(MockEjbDescriptor.of(ejbClass));
+ }
+ }
+
+ public Collection<URL> getBeansXml()
+ {
+ return beansXmlFiles;
+ }
+
+ public void setBeansXmlFiles(Collection<URL> beansXmlFiles)
+ {
+ this.beansXmlFiles = beansXmlFiles;
+ }
+
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return bdas;
+ }
+
+ public Collection<EjbDescriptor<?>> getEjbs()
+ {
+ return ejbs;
+ }
+
+ protected static Iterable<Class<?>> discoverEjbs(Iterable<Class<?>> webBeanClasses)
+ {
+ Set<Class<?>> ejbs = new HashSet<Class<?>>();
+ for (Class<?> clazz : webBeanClasses)
+ {
+ if (clazz.isAnnotationPresent(Stateless.class) || clazz.isAnnotationPresent(Stateful.class) || clazz.isAnnotationPresent(MessageDriven.class) || clazz.isAnnotationPresent(Singleton.class) || EnterpriseBean.class.isAssignableFrom(clazz))
+ {
+ ejbs.add(clazz);
+ }
+ }
+ return ejbs;
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof MockBeanDeploymentArchive)
+ {
+ MockBeanDeploymentArchive that = (MockBeanDeploymentArchive) obj;
+ return this.getId().equals(that.getId());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getId().hashCode();
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockDeployment.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockDeployment.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockDeployment.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+
+public class MockDeployment extends AbstractMockDeployment
+{
+
+ private final BeanDeploymentArchive archive;
+
+ public MockDeployment(BeanDeploymentArchive beanDeploymentArchive)
+ {
+ this.archive = beanDeploymentArchive;
+ getBeanDeploymentArchives().add(archive);
+ }
+
+ public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass)
+ {
+ return archive;
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEELifecycle.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEELifecycle.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEELifecycle.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.bootstrap.api.Environment;
+import org.jboss.weld.bootstrap.api.Environments;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.ejb.spi.EjbServices;
+import org.jboss.weld.injection.spi.EjbInjectionServices;
+import org.jboss.weld.injection.spi.JpaInjectionServices;
+import org.jboss.weld.injection.spi.ResourceInjectionServices;
+import org.jboss.weld.security.spi.SecurityServices;
+import org.jboss.weld.transaction.spi.TransactionServices;
+import org.jboss.weld.validation.spi.ValidationServices;
+
+public class MockEELifecycle extends MockServletLifecycle
+{
+
+ private static final TransactionServices MOCK_TRANSACTION_SERVICES = new MockTransactionServices();
+
+ public MockEELifecycle(BeanDeploymentArchive war)
+ {
+ super(war);
+ getDeployment().getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
+ getDeployment().getServices().add(SecurityServices.class, new MockSecurityServices());
+ getDeployment().getServices().add(ValidationServices.class, new MockValidationServices());
+ getDeployment().getServices().add(EjbServices.class, new MockEjBServices());
+ getWar().getServices().add(EjbInjectionServices.class, new MockEjbInjectionServices());
+ getWar().getServices().add(JpaInjectionServices.class, new MockJpaServices(getDeployment()));
+ getWar().getServices().add(ResourceInjectionServices.class, new MockResourceServices());
+ }
+
+ @Override
+ public Environment getEnvironment()
+ {
+ return Environments.EE_INJECT;
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjBServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjBServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjBServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.ejb.api.SessionObjectReference;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+import org.jboss.weld.ejb.spi.EjbServices;
+import org.jboss.weld.ejb.spi.InterceptorBindings;
+
+public class MockEjBServices implements EjbServices
+{
+
+
+
+ public SessionObjectReference resolveEjb(EjbDescriptor<?> ejbDescriptor)
+ {
+ return new SessionObjectReference()
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ public <S> S getBusinessObject(Class<S> businessInterfaceType)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void remove()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isRemoved()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ };
+ }
+
+ public void registerInterceptors(EjbDescriptor<?> ejbDescriptor, InterceptorBindings interceptorBindings)
+ {
+ // do nothing
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbDescriptor.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbDescriptor.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbDescriptor.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,201 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.ejb.MessageDriven;
+import javax.ejb.Remove;
+import javax.ejb.Singleton;
+import javax.ejb.Stateful;
+import javax.ejb.Stateless;
+
+import org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+
+public class MockEjbDescriptor<T> implements EjbDescriptor<T>
+{
+ private final Class<T> beanClass;
+ private final String ejbName;
+ private final List<BusinessInterfaceDescriptor<?>> localInterfaces;
+ private final HashSet<Method> removeMethods;
+
+ public static <T> MockEjbDescriptor<T> of(Class<T> type)
+ {
+ return new MockEjbDescriptor<T>(type);
+ }
+
+ private MockEjbDescriptor(final Class<T> type)
+ {
+ this.beanClass = type;
+ this.ejbName = type.getSimpleName();
+ this.localInterfaces = new ArrayList<BusinessInterfaceDescriptor<?>>();
+
+ Local localAnnotation = type.getAnnotation(Local.class);
+ if (localAnnotation != null)
+ {
+ for (final Class<?> clazz : localAnnotation.value())
+ {
+ localInterfaces.add(createBusinessInterfaceDescriptor(clazz));
+ }
+ }
+
+ for (final Class<?> clazz : type.getInterfaces())
+ {
+ if (clazz.isAnnotationPresent(Local.class))
+ {
+ localInterfaces.add(createBusinessInterfaceDescriptor(clazz));
+ }
+ }
+ // cope with EJB 3.1 style no-interface views
+ if (localInterfaces.size() == 0)
+ {
+ localInterfaces.add(createBusinessInterfaceDescriptor(type));
+ }
+ this.removeMethods = new HashSet<Method>();
+ for (final Method method : type.getMethods())
+ {
+ if (method.isAnnotationPresent(Remove.class))
+ {
+ removeMethods.add(method);
+ }
+ }
+ }
+
+ private BusinessInterfaceDescriptor<Object> createBusinessInterfaceDescriptor(final Class<?> clazz)
+ {
+ return new BusinessInterfaceDescriptor<Object>()
+ {
+
+ @SuppressWarnings("unchecked")
+ public Class<Object> getInterface()
+ {
+ return (Class<Object>) clazz;
+ }
+
+ public String getJndiName()
+ {
+ return clazz.getSimpleName() + "/local";
+ }
+
+ };
+ }
+
+ public String getEjbName()
+ {
+ return ejbName;
+ }
+
+ public Collection<BusinessInterfaceDescriptor<?>> getLocalBusinessInterfaces()
+ {
+ return localInterfaces;
+ }
+
+ public Iterable<BusinessInterfaceDescriptor<?>> getRemoteBusinessInterfaces()
+ {
+ return Collections.emptyList();
+ }
+
+ public Collection<Method> getRemoveMethods()
+ {
+
+ return removeMethods;
+ }
+
+ public Class<T> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public boolean isMessageDriven()
+ {
+ return beanClass.isAnnotationPresent(MessageDriven.class);
+ }
+
+ public boolean isSingleton()
+ {
+ return beanClass.isAnnotationPresent(Singleton.class);
+ }
+
+ public boolean isStateful()
+ {
+ return beanClass.isAnnotationPresent(Stateful.class);
+ }
+
+ public boolean isStateless()
+ {
+ return beanClass.isAnnotationPresent(Stateless.class);
+ }
+
+ public String getLocalJndiName()
+ {
+ return beanClass.getSimpleName() + "/local";
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(getEjbName());
+ if (isStateful())
+ {
+ builder.append(" (SFSB)");
+ }
+ if (isStateless())
+ {
+ builder.append(" (SLSB)");
+ }
+ if (isSingleton())
+ {
+ builder.append(" (Singleton)");
+ }
+ if (isMessageDriven())
+ {
+ builder.append(" (MDB)");
+ }
+ builder.append("remove methods; " + removeMethods + "; ");
+ builder.append("; BeanClass: " + getBeanClass() + "; Local Business Interfaces: " + getLocalBusinessInterfaces());
+ return builder.toString();
+ }
+
+// @Override
+// public boolean equals(Object other)
+// {
+// if (other instanceof EjbDescriptor)
+// {
+// EjbDescriptor<T> that = (EjbDescriptor<T>) other;
+// return this.getBeanClass().equals(that.getBeanClass());
+// }
+// else
+// {
+// return false;
+// }
+// }
+//
+// @Override
+// public int hashCode()
+// {
+// return getEjbName().hashCode();
+// }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbInjectionServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbInjectionServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockEjbInjectionServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.injection.spi.EjbInjectionServices;
+
+/**
+ * @author pmuir
+ *
+ */
+public class MockEjbInjectionServices implements EjbInjectionServices
+{
+
+ public Object resolveEjb(InjectionPoint injectionPoint)
+ {
+ return null;
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockHttpSession.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockHttpSession.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockHttpSession.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionContext;
+
+/**
+ * A mock implementation of the HttpSession interface for tests.
+ *
+ * @author Dan Allen
+ */
+public class MockHttpSession implements HttpSession
+{
+ private String id;
+
+ private ServletContext servletContext;
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private boolean invalid = false;
+
+ private int maxInactiveInterval = 60;
+
+ private int lastAccessedTime = -1;
+
+ public MockHttpSession() {}
+
+ public MockHttpSession(String id)
+ {
+ this.id = id;
+ }
+
+ public MockHttpSession(String id, ServletContext servletContext)
+ {
+ this(id);
+ this.servletContext = servletContext;
+ }
+
+ public Object getAttribute(String name)
+ {
+ return attributes.get(name);
+ }
+
+ public Enumeration<String> getAttributeNames()
+ {
+ final Iterator<String> nameIterator = attributes.keySet().iterator();
+ return new Enumeration<String>()
+ {
+
+ public boolean hasMoreElements()
+ {
+ return nameIterator.hasNext();
+ }
+
+ public String nextElement()
+ {
+ return nameIterator.next();
+ }
+ };
+ }
+
+ public long getCreationTime()
+ {
+ return 0;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public long getLastAccessedTime()
+ {
+ return lastAccessedTime;
+ }
+
+ public int getMaxInactiveInterval()
+ {
+ return maxInactiveInterval;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+ @SuppressWarnings("deprecation")
+ public HttpSessionContext getSessionContext()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getValue(String name)
+ {
+ return getAttribute(name);
+ }
+
+ public String[] getValueNames()
+ {
+ return attributes.keySet().toArray(new String[0]);
+ }
+
+ public void invalidate()
+ {
+ attributes.clear();
+ invalid = true;
+ }
+
+ public boolean isNew()
+ {
+ return false;
+ }
+
+ public void putValue(String name, Object value)
+ {
+ setAttribute(name, value);
+ }
+
+ public void removeAttribute(String name)
+ {
+ attributes.remove(name);
+ }
+
+ public void removeValue(String name)
+ {
+ removeAttribute(name);
+ }
+
+ public void setAttribute(String name, Object value)
+ {
+ if (value == null)
+ {
+ removeAttribute(name);
+ }
+ else
+ {
+ attributes.put(name, value);
+ }
+ }
+
+ public void setMaxInactiveInterval(int seconds)
+ {
+ maxInactiveInterval = seconds;
+ }
+
+ public boolean isInvalid()
+ {
+ return invalid;
+ }
+
+ public void access()
+ {
+ lastAccessedTime = (int) System.currentTimeMillis();
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockJpaServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockJpaServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockJpaServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.injection.spi.JpaInjectionServices;
+
+public class MockJpaServices implements JpaInjectionServices
+{
+
+ private final Deployment deployment;
+
+ public MockJpaServices(Deployment deployment)
+ {
+ this.deployment = deployment;
+ }
+
+ public EntityManager resolvePersistenceContext(InjectionPoint injectionPoint)
+ {
+ return null;
+ }
+
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint)
+ {
+ return null;
+ }
+
+ public Collection<Class<?>> discoverEntities()
+ {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ for (BeanDeploymentArchive archive : deployment.getBeanDeploymentArchives())
+ {
+ discoverEntities(archive, classes);
+ }
+ return classes;
+ }
+
+ private void discoverEntities(BeanDeploymentArchive archive, Set<Class<?>> classes)
+ {
+ for (Class<?> clazz : archive.getBeanClasses())
+ {
+ if (clazz.isAnnotationPresent(Entity.class))
+ {
+ classes.add(clazz);
+ }
+ }
+ for (BeanDeploymentArchive child : archive.getBeanDeploymentArchives())
+ {
+ discoverEntities(child, classes);
+ }
+ }
+
+ public void cleanup() {}
+
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockLifecycle.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockLifecycle.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockLifecycle.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.bootstrap.api.Lifecycle;
+
+public interface MockLifecycle extends Lifecycle
+{
+
+ public abstract void initialize();
+
+ public abstract void beginApplication();
+
+ public abstract void endApplication();
+
+ public abstract void resetContexts();
+
+ public abstract void beginRequest();
+
+ public abstract void endRequest();
+
+ public abstract void beginSession();
+
+ public abstract void endSession();
+
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceLoader.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceLoader.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceLoader.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.resources.spi.ResourceLoadingException;
+import org.jboss.weld.util.collections.EnumerationList;
+
+public class MockResourceLoader implements ResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ return Thread.currentThread().getContextClassLoader().getResource(name);
+ }
+
+ public Collection<URL> getResources(String name)
+ {
+ try
+ {
+ return new EnumerationList<URL>(Thread.currentThread().getContextClassLoader().getResources(name));
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockResourceServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.injection.spi.ResourceInjectionServices;
+
+/**
+ * @author Pete Muir
+ *
+ */
+public class MockResourceServices implements ResourceInjectionServices
+{
+
+ public Object resolveResource(InjectionPoint injectionPoint)
+ {
+ return null;
+ }
+
+ public Object resolveResource(String jndiName, String mappedName)
+ {
+ return null;
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockSecurityServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockSecurityServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockSecurityServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.security.Principal;
+
+import org.jboss.weld.security.spi.SecurityServices;
+
+/**
+ * @author pmuir
+ *
+ */
+public class MockSecurityServices implements SecurityServices
+{
+
+ public Principal getPrincipal()
+ {
+ return new Principal()
+ {
+
+ public String getName()
+ {
+ return null;
+ }
+ };
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletContext.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletContext.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletContext.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,704 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterRegistration;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.SessionCookieConfig;
+import javax.servlet.SessionTrackingMode;
+import javax.servlet.FilterRegistration.Dynamic;
+import javax.servlet.descriptor.JspConfigDescriptor;
+
+/**
+ * Mock implementation of the servlet context for testing purposes. This implementation supports all
+ * of the standard context methods except that request dispatching just indicates what is being
+ * dispatched to, rather than doing the actual dispatch.
+ * <p>
+ * The context can be configured with a path parameter that should point to an absolute directory
+ * location that represents the place where the contents of the WAR bundle are located. Setting this
+ * value allows all of the resource location functionality to work as in a fully functioning web
+ * application. This value is not set then not resource location functionality will work and instead
+ * null will always be returned.
+ *
+ * Adapted from Apache Wicket
+ *
+ * @author Chris Turner (Wicket)
+ */
+public class MockServletContext implements ServletContext
+{
+ private final Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private final Map<String, String> initParameters = new HashMap<String, String>();
+
+ /** Map of mime types */
+ private final Map<String, String> mimeTypes = new HashMap<String, String>();
+
+ private File webappRoot;
+
+ /**
+ * Create the mock object. As part of the creation, the context sets the root directory where
+ * web application content is stored. This must be an ABSOLUTE directory relative to where the
+ * tests are being executed. For example: <code>System.getProperty("user.dir") +
+ * "/src/webapp"</code>
+ *
+ * @param application
+ * The application that this context is for
+ * @param path
+ * The path to the root of the web application
+ */
+ public MockServletContext(final String path)
+ {
+ webappRoot = null;
+ if (path != null)
+ {
+ webappRoot = new File(path);
+ if (!webappRoot.exists() || !webappRoot.isDirectory())
+ {
+ //log.warn("WARNING: The webapp root directory is invalid: " + path);
+ webappRoot = null;
+ }
+ }
+
+ // assume we're running in maven or an eclipse project created by maven,
+ // so the sessions directory will be created inside the target directory,
+ // and will be cleaned up with a mvn clean
+
+ File file = new File("target/work/");
+ file.mkdirs();
+ attributes.put("javax.servlet.context.tempdir", file);
+
+ mimeTypes.put("html", "text/html");
+ mimeTypes.put("htm", "text/html");
+ mimeTypes.put("css", "text/css");
+ mimeTypes.put("xml", "text/xml");
+ mimeTypes.put("js", "text/plain");
+ mimeTypes.put("gif", "image/gif");
+ mimeTypes.put("jpg", "image/jpeg");
+ mimeTypes.put("png", "image/png");
+ }
+
+ /**
+ * Add an init parameter.
+ *
+ * @param name
+ * The parameter name
+ * @param value
+ * The parameter value
+ */
+ public void addInitParameter(final String name, final String value)
+ {
+ initParameters.put(name, value);
+ }
+
+ // Configuration methods
+
+ /**
+ * Add a new recognized mime type.
+ *
+ * @param fileExtension
+ * The file extension (e.g. "jpg")
+ * @param mimeType
+ * The mime type (e.g. "image/jpeg")
+ */
+ public void addMimeType(final String fileExtension, final String mimeType)
+ {
+ mimeTypes.put(fileExtension, mimeType);
+ }
+
+ /**
+ * Get an attribute with the given name.
+ *
+ * @param name
+ * The attribute name
+ * @return The value, or null
+ */
+ public Object getAttribute(final String name)
+ {
+ return attributes.get(name);
+ }
+
+ /**
+ * Get all of the attribute names.
+ *
+ * @return The attribute names
+ */
+ public Enumeration<String> getAttributeNames()
+ {
+ return Collections.enumeration(attributes.keySet());
+ }
+
+ // ServletContext interface methods
+
+ /**
+ * Get the context for the given URL path
+ *
+ * @param name
+ * The url path
+ * @return Always returns this
+ */
+ public ServletContext getContext(String name)
+ {
+ return this;
+ }
+
+ /**
+ * Get the init parameter with the given name.
+ *
+ * @param name
+ * The name
+ * @return The parameter, or null if no such parameter
+ */
+ public String getInitParameter(final String name)
+ {
+ return initParameters.get(name);
+ }
+
+ /**
+ * Get the name of all of the init parameters.
+ *
+ * @return The init parameter names
+ */
+ public Enumeration<String> getInitParameterNames()
+ {
+ return Collections.enumeration(initParameters.keySet());
+ }
+
+ /**
+ * @return Always 2
+ */
+ public int getMajorVersion()
+ {
+ return 2;
+ }
+
+ /**
+ * Get the mime type for the given file. Uses a hardcoded map of mime types set at
+ * Initialization time.
+ *
+ * @param name
+ * The name to get the mime type for
+ * @return The mime type
+ */
+ public String getMimeType(final String name)
+ {
+ int index = name.lastIndexOf('.');
+ if (index == -1 || index == (name.length() - 1))
+ {
+ return null;
+ }
+ else
+ {
+ return mimeTypes.get(name.substring(index + 1));
+ }
+ }
+
+ /**
+ * @return Always 3
+ */
+ public int getMinorVersion()
+ {
+ return 3;
+ }
+
+ /**
+ * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value.
+ *
+ * @param name
+ * The name of the servlet or JSP
+ * @return The dispatcher
+ */
+ public RequestDispatcher getNamedDispatcher(final String name)
+ {
+ return getRequestDispatcher(name);
+ }
+
+ /**
+ * Get the real file path of the given resource name.
+ *
+ * @param name
+ * The name
+ * @return The real path or null
+ */
+ public String getRealPath(String name)
+ {
+ if (webappRoot == null)
+ {
+ return null;
+ }
+
+ if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
+ File f = new File(webappRoot, name);
+ if (!f.exists())
+ {
+ return null;
+ }
+ else
+ {
+ return f.getPath();
+ }
+ }
+
+ /**
+ * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value.
+ *
+ * @param name
+ * The name of the resource to get the dispatcher for
+ * @return The dispatcher
+ */
+ public RequestDispatcher getRequestDispatcher(final String name)
+ {
+ return new RequestDispatcher()
+ {
+ public void forward(ServletRequest servletRequest, ServletResponse servletResponse)
+ throws IOException
+ {
+ servletResponse.getWriter().write("FORWARD TO RESOURCE: " + name);
+ }
+
+ public void include(ServletRequest servletRequest, ServletResponse servletResponse)
+ throws IOException
+ {
+ servletResponse.getWriter().write("INCLUDE OF RESOURCE: " + name);
+ }
+ };
+ }
+
+ /**
+ * Get the URL for a particular resource that is relative to the web app root directory.
+ *
+ * @param name
+ * The name of the resource to get
+ * @return The resource, or null if resource not found
+ * @throws MalformedURLException
+ * If the URL is invalid
+ */
+ public URL getResource(String name) throws MalformedURLException
+ {
+ if (webappRoot == null)
+ {
+ return null;
+ }
+
+ if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
+ File f = new File(webappRoot, name);
+ if (!f.exists())
+ {
+ return null;
+ }
+ else
+ {
+ return f.toURI().toURL();
+ }
+ }
+
+ /**
+ * Get an input stream for a particular resource that is relative to the web app root directory.
+ *
+ * @param name
+ * The name of the resource to get
+ * @return The input stream for the resource, or null of resource is not found
+ */
+ public InputStream getResourceAsStream(String name)
+ {
+ if (webappRoot == null)
+ {
+ return null;
+ }
+
+ if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+
+ File f = new File(webappRoot, name);
+ if (!f.exists())
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ return new FileInputStream(f);
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Get the resource paths starting from the web app root directory and then relative to the the
+ * given name.
+ *
+ * @param name
+ * The starting name
+ * @return The set of resource paths at this location
+ */
+ public Set<String> getResourcePaths(String name)
+ {
+ if (webappRoot == null)
+ {
+ return new HashSet<String>();
+ }
+
+ if (name.startsWith("/"))
+ {
+ name = name.substring(1);
+ }
+ if (name.endsWith("/"))
+ {
+ name = name.substring(0, name.length() - 1);
+ }
+ String[] elements = null;
+ if (name.trim().length() == 0)
+ {
+ elements = new String[0];
+ }
+ else
+ {
+ elements = name.split("/");
+ }
+
+ File current = webappRoot;
+ for (int i = 0; i < elements.length; i++)
+ {
+ File[] files = current.listFiles();
+ boolean match = false;
+ for (int f = 0; f < files.length; f++)
+ {
+ if (files[f].getName().equals(elements[i]) && files[f].isDirectory())
+ {
+ current = files[f];
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ {
+ return null;
+ }
+ }
+
+ File[] files = current.listFiles();
+ Set<String> result = new HashSet<String>();
+ int stripLength = webappRoot.getPath().length();
+ for (int f = 0; f < files.length; f++)
+ {
+ String s = files[f].getPath().substring(stripLength).replace('\\', '/');
+ if (files[f].isDirectory())
+ {
+ s = s + "/";
+ }
+ result.add(s);
+ }
+ return result;
+ }
+
+ /**
+ * Get the server info.
+ *
+ * @return The server info
+ */
+ public String getServerInfo()
+ {
+ return "Wicket Mock Test Environment v1.0";
+ }
+
+ /**
+ * NOT USED - Servlet Spec requires that this always returns null.
+ *
+ * @param name
+ * Not used
+ * @return null
+ * @throws ServletException
+ * Not used
+ */
+ public Servlet getServlet(String name) throws ServletException
+ {
+ return null;
+ }
+
+ /**
+ * Return the name of the servlet context.
+ *
+ * @return The name
+ */
+ public String getServletContextName()
+ {
+ return "Mock";
+ }
+
+ /**
+ * NOT USED - Servlet spec requires that this always returns null.
+ *
+ * @return null
+ */
+ public Enumeration<String> getServletNames()
+ {
+ return null;
+ }
+
+ /**
+ * NOT USED - Servlet spec requires that this always returns null.
+ *
+ * @return null
+ */
+ public Enumeration<Servlet> getServlets()
+ {
+ return null;
+ }
+
+ /**
+ * As part of testing we always log to the console.
+ *
+ * @param e
+ * The exception to log
+ * @param msg
+ * The message to log
+ */
+ public void log(Exception e, String msg)
+ {
+ //log.error(msg, e);
+ }
+
+ /**
+ * As part of testing we always log to the console.
+ *
+ * @param msg
+ * The message to log
+ */
+ public void log(String msg)
+ {
+ //log.info(msg);
+ }
+
+ /**
+ * As part of testing we always log to the console.
+ *
+ * @param msg
+ * The message to log
+ * @param cause
+ * The cause exception
+ */
+ public void log(String msg, Throwable cause)
+ {
+ //log.error(msg, cause);
+ }
+
+ /**
+ * Remove an attribute with the given name.
+ *
+ * @param name
+ * The name
+ */
+ public void removeAttribute(final String name)
+ {
+ attributes.remove(name);
+ }
+
+ /**
+ * Set an attribute.
+ *
+ * @param name
+ * The name of the attribute
+ * @param o
+ * The value
+ */
+ public void setAttribute(final String name, final Object o)
+ {
+ attributes.put(name, o);
+ }
+
+ /**
+ * @return context path
+ */
+ public String getContextPath()
+ {
+ return "";
+ }
+
+ public Dynamic addFilter(String arg0, String arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Dynamic addFilter(String arg0, Filter arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Dynamic addFilter(String arg0, Class<? extends Filter> arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void addListener(String arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public <T extends EventListener> void addListener(T arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void addListener(Class<? extends EventListener> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0,
+ String arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0,
+ Servlet arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0,
+ Class<? extends Servlet> arg1) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends Filter> T createFilter(Class<T> arg0)
+ throws ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends EventListener> T createListener(Class<T> arg0)
+ throws ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T extends Servlet> T createServlet(Class<T> arg0)
+ throws ServletException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void declareRoles(String... arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public ClassLoader getClassLoader() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getEffectiveMajorVersion() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getEffectiveMinorVersion() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public FilterRegistration getFilterRegistration(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public JspConfigDescriptor getJspConfigDescriptor() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ServletRegistration getServletRegistration(String arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<String, ? extends ServletRegistration> getServletRegistrations() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SessionCookieConfig getSessionCookieConfig() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean setInitParameter(String arg0, String arg1) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setSessionTrackingModes(Set<SessionTrackingMode> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletLifecycle.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletLifecycle.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletLifecycle.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.bootstrap.WeldBootstrap;
+import org.jboss.weld.bootstrap.api.Environment;
+import org.jboss.weld.bootstrap.api.Environments;
+import org.jboss.weld.bootstrap.api.Lifecycle;
+import org.jboss.weld.bootstrap.api.helpers.ForwardingLifecycle;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.servlet.api.ServletServices;
+
+public class MockServletLifecycle extends ForwardingLifecycle implements MockLifecycle
+{
+ private static final ResourceLoader MOCK_RESOURCE_LOADER = new MockResourceLoader();
+
+ private final WeldBootstrap bootstrap;
+ private final Deployment deployment;
+ private final BeanDeploymentArchive war;
+ private final BeanStore applicationBeanStore;
+ private final BeanStore sessionBeanStore;
+ private final BeanStore requestBeanStore;
+
+ private Lifecycle lifecycle;
+
+ public MockServletLifecycle(BeanDeploymentArchive war)
+ {
+ this(new MockDeployment(war), war);
+ }
+
+ public MockServletLifecycle(Deployment deployment, BeanDeploymentArchive war)
+ {
+ this.deployment = deployment;
+ this.war = war;
+ if (deployment == null)
+ {
+ throw new IllegalStateException("No WebBeanDiscovery is available");
+ }
+ this.bootstrap = new WeldBootstrap();
+ this.deployment.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
+ this.deployment.getServices().add(ServletServices.class, new MockServletServices(war));
+ this.applicationBeanStore = new ConcurrentHashMapBeanStore();
+ this.sessionBeanStore = new ConcurrentHashMapBeanStore();
+ this.requestBeanStore = new ConcurrentHashMapBeanStore();
+ }
+
+ protected BeanStore getSessionBeanStore()
+ {
+ return sessionBeanStore;
+ }
+
+ protected BeanStore getRequestBeanStore()
+ {
+ return requestBeanStore;
+ }
+
+ protected BeanStore getApplicationBeanStore()
+ {
+ return applicationBeanStore;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#initialize()
+ */
+ public void initialize()
+ {
+ try
+ {
+ bootstrap.startContainer(getEnvironment(), getDeployment(), getApplicationBeanStore());
+ }
+ finally
+ {
+ lifecycle = deployment.getServices().get(ContextLifecycle.class);
+ }
+ }
+
+ @Override
+ protected Lifecycle delegate()
+ {
+ return lifecycle;
+ }
+
+ protected Deployment getDeployment()
+ {
+ return deployment;
+ }
+
+ public WeldBootstrap getBootstrap()
+ {
+ return bootstrap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#beginApplication()
+ */
+ public void beginApplication()
+ {
+ bootstrap.startInitialization().deployBeans().validateBeans().endInitialization();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#endApplication()
+ */
+ @Override
+ public void endApplication()
+ {
+ bootstrap.shutdown();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#resetContexts()
+ */
+ public void resetContexts()
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#beginRequest()
+ */
+ public void beginRequest()
+ {
+ super.beginRequest("Mock", getRequestBeanStore());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#endRequest()
+ */
+ public void endRequest()
+ {
+ super.endRequest("Mock", getRequestBeanStore());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#beginSession()
+ */
+ public void beginSession()
+ {
+ super.restoreSession("Mock", getSessionBeanStore());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.weld.mock.MockLifecycle#endSession()
+ */
+ public void endSession()
+ {
+ // TODO Conversation handling breaks this :-(
+ //super.endSession("Mock", sessionBeanStore);
+ }
+
+ protected Environment getEnvironment()
+ {
+ return Environments.SERVLET;
+ }
+
+ public BeanDeploymentArchive getWar()
+ {
+ return war;
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockServletServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import javax.servlet.ServletContext;
+
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.servlet.api.ServletServices;
+
+/**
+ * @author pmuir
+ *
+ */
+public class MockServletServices implements ServletServices
+{
+
+ private final BeanDeploymentArchive beanDeploymentArchive;
+
+ public MockServletServices(BeanDeploymentArchive beanDeploymentArchive)
+ {
+ this.beanDeploymentArchive = beanDeploymentArchive;
+ }
+
+ public BeanDeploymentArchive getBeanDeploymentArchive(ServletContext ctx)
+ {
+ if (ctx instanceof MockServletContext)
+ {
+ return beanDeploymentArchive;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockTransactionServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockTransactionServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockTransactionServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.jboss.weld.transaction.spi.TransactionServices;
+
+/**
+ * A mock version of TransactionServices for RI unit tests. Since
+ * no JTA transaction can be active for these unit tests, all
+ * methods here are empty.
+ *
+ * @author David Allen
+ *
+ */
+public class MockTransactionServices implements TransactionServices
+{
+
+ public boolean isTransactionActive()
+ {
+ return false;
+ }
+
+ public void registerSynchronization(Synchronization synchronizedObserver)
+ {
+ }
+
+ public UserTransaction getUserTransaction()
+ {
+ return new UserTransaction()
+ {
+
+ public void setTransactionTimeout(int arg0) throws SystemException
+ {
+
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException, SystemException
+ {
+
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return 0;
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+
+ }
+ };
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidationServices.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidationServices.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidationServices.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+
+import org.jboss.weld.validation.spi.ValidationServices;
+
+/**
+ * @author pmuir
+ *
+ */
+public class MockValidationServices implements ValidationServices
+{
+
+ public ValidatorFactory getDefaultValidatorFactory()
+ {
+ return new ValidatorFactory()
+ {
+
+ public ValidatorContext usingContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> T unwrap(Class<T> type)
+ {
+ if (type.equals(ValidatorFactory.class))
+ {
+ return type.cast(this);
+ }
+ else
+ {
+ throw new ValidationException();
+ }
+ }
+
+ public Validator getValidator()
+ {
+ return new MockValidator();
+ }
+
+ public TraversableResolver getTraversableResolver()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public MessageInterpolator getMessageInterpolator()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ConstraintValidatorFactory getConstraintValidatorFactory()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+
+ public void cleanup() {}
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidator.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidator.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/MockValidator.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.metadata.BeanDescriptor;
+
+public class MockValidator implements Validator
+{
+
+ public BeanDescriptor getConstraintsForClass(Class<?> clazz)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> T unwrap(Class<T> type)
+ {
+ if (type.equals(Validator.class))
+ {
+ return type.cast(this);
+ }
+ else
+ {
+ throw new ValidationException();
+ }
+ }
+
+ public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> Set<ConstraintViolation<T>> validateProperty(T object, String propertyName, Class<?>... groups)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/TestContainer.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock;
+
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.context.ConversationContext;
+import org.jboss.weld.manager.BeanManagerImpl;
+
+/**
+ * Control of the container, used for tests. Wraps up common operations.
+ *
+ * If you require more control over the container bootstrap lifecycle you should
+ * use the {@link #getLifecycle()} method. For example:
+ *
+ * <code>TestContainer container = new TestContainer(...);
+ * container.getLifecycle().initialize();
+ * container.getLifecycle().getBootstrap().startInitialization();
+ * container.getLifecycle().getBootstrap().deployBeans();
+ * container.getLifecycle().getBootstrap().validateBeans();
+ * container.getLifecycle().getBootstrap().endInitialization();
+ * container.getLifecycle().stopContainer();</code>
+ *
+ * Note that we can easily mix fine-grained calls to bootstrap, and coarse grained calls to {@link TestContainer}.
+ *
+ * @author pmuir
+ *
+ */
+public class TestContainer
+{
+
+ private final MockServletLifecycle lifecycle;
+
+ /**
+ * Create a container, specifying the classes and beans.xml to deploy
+ *
+ * @param lifecycle
+ * @param classes
+ * @param beansXml
+ */
+// public TestContainer(MockServletLifecycle lifecycle, Collection<Class<?>> classes, Collection<URL> beansXml)
+// {
+// this(lifecycle);
+// configureArchive(classes, beansXml);
+// }
+
+ public TestContainer(MockServletLifecycle lifecycle)
+ {
+ this.lifecycle = lifecycle;
+ }
+
+// public TestContainer(MockServletLifecycle lifecycle, Class<?>[] classes, URL[] beansXml)
+// {
+// this(lifecycle, classes == null ? null : Arrays.asList(classes), beansXml == null ? null : Arrays.asList(beansXml));
+// }
+//
+// public TestContainer(MockServletLifecycle lifecycle, Class<?>... classes)
+// {
+// this(lifecycle, classes == null ? null : Arrays.asList(classes), null);
+// }
+
+ /**
+ * Starts the container and begins the application
+ */
+ public TestContainer startContainer()
+ {
+ getLifecycle().initialize();
+ getLifecycle().beginApplication();
+ return this;
+ }
+
+ /**
+ * Configure's the archive with the classes and beans.xml
+ */
+// protected TestContainer configureArchive(Collection<Class<?>> classes, Collection<URL> beansXml)
+// {
+// BeanDeploymentArchive archive = lifecycle.getWar();
+// archive.setBeanClasses(classes);
+// if (beansXml != null)
+// {
+// archive.setBeansXmlFiles(beansXml);
+// }
+// return this;
+// }
+
+ /**
+ * Get the context lifecycle, allowing fine control over the contexts' state
+ *
+ * @return
+ */
+ public MockServletLifecycle getLifecycle()
+ {
+ return lifecycle;
+ }
+
+ public BeanManagerImpl getBeanManager()
+ {
+ return getLifecycle().getBootstrap().getManager(getLifecycle().getWar());
+ }
+
+ public Deployment getDeployment()
+ {
+ return getLifecycle().getDeployment();
+ }
+
+ /**
+ * Utility method which ensures a request is active and available for use
+ *
+ */
+ public TestContainer ensureRequestActive()
+ {
+ if (!getLifecycle().isSessionActive())
+ {
+ getLifecycle().beginSession();
+ }
+ if (!getLifecycle().isConversationActive())
+ {
+ ((ConversationContext) getLifecycle().getConversationContext()).setActive(true);
+ }
+ if (!getLifecycle().isRequestActive())
+ {
+ getLifecycle().beginRequest();
+ }
+ return this;
+ }
+
+ /**
+ * Clean up the container, ending any active contexts
+ *
+ */
+ public TestContainer stopContainer()
+ {
+ if (getLifecycle().isRequestActive())
+ {
+ getLifecycle().endRequest();
+ }
+ if (getLifecycle().isConversationActive())
+ {
+ ((ConversationContext) getLifecycle().getConversationContext()).setActive(false);
+ }
+ if (getLifecycle().isSessionActive())
+ {
+ getLifecycle().endSession();
+ }
+ if (getLifecycle().isApplicationActive())
+ {
+ getLifecycle().endApplication();
+ }
+ return this;
+ }
+
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/el/EL.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/el/EL.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/mock/el/EL.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.mock.el;
+
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELContextEvent;
+import javax.el.ELContextListener;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import javax.el.VariableMapper;
+
+import org.jboss.weld.el.WeldELContextListener;
+import org.jboss.weld.el.WeldExpressionFactory;
+import org.jboss.weld.manager.BeanManagerImpl;
+
+import com.sun.el.ExpressionFactoryImpl;
+import com.sun.el.lang.FunctionMapperImpl;
+import com.sun.el.lang.VariableMapperImpl;
+
+/**
+ * An instance of JBoss EL.
+ *
+ * @author Gavin King
+ *
+ */
+public class EL
+{
+
+ public static final ExpressionFactory EXPRESSION_FACTORY = new WeldExpressionFactory(new ExpressionFactoryImpl());
+
+ public static final ELContextListener[] EL_CONTEXT_LISTENERS = { new WeldELContextListener() };
+
+ private static ELResolver createELResolver(BeanManagerImpl beanManagerImpl)
+ {
+ CompositeELResolver resolver = new CompositeELResolver();
+ resolver.add( beanManagerImpl.getELResolver() );
+ resolver.add( new MapELResolver() );
+ resolver.add( new ListELResolver() );
+ resolver.add( new ArrayELResolver() );
+ resolver.add( new ResourceBundleELResolver() );
+ resolver.add( new BeanELResolver() );
+ return resolver;
+ }
+
+ public static ELContext createELContext(BeanManagerImpl beanManagerImpl) {
+ return createELContext(createELResolver(beanManagerImpl), new FunctionMapperImpl() );
+ }
+
+ public static ELContext createELContext(final ELResolver resolver, final FunctionMapper functionMapper)
+ {
+ ELContext context = new ELContext()
+ {
+ final VariableMapperImpl variableMapper = new VariableMapperImpl();
+
+ @Override
+ public ELResolver getELResolver()
+ {
+ return resolver;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper()
+ {
+ return functionMapper;
+ }
+
+ @Override
+ public VariableMapper getVariableMapper()
+ {
+ return variableMapper;
+ }
+
+ };
+ callELContextListeners(context);
+ return context;
+ }
+
+ public static void callELContextListeners(ELContext context)
+ {
+ ELContextEvent event = new ELContextEvent(context);
+ for (ELContextListener listener : EL_CONTEXT_LISTENERS)
+ {
+ listener.contextCreated(event);
+ }
+ }
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkWrapClassLoader.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkWrapClassLoader.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkWrapClassLoader.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.shrinkwrap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.security.SecureClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Node;
+
+/**
+ * A ClassLoader implementation that can locate resources in a ShrinkWrap archive
+ *
+ * <p><strong>NOTE</strong> This is a prototype implementation of this concept. It
+ * does not address all classloading concerns as of yet.</p>
+ *
+ * @author <a href="mailto:dan.allen at mojavelinux.com">Dan Allen</a>
+ */
+public class ShrinkWrapClassLoader extends SecureClassLoader
+{
+ public static final String ARCHIVE_PROTOCOL = "archive:/";
+
+ private final Archive<?> archive;
+
+ public ShrinkWrapClassLoader(Archive<?> archive)
+ {
+ super();
+ this.archive = archive;
+ }
+
+ @Override
+ protected URL findResource(final String name)
+ {
+ final Node a = archive.get(name);
+ if (a == null)
+ {
+ return null;
+ }
+ try
+ {
+ return new URL(null, ARCHIVE_PROTOCOL + name, new URLStreamHandler()
+ {
+ @Override
+ protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+ {
+ return new URLConnection(u)
+ {
+ @Override
+ public void connect() throws IOException
+ {
+ }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return a.getAsset().openStream();
+ }
+ };
+ }
+
+ ;
+ });
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
+
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException
+ {
+ Iterator<URL> it = new ArrayList<URL>(0).iterator();
+ URL resource = findResource(name);
+ if (resource != null)
+ {
+ it = Arrays.asList(resource).iterator();
+ }
+ final Iterator<URL> i = it;
+ return new Enumeration<URL>()
+ {
+ public boolean hasMoreElements()
+ {
+ return i.hasNext();
+ }
+
+ public URL nextElement()
+ {
+ return i.next();
+ }
+ };
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchive.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchive.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchive.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.shrinkwrap;
+
+import org.jboss.shrinkwrap.api.Assignable;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+
+/**
+ * ShrinkwrapBeanDeploymentArchive
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface ShrinkwrapBeanDeploymentArchive extends BeanDeploymentArchive, Assignable
+{
+
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchiveImpl.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchiveImpl.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/java/org/jboss/arquillian/weldee/shrinkwrap/ShrinkwrapBeanDeploymentArchiveImpl.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,244 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.shrinkwrap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.EnterpriseBean;
+import javax.ejb.MessageDriven;
+import javax.ejb.Singleton;
+import javax.ejb.Stateful;
+import javax.ejb.Stateless;
+
+import org.jboss.arquillian.weldee.mock.MockEjbDescriptor;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.Filters;
+import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.impl.base.AssignableBase;
+import org.jboss.shrinkwrap.impl.base.Validate;
+import org.jboss.shrinkwrap.impl.base.asset.ArchiveAsset;
+import org.jboss.shrinkwrap.impl.base.asset.ClassAsset;
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+
+/**
+ * ShrinkwrapBeanDeploymentArchiveImpl
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class ShrinkwrapBeanDeploymentArchiveImpl extends AssignableBase implements ShrinkwrapBeanDeploymentArchive
+{
+ private Archive<?> archive;
+
+ private ServiceRegistry serviceRegistry = new SimpleServiceRegistry();
+
+ public ShrinkwrapBeanDeploymentArchiveImpl(Archive<?> archive)
+ {
+ Validate.notNull(archive, "Archive must be specified");
+ this.archive = archive;
+ }
+
+ @Override
+ protected Archive<?> getArchive()
+ {
+ return archive;
+ }
+
+ public String getId()
+ {
+ return archive.getName();
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return serviceRegistry;
+ }
+
+ public Collection<URL> getBeansXml()
+ {
+ List<URL> beanClasses = new ArrayList<URL>();
+ Map<ArchivePath, Node> nestedArchives = archive.getContent(Filters.include(".*\\.jar|.*\\.war"));
+ for(final Map.Entry<ArchivePath, Node> nestedArchiveEntry : nestedArchives.entrySet())
+ {
+ if( !(nestedArchiveEntry.getValue().getAsset() instanceof ArchiveAsset))
+ {
+ continue;
+ }
+ ArchiveAsset nestedArchive = (ArchiveAsset)nestedArchiveEntry.getValue().getAsset();
+ Map<ArchivePath, Node> classes = nestedArchive.getArchive().getContent(Filters.include(".*/beans.xml"));
+ for(final Map.Entry<ArchivePath, Node> entry : classes.entrySet())
+ {
+ try
+ {
+ beanClasses.add(
+ new URL(null, "archive://" + entry.getKey().get(), new URLStreamHandler()
+ {
+ @Override
+ protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+ {
+ return new URLConnection(u)
+ {
+ @Override
+ public void connect() throws IOException { }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return entry.getValue().getAsset().openStream();
+ }
+ };
+ };
+ }));
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ Map<ArchivePath, Node> classes = archive.getContent(Filters.include(".*/beans.xml"));
+ for(final Map.Entry<ArchivePath, Node> entry : classes.entrySet())
+ {
+ try
+ {
+ beanClasses.add(
+ new URL(null, "archive://" + entry.getKey().get(), new URLStreamHandler()
+ {
+ @Override
+ protected java.net.URLConnection openConnection(URL u) throws java.io.IOException
+ {
+ return new URLConnection(u)
+ {
+ @Override
+ public void connect() throws IOException { }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return entry.getValue().getAsset().openStream();
+ }
+ };
+ };
+ }));
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return beanClasses;
+ }
+
+ public Collection<Class<?>> getBeanClasses()
+ {
+ List<Class<?>> beanClasses = new ArrayList<Class<?>>();
+
+ Map<ArchivePath, Node> nestedArchives = archive.getContent(Filters.include(".*\\.jar|.*\\.war"));
+ for(final Map.Entry<ArchivePath, Node> nestedArchiveEntry : nestedArchives.entrySet())
+ {
+ if( !(nestedArchiveEntry.getValue().getAsset() instanceof ArchiveAsset))
+ {
+ continue;
+ }
+ ArchiveAsset nestedArchive = (ArchiveAsset)nestedArchiveEntry.getValue().getAsset();
+ Map<ArchivePath, Node> classes = nestedArchive.getArchive().getContent(Filters.include(".*\\.class"));
+ for(Map.Entry<ArchivePath, Node> classEntry : classes.entrySet())
+ {
+ if (classEntry.getValue().getAsset() instanceof ClassAsset)
+ {
+ beanClasses.add(
+ (Class<?>)extractFieldFromAsset(
+ classEntry.getValue().getAsset(),
+ "clazz"));
+ }
+ }
+ }
+ Map<ArchivePath, Node> classes = archive.getContent(Filters.include(".*\\.class"));
+ for(Map.Entry<ArchivePath, Node> classEntry : classes.entrySet())
+ {
+ if (classEntry.getValue().getAsset() instanceof ClassAsset)
+ {
+ beanClasses.add(
+ (Class<?>)extractFieldFromAsset(
+ classEntry.getValue().getAsset(),
+ "clazz"));
+ }
+ }
+ return beanClasses;
+ }
+
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return Collections.emptySet();
+ }
+
+ public Collection<EjbDescriptor<?>> getEjbs()
+ {
+ List<EjbDescriptor<?>> ejbs = new ArrayList<EjbDescriptor<?>>();
+ for (Class<?> ejbClass : discoverEjbs(getBeanClasses()))
+ {
+ ejbs.add(MockEjbDescriptor.of(ejbClass));
+ }
+ return ejbs;
+ }
+
+ protected static Iterable<Class<?>> discoverEjbs(Iterable<Class<?>> webBeanClasses)
+ {
+ Set<Class<?>> ejbs = new HashSet<Class<?>>();
+ for (Class<?> clazz : webBeanClasses)
+ {
+ if (clazz.isAnnotationPresent(Stateless.class) || clazz.isAnnotationPresent(Stateful.class) || clazz.isAnnotationPresent(MessageDriven.class) || clazz.isAnnotationPresent(Singleton.class) || EnterpriseBean.class.isAssignableFrom(clazz))
+ {
+ ejbs.add(clazz);
+ }
+ }
+ return ejbs;
+ }
+
+ private Object extractFieldFromAsset(Asset asset, String fieldName)
+ {
+ try
+ {
+ Field field = asset.getClass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+
+ return field.get(asset);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.ContainerConfiguration 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1 @@
+org.jboss.arquillian.weldee.WeldEEMockConfiguration
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeployableContainer 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1 @@
+org.jboss.arquillian.weldee.WeldEEMockContainer
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1 @@
+org.jboss.arquillian.weldee.WeldEETestEnricher
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/main/resources/META-INF/services/org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchive 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1 @@
+org.jboss.arquillian.weldee.shrinkwrap.ShrinkwrapBeanDeploymentArchiveImpl
\ No newline at end of file
Added: arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationEARTestCase.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationEARTestCase.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationEARTestCase.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.weldee.beans.MyBean;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * WeldEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class WeldEmbeddedIntegrationEARTestCase
+{
+ @Deployment
+ public static EnterpriseArchive createdeployment()
+ {
+ return ShrinkWrap.create("test.ear", EnterpriseArchive.class)
+ .addModule(
+ ShrinkWrap.create("test.war", WebArchive.class)
+ .addClasses(
+ WeldEmbeddedIntegrationWARTestCase.class,
+ MyBean.class)
+ .addWebResource(
+ new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"))
+ );
+ }
+
+ @Inject
+ private MyBean instanceVariable;
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsInstanceVariable() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ instanceVariable);
+
+ Assert.assertEquals("aslak", instanceVariable.getName());
+ }
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsArgumentVariable(MyBean argumentVariable) throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ argumentVariable);
+
+ Assert.assertEquals("aslak", argumentVariable.getName());
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationJARTestCase.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationJARTestCase.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationJARTestCase.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.weldee.beans.MyBean;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * WeldEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class WeldEmbeddedIntegrationJARTestCase
+{
+ @Deployment
+ public static JavaArchive createdeployment()
+ {
+ return ShrinkWrap.create("test.jar", JavaArchive.class)
+ .addClasses(
+ WeldEmbeddedIntegrationJARTestCase.class,
+ MyBean.class)
+ .addManifestResource(
+ new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ private MyBean instanceVariable;
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsInstanceVariable() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ instanceVariable);
+
+ Assert.assertEquals("aslak", instanceVariable.getName());
+ }
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsArgumentVariable(MyBean argumentVariable) throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ argumentVariable);
+
+ Assert.assertEquals("aslak", argumentVariable.getName());
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationWARTestCase.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationWARTestCase.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/WeldEmbeddedIntegrationWARTestCase.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.weldee.beans.MyBean;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * WeldEmbeddedIntegrationTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+public class WeldEmbeddedIntegrationWARTestCase
+{
+ @Deployment
+ public static WebArchive createdeployment()
+ {
+ return ShrinkWrap.create("test.war", WebArchive.class)
+ .addClasses(
+ WeldEmbeddedIntegrationWARTestCase.class,
+ MyBean.class)
+ .addWebResource(
+ new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ private MyBean instanceVariable;
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsInstanceVariable() throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ instanceVariable);
+
+ Assert.assertEquals("aslak", instanceVariable.getName());
+ }
+
+ @Test
+ public void shouldBeAbleToInjectBeanAsArgumentVariable(MyBean argumentVariable) throws Exception
+ {
+ Assert.assertNotNull(
+ "Verify that the Bean has been injected",
+ argumentVariable);
+
+ Assert.assertEquals("aslak", argumentVariable.getName());
+ }
+}
Added: arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java
===================================================================
--- arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java (rev 0)
+++ arquillian/trunk/containers/weld-ee-embedded/src/test/java/org/jboss/arquillian/weldee/beans/MyBean.java 2010-06-15 17:32:23 UTC (rev 4529)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.weldee.beans;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * MyBean
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at ApplicationScoped
+public class MyBean
+{
+ public String getName()
+ {
+ return "aslak";
+ }
+}
More information about the jboss-svn-commits
mailing list