use of com.linkedin.restli.server.resources.InjectResourceFactory in project rest.li by linkedin.
the class TestPhotoResource method initResource.
// function annotated with @BeforeMethod will run once before each test starts
@BeforeMethod
public void initResource() {
// the photo resource requires dependency injection to work
// we use InjectResourceFactory from pegasus to manually inject the dependency
SimpleBeanProvider beanProvider = new SimpleBeanProvider();
final PhotoDatabase photoDb = new PhotoDatabaseImpl(10);
beanProvider.add("photoDb", photoDb);
beanProvider.add("albumDb", new AlbumDatabaseImpl(10));
beanProvider.add("albumEntryDb", new AlbumEntryDatabaseImpl(photoDb, 3));
final InjectResourceFactory factory = new InjectResourceFactory(beanProvider);
final Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(PhotoResource.class);
factory.setRootResources(pathRootResourceMap);
_res = factory.create(PhotoResource.class);
Assert.assertNotNull(_res);
Assert.assertNotNull(_res.getDb());
}
use of com.linkedin.restli.server.resources.InjectResourceFactory in project rest.li by linkedin.
the class TestAlbumEntryResource method initResource.
// function annotated with @BeforeMethod will run once before any test starts
@BeforeMethod
public void initResource() {
// the photo resource requires dependency injection to work
// we use InjectResourceFactory from pegasus to manually inject the dependency
SimpleBeanProvider beanProvider = new SimpleBeanProvider();
final PhotoDatabase photoDb = new PhotoDatabaseImpl(10);
beanProvider.add("photoDb", photoDb);
beanProvider.add("albumDb", new AlbumDatabaseImpl(10));
beanProvider.add("albumEntryDb", new AlbumEntryDatabaseImpl(photoDb, 3));
final InjectResourceFactory factory = new InjectResourceFactory(beanProvider);
final Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(PhotoResource.class, AlbumResource.class, AlbumEntryResource.class);
factory.setRootResources(pathRootResourceMap);
_photoRes = factory.create(PhotoResource.class);
Assert.assertNotNull(_photoRes);
Assert.assertNotNull(_photoRes.getDb());
_albumRes = factory.create(AlbumResource.class);
Assert.assertNotNull(_albumRes);
Assert.assertNotNull(_albumRes.getDb());
_entryRes = factory.create(AlbumEntryResource.class);
Assert.assertNotNull(_entryRes);
makeData();
}
Aggregations