Search in sources :

Example 1 with ConstructorArgResource

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

the class TestInjectResourceFactory method testInjectConstructorArgs.

@Test
public void testInjectConstructorArgs() {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(ConstructorArgResource.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
    ConstructorArgResource r1 = factory.create(ConstructorArgResource.class);
    assertNotNull(r1);
    assertNotNull(r1.getDependency1());
    assertNotNull(r1.getDependency2());
    assertNull(r1.getNonInjectedDependency());
}
Also used : SomeDependency2(com.linkedin.restli.server.resources.fixtures.SomeDependency2) SomeDependency1(com.linkedin.restli.server.resources.fixtures.SomeDependency1) ConstructorArgResource(com.linkedin.restli.server.resources.fixtures.ConstructorArgResource) HashMap(java.util.HashMap) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Test(org.testng.annotations.Test)

Aggregations

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