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