MentaContainer

Compare Revisions

Ignore whitespace Rev 102 → Rev 103

/trunk/src/test/java/org/mentacontainer/impl/MentaContainerTest.java
326,7 → 326,7
SomeAction a = new SomeAction();
c.populate(a); // great... properties of SomeAction were populated by container...
c.inject(a); // great... properties of SomeAction were populated by container...
// let's check if myDAO was injected...
343,6 → 343,61
Assert.assertNotNull(conn.getMyDep());
}
public static class SomeAction2 {
private final MyDAO myDAO;
public SomeAction2(MyDAO myDAO) {
this.myDAO = myDAO;
}
public MyDAO getMyDAO() { return myDAO; }
}
@Test
public void testConstructorDependency() {
Container c = new MentaContainer();
c.ioc("myDAO", JdbcMyDAO.class);
c.ioc("aDependency", SomeDependency.class, Scope.SINGLETON).addPropertyValue("name", "A super dependency!");
c.ioc("connection", Connection.class).addInitValue("A super JDBC connection!");
c.autowire("connection");
c.autowire("aDependency", "myDep");
c.ioc("someAction2", SomeAction2.class).addInitDependency("myDAO");
SomeAction2 action = c.get("someAction2");
Assert.assertNotNull(action.getMyDAO());
}
@Test
public void testConstruct() {
Container c = getConfiguredContainer();
SomeAction2 a = c.construct(SomeAction2.class);
// let's check if myDAO was injected...
Assert.assertNotNull(a.getMyDAO());
// also check if myDAO was corrected wired...
Connection conn = ((JdbcMyDAO) a.getMyDAO()).getConnection();
Assert.assertNotNull(conn);
// check if conn was also wired...
Assert.assertNotNull(conn.getMyDep());
}
private static class SomeObject {
private boolean cleared = false;