Skip to content

Commit

Permalink
Ciruclar dependency tests
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1253 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 27, 2009
1 parent d2b820f commit cae6ed1
Show file tree
Hide file tree
Showing 23 changed files with 559 additions and 0 deletions.
@@ -0,0 +1,14 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.context.ApplicationScoped;
import javax.inject.Initializer;

@ApplicationScoped
class Air
{
@Initializer
public Air(Fish fish)
{
}

}
@@ -0,0 +1,34 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.annotation.PostConstruct;
import javax.context.ApplicationScoped;
import javax.inject.Current;

@ApplicationScoped
class Bar
{

public static boolean success;

@Current Foo foo;

public Bar()
{
success = false;
}

@PostConstruct
public void postConstruct()
{
if (foo.getName().equals("foo"))
{
success = true;
}
}

public String getName()
{
return "bar";
}

}
@@ -0,0 +1,18 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.context.ApplicationScoped;
import javax.inject.Initializer;

@ApplicationScoped
class Bird
{

private Water water;

@Initializer
public Bird(Water water)
{
this.water = water;
}

}
@@ -0,0 +1,32 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.annotation.PostConstruct;
import javax.inject.Current;

class Car
{

public static boolean success;

@Current Petrol petrol;

public Car()
{
success = false;
}

@PostConstruct
public void postConstruct()
{
if (petrol.getName().equals("petrol"))
{
success = true;
}
}

public String getName()
{
return "herbie";
}

}
@@ -0,0 +1,223 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import org.jboss.webbeans.test.unit.AbstractTest;
import org.testng.annotations.Test;

public class CircularDependencyTest extends AbstractTest
{


@Test(groups="broken")
public void testCircularInjectionOnTwoNormalBeans() throws Exception
{
deployBeans(Pig.class, Food.class);
manager.getInstanceByType(Pig.class).getName();
assert Pig.success;
assert Food.success;
}

@Test(groups="broken")
public void testCircularInjectionOnOneNormalAndOneDependentBean() throws Exception
{
deployBeans(Car.class, Petrol.class);
manager.getInstanceByType(Petrol.class).getName();
assert Petrol.success;
assert Car.success;
}


@Test(groups="broken")
public void testCircularInjectionOnTwoSimpleDependentBeans() throws Exception
{
deployBeans(Foo.class, Bar.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Foo.class).getName();
assert Foo.success;
assert Bar.success;
}

}.run();
}

@Test(groups="broken")
public void testDependentProducerMethodDeclaredOnDependentBeanWhichInjectsProducedBean() throws Exception
{
deployBeans(DependentSelfConsumingDependentProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(DependentSelfConsumingDependentProducer.class).ping();
}

}.run();
}

@Test
public void testNormalProducerMethodDeclaredOnNormalBeanWhichInjectsProducedBean() throws Exception
{
deployBeans(NormalSelfConsumingNormalProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(NormalSelfConsumingNormalProducer.class).ping();
}

}.run();
}

@Test
public void testNormalProducerMethodDeclaredOnDependentBeanWhichInjectsProducedBean() throws Exception
{
deployBeans(DependentSelfConsumingNormalProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(DependentSelfConsumingNormalProducer.class).ping();
}

}.run();
}

@Test
public void testDependentProducerMethodDeclaredOnNormalBeanWhichInjectsProducedBean() throws Exception
{
deployBeans(NormalSelfConsumingDependentProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(NormalSelfConsumingDependentProducer.class).ping();
}

}.run();
}

@Test
public void testNormalSelfConsumingProducer() throws Exception
{
deployBeans(NormalLoopingProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Violation.class).ping();
}

}.run();
}

@Test(groups="broken")
public void testDependentSelfConsumingProducer() throws Exception
{
deployBeans(DependentLoopingProducer.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Violation.class).ping();
}

}.run();
}

@Test(groups="broken")
public void testDependentCircularConstructors() throws Exception
{
deployBeans(Water.class, Fish.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Fish.class);
}

}.run();
}

@Test(groups="broken")
public void testNormalCircularConstructors() throws Exception
{
deployBeans(Bird.class, Air.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Bird.class);
}

}.run();
}

@Test(groups="broken")
public void testNormalAndDependentCircularConstructors() throws Exception
{
deployBeans(Space.class, Planet.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Planet.class);
}

}.run();
}

@Test(groups="broken")
public void testSelfConsumingConstructorsOnDependentBean() throws Exception
{
deployBeans(Farm.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(Farm.class);
}

}.run();
}

@Test(groups="broken")
public void testSelfConsumingConstructorsOnNormalBean() throws Exception
{
deployBeans(House.class);
new RunInDependentContext()
{

@Override
protected void execute() throws Exception
{
manager.getInstanceByType(House.class);
}

}.run();
}

}
@@ -0,0 +1 @@
package org.jboss.webbeans.test.unit.lookup.circular;import javax.inject.Produces;class DependentLoopingProducer{ @Produces public Violation produceViolation(Violation violation) { return new Violation(); }}
Expand Down
@@ -0,0 +1 @@
package org.jboss.webbeans.test.unit.lookup.circular;import javax.inject.Current;import javax.inject.Produces;class DependentSelfConsumingDependentProducer{ @Current Violation violation; @Produces public Violation produceViolation() { return new Violation(); } public void ping() { }}
Expand Down
@@ -0,0 +1 @@
package org.jboss.webbeans.test.unit.lookup.circular;import javax.context.ApplicationScoped;import javax.inject.Current;import javax.inject.Produces;@ApplicationScopedclass DependentSelfConsumingNormalProducer{ @Current Violation violation; @Produces @ApplicationScoped public Violation produceViolation() { return new Violation(); } public void ping() { }}
Expand Down
@@ -0,0 +1,13 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.inject.Initializer;

class Farm
{

@Initializer
public Farm(Farm farm)
{
}

}
@@ -0,0 +1,16 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.inject.Initializer;

class Fish
{

private Water water;

@Initializer
public Fish(Water water)
{
this.water = water;
}

}
@@ -0,0 +1,32 @@
package org.jboss.webbeans.test.unit.lookup.circular;

import javax.annotation.PostConstruct;
import javax.inject.Current;

class Foo
{

public static boolean success;

@Current Bar bar;

public Foo()
{
success = false;
}

@PostConstruct
public void postConstruct()
{
if (bar.getName().equals("bar"))
{
success = true;
}
}

public String getName()
{
return "foo";
}

}

0 comments on commit cae6ed1

Please sign in to comment.