Search in sources :

Example 1 with SomeResource5

use of com.linkedin.restli.server.resources.fixtures.SomeResource5 in project rest.li by linkedin.

the class TestInjectResourceFactory method testHappyPath.

@Test
public void testHappyPath() {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(SomeResource1.class, SomeResource2.class, SomeResource5.class);
    // set up mock ApplicationContext
    BeanProvider ctx = createMock(BeanProvider.class);
    EasyMock.expect(ctx.getBean(EasyMock.eq("dep1"))).andReturn(new SomeDependency1()).anyTimes();
    EasyMock.expect(ctx.getBean(EasyMock.eq("dep3"))).andReturn(new SomeDependency1()).anyTimes();
    Map<String, SomeDependency2> map = new HashMap<String, SomeDependency2>();
    map.put("someBeanName", new SomeDependency2());
    EasyMock.expect(ctx.getBeansOfType(EasyMock.eq(SomeDependency2.class))).andReturn(map).anyTimes();
    EasyMock.replay(ctx);
    InjectResourceFactory factory = new InjectResourceFactory(ctx);
    factory.setRootResources(pathRootResourceMap);
    // #1 happy path
    SomeResource1 r1 = factory.create(SomeResource1.class);
    assertNotNull(r1);
    assertNotNull(r1.getDependency1());
    assertNotNull(r1.getDependency2());
    assertNull(r1.getNonInjectedDependency());
    // #2 No deps
    SomeResource2 r2 = factory.create(SomeResource2.class);
    assertNotNull(r2);
    // #3 bean not registered with ResourceFactory
    try {
        factory.create(SomeResource3.class);
        fail("Expected no such bean exception");
    } catch (RestLiInternalException e) {
    // expected
    }
    EasyMock.verify(ctx);
    EasyMock.reset(ctx);
    // #4 derived resource
    SomeResource5 r5 = factory.create(SomeResource5.class);
    assertNotNull(r5);
    assertNotNull(r5.getDependency1());
    assertNotNull(r5.getDerivedDependency1());
    assertNotNull(r5.getDependency2());
    assertNotNull(r5.getDependency3());
    assertNull(r5.getNonInjectedDependency());
}
Also used : HashMap(java.util.HashMap) SomeResource5(com.linkedin.restli.server.resources.fixtures.SomeResource5) SomeResource2(com.linkedin.restli.server.resources.fixtures.SomeResource2) SomeDependency2(com.linkedin.restli.server.resources.fixtures.SomeDependency2) SomeDependency1(com.linkedin.restli.server.resources.fixtures.SomeDependency1) SomeResource1(com.linkedin.restli.server.resources.fixtures.SomeResource1) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Test(org.testng.annotations.Test)

Aggregations

RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)1 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)1 SomeDependency1 (com.linkedin.restli.server.resources.fixtures.SomeDependency1)1 SomeDependency2 (com.linkedin.restli.server.resources.fixtures.SomeDependency2)1 SomeResource1 (com.linkedin.restli.server.resources.fixtures.SomeResource1)1 SomeResource2 (com.linkedin.restli.server.resources.fixtures.SomeResource2)1 SomeResource5 (com.linkedin.restli.server.resources.fixtures.SomeResource5)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1