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());
}
Aggregations