Weld SVN: r5283 - in archetypes/trunk/jsf: jee-minimal/src/main/resources/archetype-resources and 1 other directories.
by weld-commits@lists.jboss.org
Author: dan.j.allen
Date: 2009-12-14 14:08:39 -0500 (Mon, 14 Dec 2009)
New Revision: 5283
Modified:
archetypes/trunk/jsf/jee-minimal/src/main/resources/archetype-resources/pom.xml
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml
archetypes/trunk/jsf/servlet-minimal/src/main/resources/archetype-resources/pom.xml
Log:
comment
Modified: archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml
===================================================================
--- archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml 2009-12-14 12:16:21 UTC (rev 5282)
+++ archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml 2009-12-14 19:08:39 UTC (rev 5283)
@@ -1,5 +1,5 @@
-## Custom Velocity declaration to allow us to escape EL expressions.
-## Removes archetype warnings about unrecognized variables.
+## Custom Velocity declaration to allow us to escape Maven variable placeholders
+## Prevents archetype warnings about unrecognized variables
#set( $expr_start = '${' )
#set( $expr_end = '}' )
<?xml version="1.0" encoding="UTF-8"?>
Modified: archetypes/trunk/jsf/jee-minimal/src/main/resources/archetype-resources/pom.xml
===================================================================
--- archetypes/trunk/jsf/jee-minimal/src/main/resources/archetype-resources/pom.xml 2009-12-14 12:16:21 UTC (rev 5282)
+++ archetypes/trunk/jsf/jee-minimal/src/main/resources/archetype-resources/pom.xml 2009-12-14 19:08:39 UTC (rev 5283)
@@ -1,5 +1,5 @@
-## Custom Velocity declaration to allow us to escape EL expressions.
-## Removes archetype warnings about unrecognized variables.
+## Custom Velocity declaration to allow us to escape Maven variable placeholders
+## Prevents archetype warnings about unrecognized variables.
#set( $expr_start = '${' )
#set( $expr_end = '}' )
<?xml version="1.0" encoding="UTF-8"?>
Modified: archetypes/trunk/jsf/servlet-minimal/src/main/resources/archetype-resources/pom.xml
===================================================================
--- archetypes/trunk/jsf/servlet-minimal/src/main/resources/archetype-resources/pom.xml 2009-12-14 12:16:21 UTC (rev 5282)
+++ archetypes/trunk/jsf/servlet-minimal/src/main/resources/archetype-resources/pom.xml 2009-12-14 19:08:39 UTC (rev 5283)
@@ -1,3 +1,5 @@
+## Custom Velocity declaration to allow us to escape Maven variable placeholders
+## Prevents archetype warnings about unrecognized variables
#set( $expr_start = '${' )
#set( $expr_end = '}' )
<?xml version="1.0" encoding="UTF-8"?>
14 years, 11 months
Weld SVN: r5273 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2009-12-11 16:22:22 -0500 (Fri, 11 Dec 2009)
New Revision: 5273
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Spidery.java
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderConsumer.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderProducer.java
Log:
Disambiguating FunnelWeaver
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderConsumer.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderConsumer.java 2009-12-11 16:17:50 UTC (rev 5272)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderConsumer.java 2009-12-11 21:22:22 UTC (rev 5273)
@@ -4,7 +4,7 @@
class FunnelWeaverSpiderConsumer
{
- @Inject
+ @Inject @Spidery
private FunnelWeaver<Spider> injectedSpider;
public FunnelWeaver<Spider> getInjectedSpider()
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderProducer.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderProducer.java 2009-12-11 16:17:50 UTC (rev 5272)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/FunnelWeaverSpiderProducer.java 2009-12-11 21:22:22 UTC (rev 5273)
@@ -5,8 +5,10 @@
class FunnelWeaverSpiderProducer
{
private static FunnelWeaver<Spider> spider;
- @Produces public FunnelWeaver<Spider> getFunnelWeaverSpider = new FunnelWeaver<Spider>();
+ @Produces @Spidery
+ public FunnelWeaver<Spider> getFunnelWeaverSpider = new FunnelWeaver<Spider>();
+
public FunnelWeaverSpiderProducer()
{
spider = this.getFunnelWeaverSpider;
Copied: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Spidery.java (from rev 5268, cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Foo.java)
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Spidery.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Spidery.java 2009-12-11 21:22:22 UTC (rev 5273)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright <Year>, Red Hat, Inc. and/or its affiliates, 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.jsr299.tck.tests.implementation.producer.field.definition;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@interface Spidery
+{
+
+}
\ No newline at end of file
Property changes on: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/producer/field/definition/Spidery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 11 months
Weld SVN: r5272 - in core/trunk/tests/src/test/java/org/jboss/weld/tests: generic and 1 other directory.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2009-12-11 11:17:50 -0500 (Fri, 11 Dec 2009)
New Revision: 5272
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/
core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBean.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBeanTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericInterface.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/TestBean.java
Log:
Adding unit test for generic beans.
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBean.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBean.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBean.java 2009-12-11 16:17:50 UTC (rev 5272)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright <Year>, Red Hat, Inc. and/or its affiliates, 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.tests.generic;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class GenericBean<T> implements GenericInterface<T>
+{
+
+ public T echo(T parameter)
+ {
+ return parameter;
+ }
+
+}
Copied: core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBeanTest.java (from rev 5268, core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/PartialDecoratorTest.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBeanTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericBeanTest.java 2009-12-11 16:17:50 UTC (rev 5272)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright <Year>, Red Hat, Inc. and/or its affiliates, 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.tests.generic;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Artifact
+public class GenericBeanTest extends AbstractWeldTest
+{
+
+ @Test(groups = "broken")
+ public void testGenericBean()
+ {
+ TestBean testBean = getCurrentManager().getInstanceByType(TestBean.class);
+ assert "Hello".equals(testBean.echo("Hello"));
+ assert Integer.valueOf(1).equals(testBean.echo(1));
+ }
+}
\ No newline at end of file
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericInterface.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericInterface.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/GenericInterface.java 2009-12-11 16:17:50 UTC (rev 5272)
@@ -0,0 +1,9 @@
+package org.jboss.weld.tests.generic;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface GenericInterface<T>
+{
+ T echo(T parameter);
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/TestBean.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/TestBean.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/generic/TestBean.java 2009-12-11 16:17:50 UTC (rev 5272)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright <Year>, Red Hat, Inc. and/or its affiliates, 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.tests.generic;
+
+import javax.inject.Inject;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class TestBean
+{
+ @Inject GenericInterface<String> genericStringField;
+
+ @Inject GenericInterface<Integer> genericIntegerField;
+
+ public String echo(String param)
+ {
+ return genericStringField.echo(param);
+ }
+
+ public Integer echo(Integer param)
+ {
+ return genericIntegerField.echo(param);
+ }
+
+}
14 years, 11 months
Weld SVN: r5271 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/decorator.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2009-12-11 08:48:39 -0500 (Fri, 11 Dec 2009)
New Revision: 5271
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/decorator/DecoratorNotInjectedTest.java
Log:
minor
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/decorator/DecoratorNotInjectedTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/decorator/DecoratorNotInjectedTest.java 2009-12-11 08:42:46 UTC (rev 5270)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/decorator/DecoratorNotInjectedTest.java 2009-12-11 13:48:39 UTC (rev 5271)
@@ -32,7 +32,7 @@
public class DecoratorNotInjectedTest extends AbstractJSR299Test
{
- @Test(groups = { "resolution" })
+ @Test(groups = { "injection" })
@SpecAssertion(section = "5.1.4", id = "a")
public void testDecoratorNotResolved()
{
14 years, 11 months
Weld SVN: r5270 - doc/trunk/reference/en-US.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-11 03:42:46 -0500 (Fri, 11 Dec 2009)
New Revision: 5270
Modified:
doc/trunk/reference/en-US/extend.xml
doc/trunk/reference/en-US/injection.xml
Log:
Minor. API updates, var typo in example.
Modified: doc/trunk/reference/en-US/extend.xml
===================================================================
--- doc/trunk/reference/en-US/extend.xml 2009-12-11 08:16:06 UTC (rev 5269)
+++ doc/trunk/reference/en-US/extend.xml 2009-12-11 08:42:46 UTC (rev 5270)
@@ -182,19 +182,18 @@
observers and contexts programmatically.
</para>
-<programlisting role="JAVA"><![CDATA[public interface Manager {
+<programlisting role="JAVA"><![CDATA[public interface BeanManager {
public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> ctx);
public Object getInjectableReference(InjectionPoint ij, CreationalContext<?> ctx);
public <T> CreationalContext<T> createCreationalContext(Contextual<T> contextual);
- public Set<Bean<?>> getBeans(Type beanType, Annotation... bindings);
+ public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers);
public Set<Bean<?>> getBeans(String name);
- public <X> Bean<? extends X> getMostSpecializedBean(Bean<X> bean);
public Bean<?> getPassivationCapableBean(String id);
public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans);
public void validate(InjectionPoint injectionPoint);
- public void fireEvent(Object event, Annotation... bindings);
- public <T> Set<ObserverMethod<?, T>> resolveObserverMethods(T event, Annotation... bindings);
- public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... bindings);
+ public void fireEvent(Object event, Annotation... qualifiers);
+ public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T event, Annotation... qualifiers);
+ public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... qualifiers);
public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings);
public boolean isScope(Class<? extends Annotation> annotationType);
public boolean isNormalScope(Class<? extends Annotation> annotationType);
@@ -255,10 +254,10 @@
InjectionTarget<SomeFrameworkComponent> it = beanManager.createInjectionTarget(type);
//each instance needs its own CDI CreationalContext
-CreationalContext instanceContext = beanManager.createCreationalContext(null);
+CreationalContext ctx = beanManager.createCreationalContext(null);
//instantiate the framework component and inject its dependencies
-SomeFrameworkComponent instance = it.produce(instanceContext); //call the constructor
+SomeFrameworkComponent instance = it.produce(ctx); //call the constructor
it.inject(instance, ctx); //call initializer methods and perform field injection
it.postConstruct(instance); //call the @PostConstruct method
Modified: doc/trunk/reference/en-US/injection.xml
===================================================================
--- doc/trunk/reference/en-US/injection.xml 2009-12-11 08:16:06 UTC (rev 5269)
+++ doc/trunk/reference/en-US/injection.xml 2009-12-11 08:42:46 UTC (rev 5270)
@@ -744,7 +744,7 @@
@Produces @HttpParam("")
String getParamValue(ServletRequest request, InjectionPoint ip) {
- return request.getParameter(ip.getAnnotation(HttpParam.class).value());
+ return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
}
}]]></programlisting>
@@ -756,11 +756,13 @@
interface:</para>
<programlisting role="JAVA"><![CDATA[public interface InjectionPoint {
- public Object getInstance();
- public Bean<?> getBean();
- public Member getMember():
- public <T extends Annotation> T getAnnotation(Class<T> annotation);
- public Set<T extends Annotation> getAnnotations();
+ public Type getType();
+ public Set<Annotation> getQualifiers();
+ public Bean<?> getBean();
+ public Member getMember();
+ public Annotated getAnnotated();
+ public boolean isDelegate();
+ public boolean isTransient();
}]]></programlisting>
</section>
14 years, 11 months
Weld SVN: r5269 - in java-se/trunk/src/test/java/org/jboss/weld/environment/se/test: beans/threading and 1 other directory.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2009-12-11 03:16:06 -0500 (Fri, 11 Dec 2009)
New Revision: 5269
Added:
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadRunner.java
Removed:
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java
Modified:
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java
Log:
WELDX-19: refactor
Modified: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java 2009-12-11 00:09:09 UTC (rev 5268)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java 2009-12-11 08:16:06 UTC (rev 5269)
@@ -16,6 +16,7 @@
*/
package org.jboss.weld.environment.se.test;
+import org.jboss.weld.environment.se.test.beans.threading.ThreadRunner;
import java.util.ArrayList;
import java.util.List;
@@ -34,8 +35,8 @@
public class ThreadContextTest
{
- static final int NUM_THREADS = 10;
- static final int NUM_LOOPS = 10;
+ public static final int NUM_THREADS = 10;
+ public static final int NUM_LOOPS = 10;
@Test
public void testThreadContext()
Deleted: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java 2009-12-11 00:09:09 UTC (rev 5268)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java 2009-12-11 08:16:06 UTC (rev 5269)
@@ -1,87 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.inject.Inject;
-import org.jboss.weld.environment.se.test.beans.threading.SingletonCounter;
-import org.jboss.weld.environment.se.test.beans.threading.ThreadCounter;
-
-import static org.testng.Assert.assertEquals;
-
-/**
- * An bean which implements Runnable and therefore can be run in a separate thread.
- * All such beans, when passed to Thread.start(), will be decorated by the
- * RunnableDecorator which will take care of making ThreadContext available to
- * that thread for resolution of @ThreadScoped beans.
- * @author Peter Royle
- */
-public class ThreadRunner implements Runnable
-{
-
- // an application scoped counter
- @Inject private SingletonCounter appCounter;
- // a thread scoped counter
- @Inject private ThreadCounter threadCounter;
- // a name for logging
- private String name = "Unnamed";
- // gather exceptions encountered for re-throwing in the test class
- private List<Exception> exceptions = new ArrayList<Exception>();
-
- /**
- * Run a loop, incrementing both the thread-scoped and application scoped
- * counters with each iteration.
- */
- public void run()
- {
- try
- {
-
- // Thread scoped counter should start at zero ...
- assertEquals(0, threadCounter.getCount());
-
- for (int loop = 1; loop <= ThreadContextTest.NUM_LOOPS; loop++)
- {
- final int appCount = appCounter.increment();
- final int threadCount = threadCounter.increment();
- System.out.println(name + " : " + appCount + ", " + threadCount);
- assertEquals(loop, threadCount);
- }
- // ... and end at the number of loops
- assertEquals(ThreadContextTest.NUM_LOOPS, threadCounter.getCount());
- } catch (Exception e)
- {
- this.exceptions.add(e);
- }
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public List<Exception> getExceptions()
- {
- return exceptions;
- }
-}
Copied: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadRunner.java (from rev 5267, java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java)
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadRunner.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadRunner.java 2009-12-11 08:16:06 UTC (rev 5269)
@@ -0,0 +1,86 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test.beans.threading;
+
+import org.jboss.weld.environment.se.test.*;
+import java.util.ArrayList;
+import java.util.List;
+import javax.inject.Inject;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * An bean which implements Runnable and therefore can be run in a separate thread.
+ * All such beans, when passed to Thread.start(), will be decorated by the
+ * RunnableDecorator which will take care of making ThreadContext available to
+ * that thread for resolution of @ThreadScoped beans.
+ * @author Peter Royle
+ */
+public class ThreadRunner implements Runnable
+{
+
+ // an application scoped counter
+ @Inject private SingletonCounter appCounter;
+ // a thread scoped counter
+ @Inject private ThreadCounter threadCounter;
+ // a name for logging
+ private String name = "Unnamed";
+ // gather exceptions encountered for re-throwing in the test class
+ private List<Exception> exceptions = new ArrayList<Exception>();
+
+ /**
+ * Run a loop, incrementing both the thread-scoped and application scoped
+ * counters with each iteration.
+ */
+ public void run()
+ {
+ try
+ {
+
+ // Thread scoped counter should start at zero ...
+ assertEquals(0, threadCounter.getCount());
+
+ for (int loop = 1; loop <= ThreadContextTest.NUM_LOOPS; loop++)
+ {
+ final int appCount = appCounter.increment();
+ final int threadCount = threadCounter.increment();
+ System.out.println(name + " : " + appCount + ", " + threadCount);
+ assertEquals(loop, threadCount);
+ }
+ // ... and end at the number of loops
+ assertEquals(ThreadContextTest.NUM_LOOPS, threadCounter.getCount());
+ } catch (Exception e)
+ {
+ this.exceptions.add(e);
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public List<Exception> getExceptions()
+ {
+ return exceptions;
+ }
+}
14 years, 11 months
Weld SVN: r5268 - java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2009-12-10 19:09:09 -0500 (Thu, 10 Dec 2009)
New Revision: 5268
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java
Log:
WELDX-19: Cleanup threadcontext after thread is run
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java 2009-12-10 13:31:14 UTC (rev 5267)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java 2009-12-11 00:09:09 UTC (rev 5268)
@@ -46,6 +46,7 @@
threadContext.setActive(true);
// run the original thread
runnable.run();
+ threadContext.destroy();
}
14 years, 11 months
Weld SVN: r5267 - in java-se/trunk/src: main/java/org/jboss/weld/environment/se/contexts and 5 other directories.
by weld-commits@lists.jboss.org
Author: peteroyle
Date: 2009-12-10 08:31:14 -0500 (Thu, 10 Dec 2009)
New Revision: 5267
Added:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/
java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadContext.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadScoped.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/
java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/Counter.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/SingletonCounter.java
java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadCounter.java
Modified:
java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
java-se/trunk/src/main/java/org/jboss/weld/environment/se/WeldSEBeanRegistrant.java
java-se/trunk/src/test/resources/META-INF/beans.xml
Log:
WELDX-19: Implemented ThreadContext and @ThreadScoped
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2009-12-10 12:25:20 UTC (rev 5266)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/Weld.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -17,8 +17,6 @@
package org.jboss.weld.environment.se;
import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.jws.soap.InitParam;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Environments;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
Modified: java-se/trunk/src/main/java/org/jboss/weld/environment/se/WeldSEBeanRegistrant.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/WeldSEBeanRegistrant.java 2009-12-10 12:25:20 UTC (rev 5266)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/WeldSEBeanRegistrant.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -16,26 +16,46 @@
*/
package org.jboss.weld.environment.se;
+import org.jboss.weld.environment.se.threading.RunnableDecorator;
import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
+import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
import org.jboss.weld.environment.se.beans.InstanceManager;
import org.jboss.weld.environment.se.beans.ParametersFactory;
+import org.jboss.weld.environment.se.contexts.ThreadContext;
/**
- * Explicitly registers all of the 'built-in' Java SE related beans.
+ * Explicitly registers all of the 'built-in' Java SE related beans and contexts.
* @author Peter Royle
*/
public class WeldSEBeanRegistrant implements Extension
{
- public void registerWeldSEBeans(@Observes BeforeBeanDiscovery event, BeanManager beanManager)
+ public static ThreadContext THREAD_CONTEXT = null;
+
+ public void registerWeldSEBeans(@Observes BeforeBeanDiscovery event, BeanManager manager)
{
- event.addAnnotatedType(beanManager.createAnnotatedType(ShutdownManager.class));
- event.addAnnotatedType(beanManager.createAnnotatedType(ParametersFactory.class));
- event.addAnnotatedType(beanManager.createAnnotatedType(InstanceManager.class));
- event.addAnnotatedType(beanManager.createAnnotatedType(Weld.class));
+ event.addAnnotatedType(manager.createAnnotatedType(ShutdownManager.class));
+ event.addAnnotatedType(manager.createAnnotatedType(ParametersFactory.class));
+ event.addAnnotatedType(manager.createAnnotatedType(InstanceManager.class));
+ event.addAnnotatedType(manager.createAnnotatedType(Weld.class));
+ event.addAnnotatedType(manager.createAnnotatedType(RunnableDecorator.class));
}
+ public void registerWeldSEContexts(@Observes AfterBeanDiscovery event)
+ {
+ // set up this thread's bean store
+ BeanStore beanStore = new HashMapBeanStore();
+ final ThreadContext threadContext = new ThreadContext();
+ threadContext.setBeanStore(beanStore);
+
+ // activate and add context
+ threadContext.setActive(true);
+ event.addContext(threadContext);
+ THREAD_CONTEXT = threadContext;
+ }
}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadContext.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadContext.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadContext.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,59 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.environment.se.contexts;
+
+import org.jboss.weld.context.AbstractThreadLocalMapContext;
+
+/**
+ * The thread context. Works with @ThreadScoped beans, maintaining a separate
+ * context for each thread.
+ *
+ * @author Nicklas Karlsson
+ * @author Peter Royle
+ */
+public class ThreadContext extends AbstractThreadLocalMapContext
+{
+
+ /**
+ * Constructor
+ */
+ public ThreadContext()
+ {
+ super(ThreadScoped.class);
+ }
+
+ @Override
+ public String toString()
+ {
+ String active = isActive() ? "Active " : "Inactive ";
+ String beanStoreInfo = getBeanStore() == null ? "" : getBeanStore().toString();
+ return active + "thread context " + beanStoreInfo;
+ }
+
+ @Override
+ protected boolean isCreationLockRequired()
+ {
+ return false;
+ }
+
+}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadScoped.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadScoped.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/contexts/ThreadScoped.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,41 @@
+/*
+* 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.environment.se.contexts;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.enterprise.context.NormalScope;
+
+/**
+ * Used to represent that a managed bean is scoped to the current thread.
+ * @author Peter Royle
+ */
+@Target( { TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+@Documented
+@NormalScope
+@Inherited
+public @interface ThreadScoped
+{
+}
Added: java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java
===================================================================
--- java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java (rev 0)
+++ java-se/trunk/src/main/java/org/jboss/weld/environment/se/threading/RunnableDecorator.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -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.environment.se.threading;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
+import org.jboss.weld.environment.se.WeldSEBeanRegistrant;
+import org.jboss.weld.environment.se.contexts.ThreadContext;
+
+/**
+ * Decorator for all beans which implements Runnable. It intercepts the call
+ * to the run() method to set up the ThreadContext for the new thread so that
+ * instances of @ThreadScoped beans can be correctly resolved.
+ * @author Peter Royle
+ */
+@Decorator
+public class RunnableDecorator implements Runnable {
+
+ @Inject @Delegate @Any Runnable runnable;
+
+ /**
+ * Set up the ThreadContet and delegate.
+ */
+ public void run()
+ {
+ // set up context for this thread
+ final ThreadContext threadContext = WeldSEBeanRegistrant.THREAD_CONTEXT;
+ threadContext.setBeanStore(new HashMapBeanStore());
+ threadContext.setActive(true);
+ // run the original thread
+ runnable.run();
+ }
+
+
+
+}
Added: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadContextTest.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,91 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test;
+
+import java.util.ArrayList;
+
+import java.util.List;
+import org.jboss.weld.environment.se.ShutdownManager;
+import org.jboss.weld.environment.se.Weld;
+import org.jboss.weld.environment.se.WeldContainer;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Tests for ThreadContext, @ThreadScoped and the RunnableDecorator. The
+ * decorator is enabled in the META-INF/beans.xml of the test resources.
+ * @author Peter Royle
+ */
+public class ThreadContextTest
+{
+
+ static final int NUM_THREADS = 10;
+ static final int NUM_LOOPS = 10;
+
+ @Test
+ public void testThreadContext()
+ {
+ WeldContainer weld = new Weld().initialize();
+
+ List<ThreadRunner> threadRunners = new ArrayList<ThreadRunner>(NUM_THREADS);
+ List<Thread> threads = new ArrayList<Thread>(NUM_THREADS);
+ for (int threadIdx = 0; threadIdx < NUM_THREADS; threadIdx++)
+ {
+ final ThreadRunner threadRunner = weld.instance().select(ThreadRunner.class).get();
+ threadRunner.setName("ThreadRunner thread #" + threadIdx);
+
+ Thread thread = new Thread(threadRunner);
+ thread.start();
+ threads.add(thread);
+ threadRunners.add(threadRunner);
+ }
+
+ // wait for all threads to complete
+ assertEquals(NUM_THREADS, threads.size());
+ for (Thread thread : threads)
+ {
+ try
+ {
+ thread.join();
+ } catch (InterruptedException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ // bubble any exception from other threads to the surface
+ assertEquals(NUM_THREADS, threadRunners.size());
+ for (ThreadRunner threadRunner : threadRunners)
+ {
+ for (Exception e : threadRunner.getExceptions())
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ shutdownManager(weld);
+ }
+
+ private void shutdownManager(WeldContainer weld)
+ {
+ ShutdownManager shutdownManager = weld.instance().select(ShutdownManager.class).get();
+ shutdownManager.shutdown();
+ }
+
+
+}
Added: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/ThreadRunner.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,87 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.inject.Inject;
+import org.jboss.weld.environment.se.test.beans.threading.SingletonCounter;
+import org.jboss.weld.environment.se.test.beans.threading.ThreadCounter;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * An bean which implements Runnable and therefore can be run in a separate thread.
+ * All such beans, when passed to Thread.start(), will be decorated by the
+ * RunnableDecorator which will take care of making ThreadContext available to
+ * that thread for resolution of @ThreadScoped beans.
+ * @author Peter Royle
+ */
+public class ThreadRunner implements Runnable
+{
+
+ // an application scoped counter
+ @Inject private SingletonCounter appCounter;
+ // a thread scoped counter
+ @Inject private ThreadCounter threadCounter;
+ // a name for logging
+ private String name = "Unnamed";
+ // gather exceptions encountered for re-throwing in the test class
+ private List<Exception> exceptions = new ArrayList<Exception>();
+
+ /**
+ * Run a loop, incrementing both the thread-scoped and application scoped
+ * counters with each iteration.
+ */
+ public void run()
+ {
+ try
+ {
+
+ // Thread scoped counter should start at zero ...
+ assertEquals(0, threadCounter.getCount());
+
+ for (int loop = 1; loop <= ThreadContextTest.NUM_LOOPS; loop++)
+ {
+ final int appCount = appCounter.increment();
+ final int threadCount = threadCounter.increment();
+ System.out.println(name + " : " + appCount + ", " + threadCount);
+ assertEquals(loop, threadCount);
+ }
+ // ... and end at the number of loops
+ assertEquals(ThreadContextTest.NUM_LOOPS, threadCounter.getCount());
+ } catch (Exception e)
+ {
+ this.exceptions.add(e);
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public List<Exception> getExceptions()
+ {
+ return exceptions;
+ }
+}
Added: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/Counter.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/Counter.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/Counter.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,46 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test.beans.threading;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A simple, threadsafe counter which can be incremented and inspected.
+ * @author Peter Royle
+ */
+public abstract class Counter {
+
+ AtomicInteger count = new AtomicInteger(0);
+
+ public Counter() {
+ }
+
+ /**
+ * Get the current value of the counter.
+ */
+ public int getCount() {
+ return this.count.get();
+ }
+
+ /**
+ * Increment and return the new value of counter.
+ */
+ public int increment() {
+ return this.count.incrementAndGet();
+ }
+
+}
Added: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/SingletonCounter.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/SingletonCounter.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/SingletonCounter.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,28 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test.beans.threading;
+
+import javax.inject.Singleton;
+
+/**
+ * An application-scoped (singleton) counter.
+ * @author Peter Royle
+ */
+@Singleton
+public class SingletonCounter extends Counter {
+
+}
Added: java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadCounter.java
===================================================================
--- java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadCounter.java (rev 0)
+++ java-se/trunk/src/test/java/org/jboss/weld/environment/se/test/beans/threading/ThreadCounter.java 2009-12-10 13:31:14 UTC (rev 5267)
@@ -0,0 +1,28 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.environment.se.test.beans.threading;
+
+import org.jboss.weld.environment.se.contexts.ThreadScoped;
+
+/**
+ * A thread-scoped counter.
+ * @author Peter Royle
+ */
+@ThreadScoped
+public class ThreadCounter extends Counter {
+
+}
Modified: java-se/trunk/src/test/resources/META-INF/beans.xml
===================================================================
--- java-se/trunk/src/test/resources/META-INF/beans.xml 2009-12-10 12:25:20 UTC (rev 5266)
+++ java-se/trunk/src/test/resources/META-INF/beans.xml 2009-12-10 13:31:14 UTC (rev 5267)
@@ -17,11 +17,12 @@
-->
<beans>
- <interceptors>
- <class>org.jboss.weld.environment.se.test.interceptors.RecordingInterceptor</class>
- <class>org.jboss.weld.environment.se.test.interceptors.AggregatingInterceptor</class>
- </interceptors>
- <decorators>
- <class>org.jboss.weld.environment.se.test.decorators.CarDoorAlarm</class>
- </decorators>
+ <interceptors>
+ <class>org.jboss.weld.environment.se.test.interceptors.RecordingInterceptor</class>
+ <class>org.jboss.weld.environment.se.test.interceptors.AggregatingInterceptor</class>
+ </interceptors>
+ <decorators>
+ <class>org.jboss.weld.environment.se.test.decorators.CarDoorAlarm</class>
+ <class>org.jboss.weld.environment.se.threading.RunnableDecorator</class>
+ </decorators>
</beans>
14 years, 11 months
Weld SVN: r5266 - in core/trunk/tests/src/test: resources/org/jboss/weld/tests/unit/deployment/structure and 1 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-10 07:25:20 -0500 (Thu, 10 Dec 2009)
New Revision: 5266
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/Alt.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/beans.xml
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java
Log:
Tests for WELD-319, part II (isolation)
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/Alt.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/Alt.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/Alt.java 2009-12-10 12:25:20 UTC (rev 5266)
@@ -0,0 +1,9 @@
+package org.jboss.weld.tests.unit.deployment.structure.nonTransitiveResolution;
+
+import javax.enterprise.inject.Alternative;
+
+@Alternative
+public class Alt
+{
+
+}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java 2009-12-10 11:44:51 UTC (rev 5265)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java 2009-12-10 12:25:20 UTC (rev 5266)
@@ -5,27 +5,95 @@
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.mock.AbstractMockDeployment;
import org.jboss.weld.mock.MockBeanDeploymentArchive;
+import org.jboss.weld.mock.MockDeployment;
import org.jboss.weld.mock.MockServletLifecycle;
import org.jboss.weld.mock.TestContainer;
import org.testng.annotations.Test;
public class TransitiveResolutionTest
{
+
+ @Test(description = "WELD-319")
+ public void testBeansXmlIsolation()
+ {
+ MockBeanDeploymentArchive jar1 = new MockBeanDeploymentArchive("first-jar", Alt.class);
+ MockBeanDeploymentArchive jar2 = new MockBeanDeploymentArchive("second-jar", Alt.class);
+ jar1.getBeansXml().add(getClass().getResource("beans.xml"));
+ MockBeanDeploymentArchive war = new MockBeanDeploymentArchive("war");
+ war.getBeanDeploymentArchives().add(jar1);
+ war.getBeanDeploymentArchives().add(jar2);
+
+ Deployment deployment = new MockDeployment(war);
+
+ TestContainer container = null;
+ try
+ {
+ container = new TestContainer(new MockServletLifecycle(deployment, war)).startContainer().ensureRequestActive();
+ BeanManagerImpl warBeanManager = container.getBeanManager();
+ BeanManagerImpl jar1BeanManager = container.getLifecycle().getBootstrap().getManager(jar1);
+ BeanManagerImpl jar2BeanManager = container.getLifecycle().getBootstrap().getManager(jar2);
+ assert warBeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert !jar1BeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert jar2BeanManager.getEnabledAlternativeClasses().isEmpty();
+ }
+ finally
+ {
+ if (container != null)
+ {
+ container.stopContainer();
+ }
+ }
+ }
- @Test(description="WELD-236")
+ @Test(description = "WELD-319")
+ public void testBeansXmlMultipleEnabling()
+ {
+ MockBeanDeploymentArchive jar1 = new MockBeanDeploymentArchive("first-jar", Alt.class);
+ MockBeanDeploymentArchive jar2 = new MockBeanDeploymentArchive("second-jar", Alt.class);
+ jar1.getBeansXml().add(getClass().getResource("beans.xml"));
+ jar2.getBeansXml().add(getClass().getResource("beans.xml"));
+ MockBeanDeploymentArchive war = new MockBeanDeploymentArchive("war");
+ war.getBeanDeploymentArchives().add(jar1);
+ war.getBeanDeploymentArchives().add(jar2);
+
+ Deployment deployment = new MockDeployment(war);
+
+ TestContainer container = null;
+ try
+ {
+ container = new TestContainer(new MockServletLifecycle(deployment, war)).startContainer().ensureRequestActive();
+ BeanManagerImpl warBeanManager = container.getBeanManager();
+ BeanManagerImpl jar1BeanManager = container.getLifecycle().getBootstrap().getManager(jar1);
+ BeanManagerImpl jar2BeanManager = container.getLifecycle().getBootstrap().getManager(jar2);
+ assert warBeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert !jar1BeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert !jar2BeanManager.getEnabledAlternativeClasses().isEmpty();
+ }
+ finally
+ {
+ if (container != null)
+ {
+ container.stopContainer();
+ }
+ }
+ }
+
+ @Test(description = "WELD-236")
public void testTypicalEarStructure()
- {
-
- // Create the BDA in which we will deploy Foo. This is equivalent to a ejb jar
+ {
+
+ // Create the BDA in which we will deploy Foo. This is equivalent to a ejb
+ // jar
final MockBeanDeploymentArchive ejbJar = new MockBeanDeploymentArchive("ejb-jar", Foo.class);
-
+
// Create the BDA in which we will deploy Bar. This is equivalent to a war
MockBeanDeploymentArchive war = new MockBeanDeploymentArchive("war", Bar.class);
-
+
// The war can access the ejb jar
war.getBeanDeploymentArchives().add(ejbJar);
-
- // Create a deployment, any other classes are put into the ejb-jar (not relevant to test)
+
+ // Create a deployment, any other classes are put into the ejb-jar (not
+ // relevant to test)
Deployment deployment = new AbstractMockDeployment(war, ejbJar)
{
@@ -33,18 +101,17 @@
{
return ejbJar;
}
-
+
};
-
-
+
TestContainer container = new TestContainer(new MockServletLifecycle(deployment, war));
container.startContainer();
container.ensureRequestActive();
-
+
// Get the bean manager for war and ejb jar
BeanManagerImpl warBeanManager = container.getBeanManager();
BeanManagerImpl ejbJarBeanManager = container.getLifecycle().getBootstrap().getManager(ejbJar);
-
+
assert warBeanManager.getBeans(Bar.class).size() == 1;
assert warBeanManager.getBeans(Foo.class).size() == 1;
assert ejbJarBeanManager.getBeans(Foo.class).size() == 1;
@@ -55,5 +122,5 @@
assert bar.getBeanManager().equals(warBeanManager);
assert bar.getFoo().getBeanManager().equals(ejbJarBeanManager);
}
-
+
}
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/beans.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/beans.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/beans.xml 2009-12-10 12:25:20 UTC (rev 5266)
@@ -0,0 +1,5 @@
+<beans>
+ <alternatives>
+ <class>org.jboss.weld.tests.unit.deployment.structure.nonTransitiveResolution.Alt</class>
+ </alternatives>
+</beans>
\ No newline at end of file
14 years, 11 months
Weld SVN: r5265 - in core/trunk: impl/src/main/resources/org/jboss/weld/messages and 5 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-10 06:44:51 -0500 (Thu, 10 Dec 2009)
New Revision: 5265
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Alt.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Dec.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Int.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/IntBind.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Plain.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/alternative.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/decorator.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/interceptor.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleAlternativeBlocks.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleDecoratorBlocks.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleInterceptorsBlocks.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unloadable.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unparseable.xml
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
core/trunk/tests/src/test/java/org/jboss/weld/tests/enterprise/EnterpriseBeanTest.java
Log:
Part I of tests for WELD-319 (parsing part)
Delegate validation to Validator
Missing parser message
Typo in test JIRA reference
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -22,8 +22,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.weld.DeploymentException;
-import org.jboss.weld.logging.messages.XmlMessage;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.resources.spi.ResourceLoadingException;
import org.jboss.weld.util.dom.NodeListIterable;
@@ -40,34 +38,14 @@
{
private URL file;
private Element element;
- private List<String> classNames;
private BeansXmlElement(URL file, Element element)
{
super();
this.file = file;
this.element = element;
- classNames = new ArrayList<String>();
}
- public BeansXmlElement validateWithMessage(XmlMessage multipleViolationMessage)
- {
- for (Node child : new NodeListIterable(element.getChildNodes()))
- {
- String className = getClassNameFromNode(child);
- if (className == null)
- {
- continue;
- }
- if (classNames.contains(className))
- {
- throw new DeploymentException(multipleViolationMessage);
- }
- classNames.add(className);
- }
- return this;
- }
-
private String getClassNameFromNode(Node node)
{
if (node instanceof Element)
@@ -89,15 +67,20 @@
public List<Class<?>> getClasses(ResourceLoader resourceLoader)
{
List<Class<?>> classes = new ArrayList<Class<?>>();
- for (String className : classNames)
+ for (Node child : new NodeListIterable(element.getChildNodes()))
{
+ String className = getClassNameFromNode(child);
+ if (className == null)
+ {
+ continue;
+ }
try
{
classes.add(resourceLoader.classForName(className));
}
catch (ResourceLoadingException e)
{
- throw new DeploymentException(CANNOT_LOAD_CLASS, className, file);
+ throw new WeldXmlException(CANNOT_LOAD_CLASS, className, file);
}
}
return classes;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -30,7 +30,6 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.jboss.weld.DeploymentException;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -102,11 +101,11 @@
}
catch (SAXException e)
{
- throw new DeploymentException(PARSING_ERROR, e, beansXml.toString());
+ throw new WeldXmlException(PARSING_ERROR, e, beansXml.toString());
}
catch (IOException e)
{
- throw new DeploymentException(LOAD_ERROR, e, beansXml.toString());
+ throw new WeldXmlException(LOAD_ERROR, e, beansXml.toString());
}
finally
{
@@ -133,6 +132,10 @@
private boolean isBeansXmlOK(URL beansXml)
{
+ if (beansXml == null)
+ {
+ throw new WeldXmlException(LOAD_ERROR, "null-URL");
+ }
InputStream in = null;
try
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -19,7 +19,6 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
import org.jboss.weld.resources.spi.ResourceLoader;
@@ -73,7 +72,7 @@
private Collection<Class<?>> getClassesInElements(List<BeansXmlElement> elements)
{
- LinkedHashSet<Class<?>> classes = new LinkedHashSet<Class<?>>();
+ List<Class<?>> classes = new ArrayList<Class<?>>();
for (BeansXmlElement element : elements)
{
classes.addAll(element.getClasses(resourceLoader));
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.weld.DeploymentException;
import org.jboss.weld.logging.messages.XmlMessage;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -50,19 +49,17 @@
decoratorsElements.addAll(getNamedElement(url, documentElement, "decorators", MULTIPLE_DECORATORS));
}
- // TODO: look over exception message when multiple blocks or multiple
- // classes. Now they're the same.
private List<BeansXmlElement> getNamedElement(URL url, Element beans, String name, XmlMessage multipleViolationMessage)
{
List<BeansXmlElement> elements = new ArrayList<BeansXmlElement>();
NodeList nodeList = beans.getElementsByTagName(name);
if (nodeList.getLength() > 1)
{
- throw new DeploymentException(multipleViolationMessage);
+ throw new WeldXmlException(multipleViolationMessage);
}
else if (nodeList.getLength() == 1)
{
- BeansXmlElement element = BeansXmlElement.of(url, nodeList.item(0)).validateWithMessage(multipleViolationMessage);
+ BeansXmlElement element = BeansXmlElement.of(url, nodeList.item(0));
elements.add(element);
}
return elements;
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/xml_en.properties 2009-12-10 11:44:51 UTC (rev 5265)
@@ -1,6 +1,7 @@
CONFIGURATION_ERROR=Error configuring XML parser
-LOAD_ERROR=Error loading {0}
+LOAD_ERROR=Error loading beans.xml {0}
+CANNOT_LOAD_CLASS=Could not load class {0}
PARSING_ERROR=Error parsing {0}
MULTIPLE_ALTERNATIVES=<alternatives> can only be specified once, but appears multiple times\: {0}
-MULTIPLE_DECORATORS=<decorator> can only be specified once, but is specified multiple times\: {0}
+MULTIPLE_DECORATORS=<decorators> can only be specified once, but is specified multiple times\: {0}
MULTIPLE_INTERCEPTORS=<interceptor> can only be specified once, but it is specified multiple times\: {0}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/enterprise/EnterpriseBeanTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/enterprise/EnterpriseBeanTest.java 2009-12-10 09:25:26 UTC (rev 5264)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/enterprise/EnterpriseBeanTest.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -21,7 +21,7 @@
}
- @Test(description="WBRI-326")
+ @Test(description="WELD-326")
public void testInvocationExceptionIsUnwrapped()
{
try
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Alt.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Alt.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Alt.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,9 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+import javax.enterprise.inject.Alternative;
+
+@Alternative
+public class Alt
+{
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,169 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.weld.logging.messages.XmlMessage;
+import org.jboss.weld.mock.MockEELifecycle;
+import org.jboss.weld.mock.TestContainer;
+import org.jboss.weld.xml.WeldXmlException;
+import org.testng.annotations.Test;
+
+@SuppressWarnings("unchecked")
+public class BeansXmlTest
+{
+ private class FailedDeployment
+ {
+ private List<Class<?>> beans = Collections.emptyList();
+ private List<URL> beansXml = Collections.emptyList();
+
+ public FailedDeployment(List<Class<?>> beans, List<URL> beansXml)
+ {
+ this.beans = beans;
+ this.beansXml = beansXml;
+ }
+
+ public void run()
+ {
+ TestContainer container = null;
+ try
+ {
+ container = new TestContainer(new MockEELifecycle(), beans, beansXml).startContainer().ensureRequestActive();
+ }
+ finally
+ {
+ if (container != null)
+ {
+ container.stopContainer();
+ }
+ }
+ }
+
+ public void runAndExpect(WeldXmlException expected)
+ {
+ String errorCode = expected.getMessage().substring(0, 12);
+ try
+ {
+ run();
+ }
+ catch (WeldXmlException e)
+ {
+ if (e.getMessage().startsWith(errorCode))
+ {
+ return;
+ }
+ }
+ assert false;
+ }
+
+ }
+
+ private void testWithBeansXmlAndExpectException(String beansXml, WeldXmlException e)
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, Plain.class, IntBind.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource(beansXml));
+ new FailedDeployment(beans, beansXmls).runAndExpect(e);
+ }
+
+ // Multiple XML blocks
+
+ @Test
+ public void multipleAlternativeBlocksFail()
+ {
+ testWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES));
+ }
+
+ @Test
+ public void multipleDecoratorBlocksFail()
+ {
+ testWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS));
+ }
+
+ @Test
+ public void multipleInterceptorBlocksFail()
+ {
+ testWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS));
+ }
+
+ @Test
+ public void alternativesEnabled()
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ container.stopContainer();
+ }
+
+ @Test
+ public void decoratorsEnabled()
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("decorator.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1;
+ assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class;
+ container.stopContainer();
+ }
+
+ @Test
+ public void interceptorsEnabled()
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("interceptor.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1;
+ assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class;
+ container.stopContainer();
+ }
+
+ @Test
+ public void testMergeBeansXmls()
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"), getClass().getResource("decorator.xml"), getClass().getResource("interceptor.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1;
+ assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class;
+ assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1;
+ assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class;
+ container.stopContainer();
+ }
+
+ @Test
+ public void testBeansXmlDoesntExist()
+ {
+ testWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR));
+ }
+
+ @Test(groups="stub")
+ public void testCannotGetDocumentBuilder()
+ {
+ }
+
+ @Test
+ public void testCannotLoadFile() throws MalformedURLException
+ {
+ List<Class<?>> beans = Collections.emptyList();
+ new FailedDeployment(beans, Arrays.asList(new URL("http://foo.bar/beans.xml"))).runAndExpect(new WeldXmlException(XmlMessage.LOAD_ERROR));
+ }
+
+ @Test
+ public void testParsingError()
+ {
+ testWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR));
+ }
+
+ @Test
+ public void testCannotLoadClass()
+ {
+ testWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS));
+ }
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Dec.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Dec.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Dec.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,11 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+
+@Decorator
+public class Dec
+{
+ @Inject @Delegate Plain plain;
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Int.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Int.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Int.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,10 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+import javax.interceptor.Interceptor;
+
+@Interceptor
+@IntBind
+public class Int
+{
+
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/IntBind.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/IntBind.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/IntBind.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Inherited
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface IntBind
+{
+}
\ No newline at end of file
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Plain.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Plain.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Plain.java 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,6 @@
+package org.jboss.weld.tests.unit.bootstrap.xml;
+
+public class Plain
+{
+
+}
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/alternative.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/alternative.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/alternative.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,5 @@
+<beans>
+ <alternatives>
+ <class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</class>
+ </alternatives>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/decorator.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/decorator.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/decorator.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,5 @@
+<beans>
+ <decorators>
+ <class>org.jboss.weld.tests.unit.bootstrap.xml.Dec</class>
+ </decorators>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/interceptor.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/interceptor.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/interceptor.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,5 @@
+<beans>
+ <interceptors>
+ <class>org.jboss.weld.tests.unit.bootstrap.xml.Int</class>
+ </interceptors>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleAlternativeBlocks.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleAlternativeBlocks.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleAlternativeBlocks.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,8 @@
+<beans>
+ <alternatives>
+ <class>org.jboss.weld.tests.unit.bootstrap.Foo</class>
+ </alternatives>
+ <alternatives>
+ <class>org.jboss.weld.tests.unit.bootstrap.Bar</class>
+ </alternatives>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleDecoratorBlocks.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleDecoratorBlocks.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleDecoratorBlocks.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,8 @@
+<beans>
+ <decorators>
+ <class>org.jboss.weld.tests.unit.bootstrap.Foo</class>
+ </decorators>
+ <decorators>
+ <class>org.jboss.weld.tests.unit.bootstrap.Bar</class>
+ </decorators>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleInterceptorsBlocks.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleInterceptorsBlocks.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/multipleInterceptorsBlocks.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,8 @@
+<beans>
+ <interceptors>
+ <class>org.jboss.weld.tests.unit.bootstrap.Foo</class>
+ </interceptors>
+ <interceptors>
+ <class>org.jboss.weld.tests.unit.bootstrap.Bar</class>
+ </interceptors>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unloadable.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unloadable.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unloadable.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,5 @@
+<beans>
+ <alternatives>
+ <class>foo.Bar</class>
+ </alternatives>
+</beans>
\ No newline at end of file
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unparseable.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unparseable.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/unparseable.xml 2009-12-10 11:44:51 UTC (rev 5265)
@@ -0,0 +1,5 @@
+<beans>
+ <alternatives
+ <class>foo.Bar</class>
+ </alternatives>
+</beans>
\ No newline at end of file
14 years, 11 months