Search in sources :

Example 1 with ViewCache

use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.

the class SpringConfig method genericViewCache.

@Bean(name = "genericViewCache")
@Autowired
public ViewCache genericViewCache(CacheProvider cacheProvider) {
    ViewCache cache = new ViewCache();
    cache.setCacheProvider(cacheProvider);
    cache.setObjectMapper(BridgeObjectMapper.get());
    cache.setCachePeriod(BridgeConstants.BRIDGE_VIEW_EXPIRE_IN_SECONDS);
    return cache;
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) Autowired(org.springframework.beans.factory.annotation.Autowired) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ViewCache

use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.

the class TagControllerTest method getTagsNotCached.

@Test
public void getTagsNotCached() throws Exception {
    when(mockViewCache.getView(eq(CacheKey.tagList()), any())).thenReturn(null);
    CacheProvider mockProvider = mock(CacheProvider.class);
    ViewCache viewCache = new ViewCache();
    viewCache.setCacheProvider(mockProvider);
    viewCache.setObjectMapper(BridgeObjectMapper.get());
    controller.setViewCache(viewCache);
    Map<String, List<String>> map = ImmutableMap.of("a", ImmutableList.of("1", "2", "3"));
    when(mockService.getTags()).thenReturn(map);
    String retValue = controller.getTags();
    assertEquals(retValue, JSON);
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) CacheProvider(org.sagebionetworks.bridge.cache.CacheProvider) Test(org.testng.annotations.Test)

Example 3 with ViewCache

use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.

the class UserProfileControllerTest method before.

@BeforeMethod
public void before() {
    MockitoAnnotations.initMocks(this);
    app = new DynamoApp();
    app.setIdentifier(TEST_APP_ID);
    app.setDataGroups(USER_DATA_GROUPS);
    app.setUserProfileAttributes(TEST_STUDY_ATTRIBUTES);
    when(mockConsentService.getConsentStatuses(any())).thenReturn(CONSENT_STATUSES_MAP);
    when(mockAppService.getApp((String) any())).thenReturn(app);
    ViewCache viewCache = new ViewCache();
    viewCache.setCachePeriod(BRIDGE_VIEW_EXPIRE_IN_SECONDS);
    viewCache.setObjectMapper(BridgeObjectMapper.get());
    viewCache.setCacheProvider(mockCacheProvider);
    controller.setViewCache(viewCache);
    SessionUpdateService sessionUpdateService = new SessionUpdateService();
    sessionUpdateService.setCacheProvider(mockCacheProvider);
    sessionUpdateService.setConsentService(mockConsentService);
    sessionUpdateService.setNotificationTopicService(mockNotificationTopicService);
    controller.setSessionUpdateService(sessionUpdateService);
    session = new UserSession(new StudyParticipant.Builder().withHealthCode(HEALTH_CODE).withId(TEST_USER_ID).build());
    session.setAppId(TEST_APP_ID);
    doReturn(session).when(controller).getAuthenticatedSession();
    doReturn(mockRequest).when(controller).request();
    doReturn(mockResponse).when(controller).response();
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with ViewCache

use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.

the class ApplicationControllerTest method before.

@BeforeMethod
public void before() {
    MockitoAnnotations.initMocks(this);
    ViewCache viewCache = new ViewCache();
    viewCache.setCachePeriod(BridgeConstants.APP_LINKS_EXPIRE_IN_SECONDS);
    viewCache.setObjectMapper(new ObjectMapper());
    viewCache.setCacheProvider(cacheProvider);
    controller.setViewCache(viewCache);
    app = App.create();
    app.setIdentifier(TEST_APP_ID);
    app.setName("<Test App>");
    app.setSupportEmail("support@email.com");
    app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
    doReturn(app).when(appService).getApp(TEST_APP_ID);
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) BridgeObjectMapper(org.sagebionetworks.bridge.json.BridgeObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ViewCache

use of org.sagebionetworks.bridge.cache.ViewCache in project BridgeServer2 by Sage-Bionetworks.

the class SpringConfig method appLinkViewCache.

@Bean(name = "appLinkViewCache")
@Autowired
public ViewCache appLinkViewCache(CacheProvider cacheProvider) {
    ViewCache cache = new ViewCache();
    cache.setCacheProvider(cacheProvider);
    cache.setObjectMapper(new ObjectMapper());
    cache.setCachePeriod(BridgeConstants.APP_LINKS_EXPIRE_IN_SECONDS);
    return cache;
}
Also used : ViewCache(org.sagebionetworks.bridge.cache.ViewCache) BridgeObjectMapper(org.sagebionetworks.bridge.json.BridgeObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

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