use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.
the class AppConfigControllerTest method before.
@BeforeMethod
public void before() {
MockitoAnnotations.initMocks(this);
// With mock dependencies, the view cache just doesn't work (no cache hits), and tests that aren't
// specifically verifying caching behavior pass.
viewCache = new ViewCache();
viewCache.setCacheProvider(mockCacheProvider);
viewCache.setObjectMapper(BridgeObjectMapper.get());
viewCache.setCachePeriod(100);
controller.setViewCache(viewCache);
doReturn(mockRequest).when(controller).request();
doReturn(mockResponse).when(controller).response();
appConfig = AppConfig.create();
appConfig.setGuid(GUID);
appConfig.setVersion(1L);
app = App.create();
app.setIdentifier(TEST_APP_ID);
session = new UserSession();
session.setAppId(TEST_APP_ID);
session.setParticipant(new StudyParticipant.Builder().withDataGroups(TestConstants.USER_DATA_GROUPS).withLanguages(TestConstants.LANGUAGES).withRoles(ImmutableSet.of(DEVELOPER)).withHealthCode(HEALTH_CODE).build());
}
use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.
the class SurveyControllerTest method before.
@BeforeMethod
public void before() {
MockitoAnnotations.initMocks(this);
// Finish mocking this in each test?
// Dummy this out so it works and we can forget about it as a dependency
cacheMap = new HashMap<>();
viewCache = new ViewCache();
viewCache.setObjectMapper(BridgeObjectMapper.get());
viewCache.setCachePeriod(BRIDGE_VIEW_EXPIRE_IN_SECONDS);
when(mockCacheProvider.getObject(any(), eq(String.class))).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
CacheKey key = invocation.getArgument(0);
return cacheMap.get(key);
}
});
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CacheKey key = invocation.getArgument(0);
String value = invocation.getArgument(1);
cacheMap.put(key, value);
return null;
}
}).when(mockCacheProvider).setObject(any(), anyString(), anyInt());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CacheKey key = invocation.getArgument(0);
cacheMap.remove(key);
return null;
}
}).when(mockCacheProvider).removeObject(any());
viewCache.setCacheProvider(mockCacheProvider);
App app = App.create();
doReturn(app).when(mockAppService).getApp(any(String.class));
controller.setViewCache(viewCache);
doReturn(mockRequest).when(controller).request();
doReturn(mockResponse).when(controller).response();
}
Aggregations