[weld-commits] Weld SVN: r4952 - in extensions/trunk: test and 75 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Tue Nov 10 08:13:58 EST 2009


Author: aslak
Date: 2009-11-10 08:13:57 -0500 (Tue, 10 Nov 2009)
New Revision: 4952

Added:
   extensions/trunk/test/
   extensions/trunk/test/core/
   extensions/trunk/test/core/pom.xml
   extensions/trunk/test/core/src/
   extensions/trunk/test/core/src/main/
   extensions/trunk/test/core/src/main/java/
   extensions/trunk/test/core/src/main/java/org/
   extensions/trunk/test/core/src/main/java/org/jboss/
   extensions/trunk/test/core/src/main/java/org/jboss/weld/
   extensions/trunk/test/core/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/
   extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/BootstrapResolver.java
   extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/TestCore.java
   extensions/trunk/test/core/src/main/resources/
   extensions/trunk/test/core/src/test/
   extensions/trunk/test/core/src/test/java/
   extensions/trunk/test/core/src/test/resources/
   extensions/trunk/test/junit/
   extensions/trunk/test/junit/pom.xml
   extensions/trunk/test/junit/src/
   extensions/trunk/test/junit/src/main/
   extensions/trunk/test/junit/src/main/java/
   extensions/trunk/test/junit/src/main/java/org/
   extensions/trunk/test/junit/src/main/java/org/jboss/
   extensions/trunk/test/junit/src/main/java/org/jboss/weld/
   extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/junit/
   extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/junit/CDIRunner.java
   extensions/trunk/test/junit/src/main/resources/
   extensions/trunk/test/junit/src/test/
   extensions/trunk/test/junit/src/test/java/
   extensions/trunk/test/junit/src/test/java/org/
   extensions/trunk/test/junit/src/test/java/org/jboss/
   extensions/trunk/test/junit/src/test/java/org/jboss/weld/
   extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/
   extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/junit/
   extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/junit/ModelTestCase.java
   extensions/trunk/test/junit/src/test/resources/
   extensions/trunk/test/pom.xml
   extensions/trunk/test/spi/
   extensions/trunk/test/spi/pom.xml
   extensions/trunk/test/spi/src/
   extensions/trunk/test/spi/src/main/
   extensions/trunk/test/spi/src/main/java/
   extensions/trunk/test/spi/src/main/java/org/
   extensions/trunk/test/spi/src/main/java/org/jboss/
   extensions/trunk/test/spi/src/main/java/org/jboss/weld/
   extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/spi/
   extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/spi/Bootstrap.java
   extensions/trunk/test/spi/src/main/resources/
   extensions/trunk/test/test-model/
   extensions/trunk/test/test-model/pom.xml
   extensions/trunk/test/test-model/src/
   extensions/trunk/test/test-model/src/main/
   extensions/trunk/test/test-model/src/main/java/
   extensions/trunk/test/test-model/src/main/java/org/
   extensions/trunk/test/test-model/src/main/java/org/jboss/
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Greeted.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/GreetingsObserver.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Language.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/LanguageType.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/NorwegianWelcomeService.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/SwedishWelcomeService.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/User.java
   extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/WelcomeService.java
   extensions/trunk/test/test-model/src/main/resources/
   extensions/trunk/test/test-model/src/main/resources/META-INF/
   extensions/trunk/test/test-model/src/main/resources/META-INF/beans.xml
   extensions/trunk/test/testng/
   extensions/trunk/test/testng/pom.xml
   extensions/trunk/test/testng/src/
   extensions/trunk/test/testng/src/main/
   extensions/trunk/test/testng/src/main/java/
   extensions/trunk/test/testng/src/main/java/org/
   extensions/trunk/test/testng/src/main/java/org/jboss/
   extensions/trunk/test/testng/src/main/java/org/jboss/weld/
   extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/testng/
   extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/testng/AbstractCDITest.java
   extensions/trunk/test/testng/src/main/resources/
   extensions/trunk/test/testng/src/test/
   extensions/trunk/test/testng/src/test/java/
   extensions/trunk/test/testng/src/test/java/org/
   extensions/trunk/test/testng/src/test/java/org/jboss/
   extensions/trunk/test/testng/src/test/java/org/jboss/weld/
   extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/
   extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/testng/
   extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/testng/ModelTestCase.java
   extensions/trunk/test/testng/src/test/resources/
   extensions/trunk/test/weld-impl/
   extensions/trunk/test/weld-impl/pom.xml
   extensions/trunk/test/weld-impl/src/
   extensions/trunk/test/weld-impl/src/main/
   extensions/trunk/test/weld-impl/src/main/java/
   extensions/trunk/test/weld-impl/src/main/java/org/
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/EnvironmentResolver.java
   extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/WeldTestBootstrap.java
   extensions/trunk/test/weld-impl/src/main/resources/
   extensions/trunk/test/weld-impl/src/main/resources/META-INF/
   extensions/trunk/test/weld-impl/src/main/resources/META-INF/services/
   extensions/trunk/test/weld-impl/src/main/resources/META-INF/services/org.jboss.weld.test.spi.Bootstrap
   extensions/trunk/test/weld-impl/src/test/
   extensions/trunk/test/weld-impl/src/test/java/
   extensions/trunk/test/weld-impl/src/test/resources/
Log:
Initial commit of Weld Test extention. Adds support for CDI based injection in both JUnit and TestNG tests.




Property changes on: extensions/trunk/test/core
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target


Added: extensions/trunk/test/core/pom.xml
===================================================================
--- extensions/trunk/test/core/pom.xml	                        (rev 0)
+++ extensions/trunk/test/core/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,31 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-core</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test Core</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>org.jboss.weld.test</groupId>
+			<artifactId>weld-test-spi</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>javax.enterprise</groupId>
+			<artifactId>cdi-api</artifactId>
+		</dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/BootstrapResolver.java
===================================================================
--- extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/BootstrapResolver.java	                        (rev 0)
+++ extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/BootstrapResolver.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.weld.test.core;
+
+import java.util.ServiceLoader;
+
+import org.jboss.weld.test.spi.Bootstrap;
+
+/**
+ * 
+ * 
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class BootstrapResolver
+{
+
+   public Bootstrap resolve() throws Exception
+   {
+      // TODO: throw exception on missing bootsteap etc
+      return ServiceLoader.load(Bootstrap.class).iterator().next();
+   }
+
+}

Added: extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/TestCore.java
===================================================================
--- extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/TestCore.java	                        (rev 0)
+++ extensions/trunk/test/core/src/main/java/org/jboss/weld/test/core/TestCore.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,82 @@
+package org.jboss.weld.test.core;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Qualifier;
+
+import org.jboss.weld.test.spi.Bootstrap;
+
+public class TestCore
+{
+   private Bootstrap boostrap;
+   private BeanManager manager;
+
+   public void start() throws Exception
+   {
+      boostrap = new BootstrapResolver().resolve();
+      manager = boostrap.start();
+   }
+
+   public void stop()
+   {
+      boostrap.stop();
+   }
+
+   public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
+   {
+      return getInstanceByType(manager, type, bindings);
+   }
+
+   @SuppressWarnings("unchecked")
+   private <T> T getInstanceByType(BeanManager manager, Class<T> type,
+         Annotation... bindings)
+   {
+      final Bean<?> bean = manager.getBeans(type, bindings).iterator().next();
+      CreationalContext<?> cc = manager.createCreationalContext(bean);
+      return (T) manager.getReference(bean, type, cc);
+   }
+
+   public void injectFields(Object target) throws Exception
+   {
+      Field[] fields = target.getClass().getDeclaredFields();
+      for (Field field : fields)
+      {
+         injectField(field, target);
+      }
+   }
+
+   private void injectField(Field field, Object target) throws Exception
+   {
+      if (!hasBindTypeAnnotation(field.getAnnotations()))
+      {
+         return;
+      }
+      if (!field.isAccessible())
+      {
+         field.setAccessible(true);
+      }
+      Object injectable = getInstanceByType(field.getType(), field
+            .getAnnotations());
+
+      if (injectable != null)
+      {
+         field.set(target, injectable);
+      }
+   }
+
+   public static boolean hasBindTypeAnnotation(Annotation[] annotations)
+   {
+      for (Annotation annotation : annotations)
+      {
+         if (annotation.annotationType().isAnnotationPresent(Qualifier.class))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+}


Property changes on: extensions/trunk/test/junit
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target


Added: extensions/trunk/test/junit/pom.xml
===================================================================
--- extensions/trunk/test/junit/pom.xml	                        (rev 0)
+++ extensions/trunk/test/junit/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,54 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-junit</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test JUnit Integration</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.jboss.weld.test</groupId>
+			<artifactId>weld-test-core</artifactId>
+		</dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-model</artifactId>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-weld</artifactId>
+            <scope>test</scope>
+         </dependency>
+		
+         <dependency>
+			<groupId>org.jboss.weld</groupId>
+			<artifactId>weld-core</artifactId>
+            <scope>test</scope>
+         </dependency>
+
+         <dependency>
+		   <groupId>org.jboss.weld</groupId>
+		   <artifactId>weld-se</artifactId>
+            <scope>test</scope>
+         </dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/junit/CDIRunner.java
===================================================================
--- extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/junit/CDIRunner.java	                        (rev 0)
+++ extensions/trunk/test/junit/src/main/java/org/jboss/weld/test/junit/CDIRunner.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,139 @@
+package org.jboss.weld.test.junit;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.weld.test.core.TestCore;
+import org.junit.Test;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+
+public class CDIRunner extends BlockJUnit4ClassRunner
+{
+   private TestCore core;
+
+   public CDIRunner(Class<?> klass) throws InitializationError
+   {
+      super(klass);
+      initialize();
+   }
+
+   /*
+    * Try to resolve the appropriate environment and initialize it.
+    */
+   private void initialize() throws InitializationError
+   {
+      try
+      {
+         core = new TestCore();
+         core.start();
+      } catch (Exception e)
+      {
+         throw new InitializationError(Arrays.asList((Throwable) e));
+      }
+   }
+   
+   /*
+    * Override the validation of TestMethods to support methods with arguments
+    */
+   @Override
+   protected void validateTestMethods(List<Throwable> errors)
+   {
+      validatePublicVoid(Test.class, false, errors);
+   }
+
+   protected void validatePublicVoid(Class<? extends Annotation> annotation,
+         boolean isStatic, List<Throwable> errors)
+   {
+      List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(
+            annotation);
+
+      for (FrameworkMethod eachTestMethod : methods)
+      {
+         eachTestMethod.validatePublicVoid(isStatic, errors);
+         validateBindingTypeParameters(eachTestMethod.getMethod(), errors);
+      }
+   }
+
+   protected void validateBindingTypeParameters(Method method,
+         List<Throwable> errors)
+   {
+      Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+      Class<?>[] parameterTypes = method.getParameterTypes();
+
+      for (int i = 0; i < parameterTypes.length; i++)
+      {
+         Class<?> parameterType = parameterTypes[i];
+         if (!TestCore.hasBindTypeAnnotation(parameterAnnotations[i]))
+         {
+            errors.add(new Exception("Parameter of type "
+                  + parameterType.getName() + " on method ("
+                  + method.toGenericString() + ") "
+                  + " should have a associated BindingType annotation"));
+         }
+      }
+   }
+
+   /*
+    * Override to inject TestCase class fields.
+    */
+   @Override
+   protected Object createTest() throws Exception
+   {
+      Object object = super.createTest();
+
+      core.injectFields(object);
+
+      return object;
+   }
+
+   /*
+    * Override to invoke TestMethod with injectable args.
+    */
+   @Override
+   protected Statement methodInvoker(FrameworkMethod method, Object test)
+   {
+      return new ParameterInvokerMethod(method, test);
+   }
+
+   private class ParameterInvokerMethod extends Statement
+   {
+
+      private final FrameworkMethod fTestMethod;
+
+      private Object fTarget;
+
+      public ParameterInvokerMethod(FrameworkMethod testMethod, Object target)
+      {
+         fTestMethod = testMethod;
+         fTarget = target;
+      }
+
+      @Override
+      public void evaluate() throws Throwable
+      {
+         fTestMethod.invokeExplosively(fTarget, getParameters());
+      }
+
+      private Object[] getParameters() throws Exception
+      {
+         Annotation[][] parameterAnnotations = fTestMethod.getMethod()
+               .getParameterAnnotations();
+         Class<?>[] parameterTypes = fTestMethod.getMethod()
+               .getParameterTypes();
+         Object[] parameters = new Object[parameterTypes.length];
+         for (int i = 0; i < parameterTypes.length; i++)
+         {
+            Class<?> parameterType = parameterTypes[i];
+            Annotation[] parameterAnnotation = parameterAnnotations[i];
+            parameters[i] = core.getInstanceByType(parameterType,
+                  parameterAnnotation);
+         }
+         return parameters;
+      }
+   }
+}

Added: extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/junit/ModelTestCase.java
===================================================================
--- extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/junit/ModelTestCase.java	                        (rev 0)
+++ extensions/trunk/test/junit/src/test/java/org/jboss/weld/test/junit/ModelTestCase.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,40 @@
+package org.jboss.weld.test.junit;
+
+import junit.framework.Assert;
+
+import org.jboss.weld.test.model.Language;
+import org.jboss.weld.test.model.LanguageType;
+import org.jboss.weld.test.model.User;
+import org.jboss.weld.test.model.WelcomeService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(CDIRunner.class)
+public class ModelTestCase
+{
+   // Will not be injected, no BindingType
+   private static String userName = "Aslak";
+
+   private @Language(LanguageType.NO)
+   WelcomeService service;
+
+   private User user = new User(userName);
+
+   @Test
+   public void shouldBeAbleToInjectInstanceVars() throws Exception
+   {
+      Assert.assertEquals("Hei " + userName, service.greet(user));
+      Assert.assertTrue(user.hasBeenGreetedIn(LanguageType.NO));
+      Assert.assertFalse(user.hasBeenGreetedIn(LanguageType.SE));
+   }
+
+   @Test
+   public void shouldBeAbleToInjectParameters(
+         @Language(LanguageType.SE) WelcomeService welcomeService)
+         throws Exception
+   {
+      Assert.assertEquals("Hej " + userName, welcomeService.greet(user));
+      Assert.assertTrue(user.hasBeenGreetedIn(LanguageType.SE));
+      Assert.assertFalse(user.hasBeenGreetedIn(LanguageType.NO));
+   }
+}

Added: extensions/trunk/test/pom.xml
===================================================================
--- extensions/trunk/test/pom.xml	                        (rev 0)
+++ extensions/trunk/test/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,101 @@
+<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">
+   <modelVersion>4.0.0</modelVersion>
+   <groupId>org.jboss.weld.test</groupId>
+   <artifactId>weld-test-parent</artifactId>
+   <packaging>pom</packaging>
+   
+   <parent>
+      <groupId>org.jboss.weld</groupId>
+      <artifactId>weld-extensions-parent</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <relativePath>../parent/pom.xml</relativePath>
+  </parent>
+
+   <name>Weld Test support build aggregator</name>
+   <url>http://www.seamframework.org/Weld</url>
+   
+   <modules>
+      <module>core</module>
+      <module>spi</module>
+      <module>junit</module>
+      <module>testng</module>
+      <module>weld-impl</module>
+      <module>test-model</module>
+   </modules>
+   
+   <issueManagement>
+      <system>JIRA</system>
+      <url>https://jira.jboss.org/jira/browse/WELDX/component/12312750</url>
+   </issueManagement>
+
+   <description>
+      Support for CDI in Test frameworks
+   </description>
+
+   <developers>
+      <developer>
+         <name>Aslak Knutsen</name>
+         <roles>
+            <role>Project Lead</role>
+         </roles>
+         <email>aslak at conduct.no</email>
+         <organization>Conduct</organization>
+      </developer>
+   </developers>
+
+   <dependencyManagement>
+      <dependencies>
+
+		<dependency>
+			<groupId>org.jboss.weld.test</groupId>
+			<artifactId>weld-test-spi</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-core</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-model</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-junit</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-testng</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-weld</artifactId>
+            <version>${project.version}</version>
+         </dependency>
+
+
+         <dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.7</version>
+         </dependency>
+
+         <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>4.6</version>
+         </dependency>
+
+      </dependencies>
+	</dependencyManagement> 
+	
+</project>


Property changes on: extensions/trunk/test/spi
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target



Added: extensions/trunk/test/spi/pom.xml
===================================================================
--- extensions/trunk/test/spi/pom.xml	                        (rev 0)
+++ extensions/trunk/test/spi/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,26 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-spi</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test Bootstap SPI</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>javax.enterprise</groupId>
+			<artifactId>cdi-api</artifactId>
+		</dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/spi/Bootstrap.java
===================================================================
--- extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/spi/Bootstrap.java	                        (rev 0)
+++ extensions/trunk/test/spi/src/main/java/org/jboss/weld/test/spi/Bootstrap.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.weld.test.spi;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Extension point for bootstrapping CDI containers.
+ * 
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public interface Bootstrap
+{
+
+   /**
+    * Called to initialize/start the container during test startup.
+    */
+   public BeanManager start() throws Exception;
+
+   /**
+    * Called to destroy/stop the container during test shutdown.
+    */
+   public void stop();
+}


Property changes on: extensions/trunk/test/test-model
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target



Added: extensions/trunk/test/test-model/pom.xml
===================================================================
--- extensions/trunk/test/test-model/pom.xml	                        (rev 0)
+++ extensions/trunk/test/test-model/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,26 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-model</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test Test Model</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>javax.enterprise</groupId>
+			<artifactId>cdi-api</artifactId>
+		</dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Greeted.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Greeted.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Greeted.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,18 @@
+package org.jboss.weld.test.model;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Target( { PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Qualifier
+public @interface Greeted
+{
+
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/GreetingsObserver.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/GreetingsObserver.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/GreetingsObserver.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,20 @@
+package org.jboss.weld.test.model;
+
+import javax.enterprise.event.Observes;
+
+public class GreetingsObserver
+{
+
+   public void onUserGreetedInNorwegian(
+         @Observes @Greeted @Language(LanguageType.NO) User user)
+   {
+      user.wasGreetedIn(LanguageType.NO);
+   }
+
+   public void onUserGreetedInSwedish(
+         @Observes @Greeted @Language(LanguageType.SE) User user)
+   {
+      user.wasGreetedIn(LanguageType.SE);
+   }
+
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Language.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Language.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/Language.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,20 @@
+package org.jboss.weld.test.model;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Retention(RUNTIME)
+ at Target( { TYPE, METHOD, FIELD, PARAMETER })
+ at Qualifier
+public @interface Language
+{
+   LanguageType value();
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/LanguageType.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/LanguageType.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/LanguageType.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,6 @@
+package org.jboss.weld.test.model;
+
+public enum LanguageType
+{
+   NO, SE
+}
\ No newline at end of file

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/NorwegianWelcomeService.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/NorwegianWelcomeService.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/NorwegianWelcomeService.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,20 @@
+package org.jboss.weld.test.model;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+ at Language(LanguageType.NO)
+public class NorwegianWelcomeService implements WelcomeService
+{
+   @Inject
+   @Greeted
+   @Language(LanguageType.NO)
+   private Event<User> greetedUserEvent;
+
+   public String greet(User user)
+   {
+      greetedUserEvent.fire(user);
+      return "Hei " + user.getFirstName();
+   }
+
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/SwedishWelcomeService.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/SwedishWelcomeService.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/SwedishWelcomeService.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,20 @@
+package org.jboss.weld.test.model;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+ at Language(LanguageType.SE)
+public class SwedishWelcomeService implements WelcomeService
+{
+   @Inject
+   @Greeted
+   @Language(LanguageType.SE)
+   private Event<User> greetedUserEvent;
+
+   public String greet(User user)
+   {
+      greetedUserEvent.fire(user);
+      return "Hej " + user.getFirstName();
+   }
+
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/User.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/User.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/User.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,37 @@
+package org.jboss.weld.test.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class User
+{
+   private String firstName;
+
+   private List<LanguageType> greetedInLanguage = new ArrayList<LanguageType>();
+
+   public User(String firstName)
+   {
+      this.firstName = firstName;
+   }
+
+   public String getFirstName()
+   {
+      return firstName;
+   }
+
+   @Override
+   public String toString()
+   {
+      return firstName;
+   }
+
+   public void wasGreetedIn(LanguageType language)
+   {
+      greetedInLanguage.add(language);
+   }
+
+   public boolean hasBeenGreetedIn(LanguageType language)
+   {
+      return greetedInLanguage.contains(language);
+   }
+}

Added: extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/WelcomeService.java
===================================================================
--- extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/WelcomeService.java	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/java/org/jboss/weld/test/model/WelcomeService.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,6 @@
+package org.jboss.weld.test.model;
+
+public interface WelcomeService
+{
+   String greet(User user);
+}

Added: extensions/trunk/test/test-model/src/main/resources/META-INF/beans.xml
===================================================================
--- extensions/trunk/test/test-model/src/main/resources/META-INF/beans.xml	                        (rev 0)
+++ extensions/trunk/test/test-model/src/main/resources/META-INF/beans.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1 @@
+<beans/>
\ No newline at end of file


Property changes on: extensions/trunk/test/testng
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target
temp-testng-customsuite.xml
test-output


Added: extensions/trunk/test/testng/pom.xml
===================================================================
--- extensions/trunk/test/testng/pom.xml	                        (rev 0)
+++ extensions/trunk/test/testng/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,55 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-testng</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test TestNG Integration</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>org.testng</groupId>
+			<artifactId>testng</artifactId>
+			<classifier>jdk15</classifier>
+		</dependency>
+
+		<dependency>
+			<groupId>org.jboss.weld.test</groupId>
+			<artifactId>weld-test-core</artifactId>
+		</dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-model</artifactId>
+         </dependency>
+
+         <dependency>
+            <groupId>org.jboss.weld.test</groupId>
+            <artifactId>weld-test-weld</artifactId>
+            <scope>test</scope>
+         </dependency>
+
+         <dependency>
+			<groupId>org.jboss.weld</groupId>
+			<artifactId>weld-core</artifactId>
+            <scope>test</scope>
+         </dependency>
+
+         <dependency>
+		   <groupId>org.jboss.weld</groupId>
+		   <artifactId>weld-se</artifactId>
+            <scope>test</scope>
+         </dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/testng/AbstractCDITest.java
===================================================================
--- extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/testng/AbstractCDITest.java	                        (rev 0)
+++ extensions/trunk/test/testng/src/main/java/org/jboss/weld/test/testng/AbstractCDITest.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,30 @@
+package org.jboss.weld.test.testng;
+
+import org.jboss.weld.test.core.TestCore;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.BeforeTest;
+
+public class AbstractCDITest
+{
+   private TestCore core;
+
+   @BeforeSuite
+   public void create() throws Exception
+   {
+      core = new TestCore();
+      core.start();
+   }
+
+   @BeforeTest
+   public void injectParameters() throws Exception
+   {
+      core.injectFields(this);
+   }
+
+   @AfterSuite
+   public void destory()
+   {
+      core.stop();
+   }
+}

Added: extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/testng/ModelTestCase.java
===================================================================
--- extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/testng/ModelTestCase.java	                        (rev 0)
+++ extensions/trunk/test/testng/src/test/java/org/jboss/weld/test/testng/ModelTestCase.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,28 @@
+package org.jboss.weld.test.testng;
+
+import org.jboss.weld.test.model.Language;
+import org.jboss.weld.test.model.LanguageType;
+import org.jboss.weld.test.model.User;
+import org.jboss.weld.test.model.WelcomeService;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class ModelTestCase extends AbstractCDITest
+{
+   // Will not be injected, no BindingType
+   private static String userName = "Aslak";
+
+   private @Language(LanguageType.NO)
+   WelcomeService service;
+
+   private User user = new User(userName);
+
+   @Test
+   public void shouldBeAbleToInjectInstanceVars() throws Exception
+   {
+      Assert.assertEquals("Hei " + userName, service.greet(user));
+      Assert.assertTrue(user.hasBeenGreetedIn(LanguageType.NO));
+      Assert.assertFalse(user.hasBeenGreetedIn(LanguageType.SE));
+   }
+
+}


Property changes on: extensions/trunk/test/weld-impl
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target



Added: extensions/trunk/test/weld-impl/pom.xml
===================================================================
--- extensions/trunk/test/weld-impl/pom.xml	                        (rev 0)
+++ extensions/trunk/test/weld-impl/pom.xml	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,37 @@
+<?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>
+		<artifactId>weld-test-parent</artifactId>
+		<groupId>org.jboss.weld.test</groupId>
+		<version>1.0.0-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.weld.test</groupId>
+	<artifactId>weld-test-weld</artifactId>
+	<version>1.0.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Weld Test Weld Bootstrap</name>
+	<url>http://www.seamframework.org/Weld</url>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>org.jboss.weld.test</groupId>
+			<artifactId>weld-test-spi</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.jboss.weld</groupId>
+			<artifactId>weld-core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.jboss.weld</groupId>
+			<artifactId>weld-se</artifactId>
+			<optional>true</optional>
+		</dependency>
+
+	</dependencies>
+
+</project>

Added: extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/EnvironmentResolver.java
===================================================================
--- extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/EnvironmentResolver.java	                        (rev 0)
+++ extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/EnvironmentResolver.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.weld.test.weld;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Helper class to find the appropriate environment to 'bootstrap'
+ * 
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class EnvironmentResolver
+{
+   public Environment resolve() throws Exception
+   {
+      Environment environment = findSupported(
+//            new EEEnvironment(),
+//            new PreviouslyInitiatedEnvironment(), 
+            new SEEnvironment());
+      if (environment == null)
+      {
+         throw new Exception(
+               "No appropriate environment found. "
+                     + "The test is running in a non EE/Servlet environment and the Webbeans SE Extension is missing from classpath");
+      }
+      return environment;
+   }
+
+   private Environment findSupported(Environment... environments)
+   {
+      for (Environment environment : environments)
+      {
+         if (environment.isSupported())
+         {
+            return environment;
+         }
+      }
+      return null;
+   }
+
+   public static abstract class Environment
+   {
+
+      boolean isSupported()
+      {
+         try
+         {
+            if(getBeanManager() != null) {
+               return true;
+            }
+         } catch (Exception e)
+         {
+         }
+         return false;
+      }
+
+      void initialize() throws Exception
+      {
+      }
+
+      void stop()
+      {
+      }
+
+      abstract BeanManager getBeanManager() throws Exception;
+   }
+
+   public static class SEEnvironment extends Environment
+   {
+      private static final String SE_EXTENTION_CLASSNAME = "org.jboss.weld.environment.se.StartMain";
+      private static final String SE_EXTENTION_CLASSNAME_METHOD = "go";
+      private static final String SE_EXTENTION_BOOSTRAP = "org.jboss.weld.environment.se.ShutdownManager";
+      private static final String SE_EXTENTION_BOOSTRAP_METHOD = "shutdown";
+
+      private boolean initialized = false;
+      private BeanManager manager;
+      
+      @Override
+      boolean isSupported()
+      {
+         try
+         {
+            Thread.currentThread().getContextClassLoader().loadClass(
+                  SE_EXTENTION_CLASSNAME);
+            return true;
+         } catch (Exception e)
+         {
+            return false;
+         }
+      }
+
+      @Override
+      void initialize() throws Exception
+      {
+         if (!initialized)
+         {
+            Class<?> seExtensionMainClass = Thread.currentThread().getContextClassLoader()
+                    .loadClass(SE_EXTENTION_CLASSNAME);
+
+            Method seExtensionStartMethod = seExtensionMainClass.getMethod(SE_EXTENTION_CLASSNAME_METHOD);
+            Constructor<?> seExtensionConstructor = seExtensionMainClass.getConstructor(String[].class);
+            Object seExtension = seExtensionConstructor.newInstance((Object)new String[0]);
+            manager = (BeanManager)seExtensionStartMethod.invoke(seExtension);
+            initialized = true;
+         }
+      }
+
+      @Override
+      BeanManager getBeanManager() throws Exception
+      {
+         if (!initialized)
+         {
+            throw new Exception("Environment has not been initialized.");
+         }
+         return manager;
+      }
+
+      @Override
+      void stop()
+      {
+         try
+         {
+            Class<?> bootstrapClass = Thread.currentThread().getContextClassLoader()
+                  .loadClass(SE_EXTENTION_BOOSTRAP);
+            
+            Method shutdownMethod = bootstrapClass.getMethod(SE_EXTENTION_BOOSTRAP_METHOD);
+            Object bootstrap = getInstanceByType(manager, bootstrapClass);
+            
+            shutdownMethod.invoke(bootstrap);
+         } 
+         catch (Exception e)
+         {
+            throw new RuntimeException(
+                  "Could load bootstrap[" + SE_EXTENTION_BOOSTRAP + "] class for shutdown", e);
+         }
+      }
+   }
+
+//   public static class EEEnvironment extends Environment
+//   {
+//      private static final String EE_CONTEXT_NAME = "java:comp/BeanManager";
+//
+//      @Override
+//      BeanManager getBeanManager() throws Exception
+//      {
+//         InitialContext context = new InitialContext();
+//         return (BeanManager) context.lookup(EE_CONTEXT_NAME);
+//      }
+//   }
+
+//   public static class PreviouslyInitiatedEnvironment extends Environment
+//   {
+//      @Override
+//      BeanManager getBeanManager() throws Exception
+//      {
+//         return null; // CurrentManager.rootManager();
+//      }
+//   }
+
+   @SuppressWarnings("unchecked")
+   public static <T> T getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings)
+   {
+      final Bean<?> bean = manager.getBeans(type).iterator().next();
+      CreationalContext cc = manager.createCreationalContext(bean);
+      return (T) manager.getReference(bean, type, cc);
+   }
+
+}

Added: extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/WeldTestBootstrap.java
===================================================================
--- extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/WeldTestBootstrap.java	                        (rev 0)
+++ extensions/trunk/test/weld-impl/src/main/java/org/jboss/weld/test/weld/WeldTestBootstrap.java	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.weld.test.weld;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.weld.test.spi.Bootstrap;
+import org.jboss.weld.test.weld.EnvironmentResolver.Environment;
+
+/**
+ * Weld Test extension Bootstrap SPI for the Weld CDI implementation.
+ * 
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class WeldTestBootstrap implements Bootstrap
+{
+   private Environment environment;
+   private BeanManager manager;
+   
+   public BeanManager start() throws Exception
+   {
+      if(environment == null && manager == null) {
+         environment = new EnvironmentResolver().resolve();
+         environment.initialize();
+         manager = environment.getBeanManager();
+      }
+      return manager;
+   }
+
+   public void stop()
+   {
+      if(environment != null && manager != null) {
+         environment.stop();
+         environment = null;
+         manager = null;
+      }
+   }
+}

Added: extensions/trunk/test/weld-impl/src/main/resources/META-INF/services/org.jboss.weld.test.spi.Bootstrap
===================================================================
--- extensions/trunk/test/weld-impl/src/main/resources/META-INF/services/org.jboss.weld.test.spi.Bootstrap	                        (rev 0)
+++ extensions/trunk/test/weld-impl/src/main/resources/META-INF/services/org.jboss.weld.test.spi.Bootstrap	2009-11-10 13:13:57 UTC (rev 4952)
@@ -0,0 +1 @@
+org.jboss.weld.test.weld.WeldTestBootstrap
\ No newline at end of file



More information about the weld-commits mailing list