Skip to content

Commit

Permalink
Refactor to remove *Model and *Constructor and xmlAnnotatedItem, part 3
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@286 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Nov 9, 2008
1 parent 1df06cf commit f93199d
Show file tree
Hide file tree
Showing 22 changed files with 375 additions and 381 deletions.
@@ -1,24 +1,20 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.createSimpleBean;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.webbeans.AnnotationLiteral;
import javax.webbeans.Current;

import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
import org.jboss.webbeans.model.bean.BeanModel;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.annotations.Asynchronous;
import org.jboss.webbeans.test.annotations.Synchronous;
import org.jboss.webbeans.test.beans.Antelope;
Expand All @@ -43,7 +39,7 @@ public class BindingTypeTest extends AbstractTest
@Test @SpecAssertion(section={"2.3.3", "2.3.1"})
public void testDefaultBindingTypeDeclaredInJava()
{
SimpleBeanModel<Order> order = createSimpleModel(Order.class, manager);
SimpleBean<Order> order = createSimpleBean(Order.class, manager);
assert order.getBindingTypes().size() == 1;
order.getBindingTypes().iterator().next().annotationType().equals(Current.class);
}
Expand All @@ -70,15 +66,15 @@ public void testBindingTypeDeclaresBindingTypeAnnotation()
@Test @SpecAssertion(section="2.3.3")
public void testBindingTypesDeclaredInJava()
{
SimpleBeanModel<Cat> cat = createSimpleModel(Cat.class, manager);
SimpleBean<Cat> cat = createSimpleBean(Cat.class, manager);
assert cat.getBindingTypes().size() == 1;
assert Reflections.annotationSetMatches(cat.getBindingTypes(), Synchronous.class);
}

@Test @SpecAssertion(section="2.3.3")
public void testMultipleBindingTypes()
{
BeanModel<?, ?> model = createSimpleModel(Cod.class, manager);
SimpleBean<?> model = createSimpleBean(Cod.class, manager);
assert model.getBindingTypes().size() == 2;
}

Expand All @@ -90,51 +86,55 @@ public void testBindingTypesDeclaredInXml()
annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
AnnotatedClass annotatedItem = new SimpleAnnotatedClass(Antelope.class, annotations);

SimpleBeanModel<Antelope> antelope = new SimpleBeanModel<Antelope>(null, annotatedItem, manager);
assert Reflections.annotationSetMatches(antelope.getBindingTypes(), Asynchronous.class);
//SimpleBean<Antelope> antelope = createSimpleBean(Antelope.class, annotatedItem, manager);
// assert Reflections.annotationSetMatches(antelope.getBindingTypes(), Asynchronous.class);
assert false;
}

@Test @SpecAssertion(section="2.3.4")
@Test(groups="webbeansxml") @SpecAssertion(section="2.3.4")
public void testXmlBindingTypeOverridesAndIgnoresJava()
{
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
AnnotatedClass<Cat> annotatedItem = new SimpleAnnotatedClass<Cat>(Cat.class, annotations);

SimpleBeanModel<Cat> cat = createSimpleModel(Cat.class, annotatedItem, manager);
assert cat.getBindingTypes().size() == 1;
assert cat.getBindingTypes().contains(new AnnotationLiteral<Asynchronous>() {});
//SimpleBean<Cat> cat = createSimpleBean(Cat.class, annotatedItem, manager);
//assert cat.getBindingTypes().size() == 1;
//assert cat.getBindingTypes().contains(new AnnotationLiteral<Asynchronous>() {});
assert false;
}

@Test @SpecAssertion(section="2.3.4")
@Test(groups="webbeansxml") @SpecAssertion(section="2.3.4")
public void testNoBindingTypesDeclaredInXml()
{
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
AnnotatedClass<Cat> annotatedItem = new SimpleAnnotatedClass<Cat>(Cat.class, annotations);

SimpleBeanModel<Cat> cat = createSimpleModel(Cat.class, annotatedItem, manager);
assert cat.getBindingTypes().size() == 1;
assert cat.getBindingTypes().contains(new AnnotationLiteral<Synchronous>() {});
//SimpleBean<Cat> cat = createSimpleBean(Cat.class, annotatedItem, manager);
//assert cat.getBindingTypes().size() == 1;
//assert cat.getBindingTypes().contains(new AnnotationLiteral<Synchronous>() {});
assert false;
}

@Test @SpecAssertion(section={"2.3.4", "2.3.1"})
@Test(groups="webbeansxml") @SpecAssertion(section={"2.3.4", "2.3.1"})
public void testDefaultBindingTypeDeclaredInXml()
{
BeanModel<?, ?> model = createSimpleModel(Tuna.class, manager);
SimpleBean<?> model = createSimpleBean(Tuna.class, manager);
assert model.getBindingTypes().size() == 1;
assert model.getBindingTypes().contains(new CurrentAnnotationLiteral());
assert false;
}



@Test(groups={"injection", "producerMethod"}) @SpecAssertion(section="2.3.5")
public void testFieldInjectedFromProducerMethod() throws Exception
{
SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
SimpleBean<SpiderProducer> spiderProducer = createSimpleBean(SpiderProducer.class, manager);
manager.addBean(spiderProducer);
Method method = SpiderProducer.class.getMethod("produceTameTarantula");
manager.addBean(createProducerMethodBean(Tarantula.class, method, manager, spiderProducer));
Barn barn = createSimpleWebBean(Barn.class, manager).create();
Barn barn = createSimpleBean(Barn.class, manager).create();
assert barn.petSpider != null;
assert barn.petSpider instanceof DefangedTarantula;
}
Expand All @@ -154,7 +154,7 @@ public void testFieldWithBindingTypeInXmlIgnoresAnnotations()
@Test(groups={"injection", "producerMethod"})
public void testMethodWithBindingAnnotationsOnParametersAreInjected() throws Exception
{
SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
SimpleBean<SpiderProducer> spiderProducer = createSimpleBean(SpiderProducer.class, manager);
manager.addBean(spiderProducer);
Method method = SpiderProducer.class.getMethod("produceTameTarantula");
manager.addBean(createProducerMethodBean(Tarantula.class, method, manager, spiderProducer));
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class ClientProxyTest extends AbstractTest
@SpecAssertion(section = { "4.4", "4.8" })
public void testClientProxyUsedForNormalScope()
{
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
Bean<Tuna> tunaBean = Util.createSimpleBean(Tuna.class, manager);
Tuna tuna = manager.getInstance(tunaBean);
assert ClientProxy.isProxy(tuna);
}
Expand All @@ -34,7 +34,7 @@ public void testClientProxyUsedForNormalScope()
@SpecAssertion(section = { "4.4", "4.8" })
public void testClientProxyNotUsedForPseudoScope()
{
Bean<Fox> foxBean = Util.createSimpleWebBean(Fox.class, manager);
Bean<Fox> foxBean = Util.createSimpleBean(Fox.class, manager);
Fox fox = manager.getInstance(foxBean);
assert !ClientProxy.isProxy(fox);
}
Expand All @@ -55,7 +55,7 @@ private Object deserializeBean(byte[] bytes) throws IOException, ClassNotFoundEx
@SpecAssertion(section = "4.4")
public void testSimpleWebBeanClientProxyIsSerializable() throws IOException, ClassNotFoundException
{
Bean<TunedTuna> tunaBean = Util.createSimpleWebBean(TunedTuna.class, manager);
Bean<TunedTuna> tunaBean = Util.createSimpleBean(TunedTuna.class, manager);
TunedTuna tuna = manager.getInstance(tunaBean);
assert ClientProxy.isProxy(tuna);
byte[] bytes = serializeBean(tuna);
Expand All @@ -68,7 +68,7 @@ public void testSimpleWebBeanClientProxyIsSerializable() throws IOException, Cla
@SpecAssertion(section = "4.4.1")
public void testInjectionPointWithUnproxyableTypeWhichResolvesToNormalScopedWebBean()
{
Bean<FinalTuna> tunaBean = Util.createSimpleWebBean(FinalTuna.class, manager);
Bean<FinalTuna> tunaBean = Util.createSimpleBean(FinalTuna.class, manager);
manager.addBean(tunaBean);
FinalTuna tuna = manager.getInstanceByType(FinalTuna.class);
assert false;
Expand All @@ -78,7 +78,7 @@ public void testInjectionPointWithUnproxyableTypeWhichResolvesToNormalScopedWebB
@SpecAssertion(section = "4.4.2")
public void testClientProxyInvocation()
{
Bean<TunedTuna> tunaBean = Util.createSimpleWebBean(TunedTuna.class, manager);
Bean<TunedTuna> tunaBean = Util.createSimpleBean(TunedTuna.class, manager);
manager.addBean(tunaBean);
TunedTuna tuna = manager.getInstance(tunaBean);
assert ClientProxy.isProxy(tuna);
Expand All @@ -87,7 +87,7 @@ public void testClientProxyInvocation()

@Test(groups = "clientProxy")
public void testProxyCreationDoesImplicitAddBean() {
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
Bean<Tuna> tunaBean = Util.createSimpleBean(Tuna.class, manager);
Tuna tuna = manager.getInstance(tunaBean);
assert manager.getBeans().size() == 2;
}
Expand Down
@@ -1,8 +1,7 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
import static org.jboss.webbeans.test.util.Util.createSimpleModel;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.createSimpleBean;

import java.lang.reflect.Method;

Expand All @@ -11,7 +10,6 @@
import javax.webbeans.manager.Bean;

import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.model.bean.BeanModel;
import org.jboss.webbeans.test.beans.RedSnapper;
import org.jboss.webbeans.test.beans.Spider;
import org.jboss.webbeans.test.beans.SpiderProducer;
Expand All @@ -31,41 +29,41 @@ public class CommonWebBeanTest extends AbstractTest
@Test @SpecAssertion(section="2")
public void testApiTypesNonEmpty()
{
BeanModel<?, ?> model = createSimpleModel(RedSnapper.class, manager);
assert model.getApiTypes().size() > 0;
Bean<?> model = createSimpleBean(RedSnapper.class, manager);
assert model.getTypes().size() > 0;
}

@Test @SpecAssertion(section="2")
public void testBindingTypesNonEmpty()
{
BeanModel<?, ?> model = createSimpleModel(RedSnapper.class, manager);
Bean<?> model = createSimpleBean(RedSnapper.class, manager);
assert model.getBindingTypes().size() > 0;
}

@Test @SpecAssertion(section="2")
public void testHasScopeType()
{
BeanModel<?, ?> model = createSimpleModel(RedSnapper.class, manager);
Bean<?> model = createSimpleBean(RedSnapper.class, manager);
assert model.getScopeType().equals(RequestScoped.class);
}

@Test @SpecAssertion(section="2")
public void testHasDeploymentType()
{
BeanModel<?, ?> model = createSimpleModel(RedSnapper.class, manager);
Bean<?> model = createSimpleBean(RedSnapper.class, manager);
assert model.getDeploymentType().equals(Production.class);
}

@Test(groups="producerMethod") @SpecAssertion(section="4.2")
public void testIsNullable() throws Exception
{
SimpleBean<SpiderProducer> spiderProducerBean = createSimpleWebBean(SpiderProducer.class, manager);
SimpleBean<SpiderProducer> spiderProducerBean = createSimpleBean(SpiderProducer.class, manager);
manager.addBean(spiderProducerBean);
Method method = SpiderProducer.class.getMethod("getWolfSpiderSize");
Bean<Integer> bean = createProducerMethodBean(int.class, method, manager);
Bean<Integer> bean = createProducerMethodBean(int.class, method, manager, spiderProducerBean);
assert !bean.isNullable();
method = SpiderProducer.class.getMethod("makeASpider");
Bean<Spider> spiderBean = createProducerMethodBean(Spider.class, method, manager);
Bean<Spider> spiderBean = createProducerMethodBean(Spider.class, method, manager, spiderProducerBean);
assert spiderBean.isNullable();
}

Expand Down
@@ -1,25 +1,24 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createSimpleBean;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.webbeans.Observer;
import javax.webbeans.Observes;
import javax.webbeans.Standard;

import org.jboss.webbeans.event.DeferredEventNotification;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.impl.InjectableMethod;
import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.Asynchronous;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.bindings.AsynchronousAnnotationLiteral;
import org.jboss.webbeans.test.mock.MockObserverImpl;
import org.testng.annotations.Test;

/**
Expand Down Expand Up @@ -68,23 +67,23 @@ public final void testBeforeCompletion() throws Exception
// When the transaction is committed, the beforeCompletion() method is
// invoked which in turn invokes the observer. Here the mock observer
// is used to keep track of the event being fired.
SimpleBeanModel<Tuna> tuna;
SimpleBean<Tuna> tuna;
InjectableMethod<Object> om;


// Create an observer with known binding types
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
AnnotatedClass<Tuna> annotatedItem = new SimpleAnnotatedClass<Tuna>(Tuna.class, annotations);
tuna = new SimpleBeanModel<Tuna>(new SimpleAnnotatedClass<Tuna>(Tuna.class), annotatedItem, manager);
tuna = createSimpleBean(Tuna.class, manager);
om = new InjectableMethod<Object>(AnObserver.class.getMethod("observe", new Class[] { Event.class }));

AnObserver observerInstance = new AnObserver();
Observer<Event> observer = new MockObserverImpl<Event>(tuna, om, Event.class);
((MockObserverImpl<Event>) observer).setInstance(observerInstance);
// TODO Fix this Observer<Event> observer = new MockObserverImpl<Event>(tuna, om, Event.class);
//((MockObserverImpl<Event>) observer).setInstance(observerInstance);
Event event = new Event();
DeferredEventNotification<Event> deferredNotification = new DeferredEventNotification<Event>(event, observer);
deferredNotification.beforeCompletion();
//DeferredEventNotification<Event> deferredNotification = new DeferredEventNotification<Event>(event, observer);
//deferredNotification.beforeCompletion();
assert observerInstance.notified;
}

Expand Down
@@ -1,7 +1,7 @@
package org.jboss.webbeans.test;

import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.createSimpleBean;

import java.lang.reflect.Method;

Expand All @@ -25,8 +25,8 @@ public class DependentContextTest extends AbstractTest
@Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
public void testInstanceNotSharedBetweenInjectionPoints()
{
Bean<FoxRun> foxRunBean = createSimpleWebBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
Bean<FoxRun> foxRunBean = createSimpleBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleBean(Fox.class, manager);
manager.addBean(foxBean);
FoxRun foxRun = foxRunBean.create();
assert !foxRun.fox.equals(foxRun.anotherFox);
Expand All @@ -41,7 +41,7 @@ public void testInstanceUsedForElEvalutionNotShared()
@Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
public void testInstanceUsedForProducerMethodNotShared() throws Exception
{
SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
SimpleBean<SpiderProducer> spiderProducer = createSimpleBean(SpiderProducer.class, manager);
manager.addBean(spiderProducer);
Method method = SpiderProducer.class.getMethod("produceTarantula");
ProducerMethodBean<Tarantula> tarantulaBean = createProducerMethodBean(Tarantula.class, method, manager, spiderProducer);
Expand All @@ -61,7 +61,7 @@ public void testInstanceUsedForObserverMethodNotShared()
@Test(groups="contexts") @SpecAssertion(section="8.3")
public void testContextGetWithCreateTrueReturnsNewInstance()
{
Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
Bean<Fox> foxBean = createSimpleBean(Fox.class, manager);
manager.addBean(foxBean);
DependentContext context = new DependentContext();
context.setActive(true);
Expand All @@ -72,7 +72,7 @@ public void testContextGetWithCreateTrueReturnsNewInstance()
@Test(groups="contexts") @SpecAssertion(section="8.3")
public void testContextGetWithCreateFalseReturnsNull()
{
Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
Bean<Fox> foxBean = createSimpleBean(Fox.class, manager);
manager.addBean(foxBean);
DependentContext context = new DependentContext();
context.setActive(true);
Expand Down Expand Up @@ -102,8 +102,8 @@ public void testContextIsActiveWhenEvaluatingElExpression()
public void testContextIsActiveDuringBeanCreation()
{
// Slightly roundabout, but I can't see a better way to test atm
Bean<FoxRun> foxRunBean = createSimpleWebBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
Bean<FoxRun> foxRunBean = createSimpleBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleBean(Fox.class, manager);
manager.addBean(foxBean);
FoxRun foxRun = foxRunBean.create();
assert foxRun.fox != null;
Expand All @@ -118,8 +118,8 @@ public void testContextIsActiveDuringBeanDestruction()
@Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
public void testContextIsActiveDuringInjection()
{
Bean<FoxRun> foxRunBean = createSimpleWebBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
Bean<FoxRun> foxRunBean = createSimpleBean(FoxRun.class, manager);
Bean<Fox> foxBean = createSimpleBean(Fox.class, manager);
manager.addBean(foxBean);
FoxRun foxRun = foxRunBean.create();
assert foxRun.fox != null;
Expand Down

0 comments on commit f93199d

Please sign in to comment.