Search in sources :

Example 6 with ViewCache

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());
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ViewCache

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();
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) ViewCache(org.sagebionetworks.bridge.cache.ViewCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ViewCache (org.sagebionetworks.bridge.cache.ViewCache)7 BeforeMethod (org.testng.annotations.BeforeMethod)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 BridgeObjectMapper (org.sagebionetworks.bridge.json.BridgeObjectMapper)2 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)2 Bean (org.springframework.context.annotation.Bean)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)1 CacheProvider (org.sagebionetworks.bridge.cache.CacheProvider)1 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)1 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)1 App (org.sagebionetworks.bridge.models.apps.App)1 SessionUpdateService (org.sagebionetworks.bridge.services.SessionUpdateService)1 Test (org.testng.annotations.Test)1