Search in sources :

Example 1 with InjectResourceFactory

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());
}
Also used : SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) InjectResourceFactory(com.linkedin.restli.server.resources.InjectResourceFactory) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with InjectResourceFactory

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();
}
Also used : SimpleBeanProvider(com.linkedin.restli.server.mock.SimpleBeanProvider) InjectResourceFactory(com.linkedin.restli.server.resources.InjectResourceFactory) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)2 SimpleBeanProvider (com.linkedin.restli.server.mock.SimpleBeanProvider)2 InjectResourceFactory (com.linkedin.restli.server.resources.InjectResourceFactory)2 BeforeMethod (org.testng.annotations.BeforeMethod)2