Search in sources :

Example 1 with Foo

use of jodd.petite.tst.Foo in project jodd by oblac.

the class MiscTest method testAdd.

@Test
public void testAdd() {
    PetiteContainer pc = new PetiteContainer();
    Foo foo = new Foo();
    pc.addBean("foo", foo);
    Foo foo2 = (Foo) pc.getBean("foo");
    assertNotNull(foo2);
    assertSame(foo, foo2);
}
Also used : Foo(jodd.petite.tst.Foo) Test(org.junit.Test)

Example 2 with Foo

use of jodd.petite.tst.Foo in project jodd by oblac.

the class ParamTest method testProperties.

@Test
public void testProperties() {
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Foo.class, null, null, null, false);
    Properties p = new Properties();
    p.setProperty("foo.name", "${name}");
    p.setProperty("name", "${name2}");
    p.setProperty("name2", "FOONAME");
    pc.defineParameters(p);
    Foo foo = (Foo) pc.getBean("foo");
    assertNotNull(foo);
    assertEquals("FOONAME", foo.getName());
}
Also used : Foo(jodd.petite.tst.Foo) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with Foo

use of jodd.petite.tst.Foo in project jodd by oblac.

the class ParamTest method testRefParams.

@Test
public void testRefParams() {
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Foo.class, null, null, null, false);
    pc.defineParameter("foo.name", "$${name}");
    pc.defineParameter("name", "${name${num}}");
    pc.defineParameter("num", "2");
    pc.defineParameter("name2", "FOONAME");
    pc.defineParameter("FOONAME", "aaa");
    Foo foo = (Foo) pc.getBean("foo");
    assertNotNull(foo);
    assertEquals("$FOONAME", foo.getName());
}
Also used : Foo(jodd.petite.tst.Foo) Test(org.junit.Test)

Example 4 with Foo

use of jodd.petite.tst.Foo in project jodd by oblac.

the class ParamTest method testRefParamsEscape.

@Test
public void testRefParamsEscape() {
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Foo.class, null, null, null, false);
    pc.defineParameter("foo.name", "\\${name}");
    Foo foo = (Foo) pc.getBean("foo");
    assertNotNull(foo);
    assertEquals("${name}", foo.getName());
}
Also used : Foo(jodd.petite.tst.Foo) Test(org.junit.Test)

Example 5 with Foo

use of jodd.petite.tst.Foo in project jodd by oblac.

the class ScopeTest method testThreadLocalScope.

@Test
public void testThreadLocalScope() throws InterruptedException {
    final PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Foo.class, "foo", null, null, false);
    pc.registerPetiteBean(Zoo.class, null, null, null, false);
    pc.registerPetiteBean(Boo.class, null, ThreadLocalScope.class, null, false);
    assertEquals(3, pc.getTotalBeans());
    assertEquals(2, pc.getTotalScopes());
    final Boo boo = (Boo) pc.getBean("boo");
    final Foo foo = (Foo) pc.getBean("foo");
    assertSame(boo.getFoo(), foo);
    final Semaphore sem = new Semaphore(1);
    sem.acquire();
    Thread thread = new Thread() {

        @Override
        public void run() {
            Boo boo2 = (Boo) pc.getBean("boo");
            Foo foo2 = (Foo) pc.getBean("foo");
            assertSame(foo2, foo);
            assertNotSame(boo2, boo);
            assertSame(foo2, boo2.getFoo());
            sem.release();
        }
    };
    thread.start();
    sem.acquire();
    sem.release();
}
Also used : Boo(jodd.petite.tst.Boo) Foo(jodd.petite.tst.Foo) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Aggregations

Foo (jodd.petite.tst.Foo)9 Test (org.junit.Test)9 Boo (jodd.petite.tst.Boo)3 Zoo (jodd.petite.tst.Zoo)2 Properties (java.util.Properties)1 Semaphore (java.util.concurrent.Semaphore)1