use of com.linkedin.restli.server.resources.fixtures.SomeDependency2 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());
}
use of com.linkedin.restli.server.resources.fixtures.SomeDependency2 in project rest.li by linkedin.
the class TestInjectResourceFactory method testMissingNamedDependency.
@Test
public void testMissingNamedDependency() {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(SomeResource1.class);
BeanProvider ctx = EasyMock.createMock(BeanProvider.class);
EasyMock.expect(ctx.getBean(EasyMock.eq("dep1"))).andReturn(null).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);
try {
factory.setRootResources(pathRootResourceMap);
fail("Expected unresolvable bean exception");
} catch (RestLiInternalException e) {
assertTrue(e.getMessage().startsWith("Expected to find"));
}
EasyMock.verify(ctx);
}
use of com.linkedin.restli.server.resources.fixtures.SomeDependency2 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());
}
use of com.linkedin.restli.server.resources.fixtures.SomeDependency2 in project rest.li by linkedin.
the class TestInjectResourceFactory method testAmbiguousBeanResolution.
@Test
public void testAmbiguousBeanResolution() throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(SomeResource1.class, SomeResource2.class, SomeResource4.class);
// set up mock ApplicationContext
BeanProvider ctx = EasyMock.createMock(BeanProvider.class);
EasyMock.expect(ctx.getBean(EasyMock.eq("dep1"))).andReturn(new SomeDependency1()).anyTimes();
Map<String, SomeDependency2> map2 = new HashMap<String, SomeDependency2>();
map2.put("someBeanName", new SomeDependency2());
EasyMock.expect(ctx.getBeansOfType(EasyMock.eq(SomeDependency2.class))).andReturn(map2).anyTimes();
Map<String, SomeDependency1> map1 = new HashMap<String, SomeDependency1>();
map1.put("someDep1", new SomeDependency1());
map1.put("anotherDep1", new SomeDependency1());
EasyMock.expect(ctx.getBeansOfType(EasyMock.eq(SomeDependency1.class))).andReturn(map1).anyTimes();
EasyMock.replay(ctx);
InjectResourceFactory factory = new InjectResourceFactory(ctx);
// #4 ambiguous dep
try {
factory.setRootResources(pathRootResourceMap);
fail("Expected unresolvable bean exception");
} catch (RestLiInternalException e) {
assertTrue(e.getMessage().startsWith("Expected to find"));
}
EasyMock.verify(ctx);
EasyMock.reset(ctx);
}
Aggregations