use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldFindAll.
@Test
public void shouldFindAll() throws TechnicalException, JsonProcessingException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
String definition = themeServiceImpl.getDefaultDefinition();
final Theme theme = mock(Theme.class);
when(theme.getId()).thenReturn(THEME_ID);
when(theme.getName()).thenReturn("NAME");
when(theme.getDefinition()).thenReturn(definition);
when(theme.getCreatedAt()).thenReturn(new Date(1));
when(theme.getUpdatedAt()).thenReturn(new Date(2));
when(themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ENVIRONMENT.name())).thenReturn(singleton(theme));
final Set<ThemeEntity> themes = themeService.findAll();
final ThemeEntity themeEntity = themes.iterator().next();
assertEquals(THEME_ID, themeEntity.getId());
assertEquals("NAME", themeEntity.getName());
assertTrue(definitionMapper.isSame(definition, definitionMapper.writeValueAsString(themeEntity.getDefinition())));
assertEquals(new Date(1), themeEntity.getCreatedAt());
assertEquals(new Date(2), themeEntity.getUpdatedAt());
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldFindEnabled.
@Test
public void shouldFindEnabled() throws TechnicalException {
String definition = themeServiceImpl.getDefaultDefinition();
final Theme theme = mock(Theme.class);
when(theme.getId()).thenReturn(THEME_ID);
when(theme.getName()).thenReturn("NAME");
when(theme.isEnabled()).thenReturn(true);
when(theme.getDefinition()).thenReturn(definition);
when(theme.getCreatedAt()).thenReturn(new Date(1));
when(theme.getUpdatedAt()).thenReturn(new Date(2));
when(themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ENVIRONMENT.name())).thenReturn(singleton(theme));
assertNotNull(themeService.findEnabled());
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldFindById.
@Test
public void shouldFindById() throws TechnicalException, JsonProcessingException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
ThemeDefinition themeDefinition = new ThemeDefinition();
themeDefinition.setData(Collections.EMPTY_LIST);
String definition = definitionMapper.writeValueAsString(themeDefinition);
final Theme theme = mock(Theme.class);
when(theme.getId()).thenReturn(THEME_ID);
when(theme.getName()).thenReturn("NAME");
when(theme.getDefinition()).thenReturn(definition);
when(theme.getReferenceId()).thenReturn("DEFAULT");
when(theme.getCreatedAt()).thenReturn(new Date(1));
when(theme.getUpdatedAt()).thenReturn(new Date(2));
when(theme.getFavicon()).thenReturn("favicon.png");
when(themeRepository.findById(THEME_ID)).thenReturn(of(theme));
final ThemeEntity themeEntity = themeService.findById(THEME_ID);
assertEquals(THEME_ID, themeEntity.getId());
assertEquals("NAME", themeEntity.getName());
assertEquals(definition, definitionMapper.writeValueAsString(themeEntity.getDefinition()));
assertEquals(new Date(1), themeEntity.getCreatedAt());
assertEquals(new Date(2), themeEntity.getUpdatedAt());
assertEquals(themeEntity.getFavicon(), theme.getFavicon());
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldGetDefaultIfNoThemeEnabled.
@Test
public void shouldGetDefaultIfNoThemeEnabled() throws TechnicalException {
final Theme theme = mock(Theme.class);
when(theme.isEnabled()).thenReturn(false);
when(themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ENVIRONMENT.name())).thenReturn(singleton(theme));
assertNotNull(themeService.findEnabled());
}
use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException, JsonProcessingException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
ThemeDefinition themeDefinition = new ThemeDefinition();
themeDefinition.setData(Collections.EMPTY_LIST);
String definition = definitionMapper.writeValueAsString(themeDefinition);
final UpdateThemeEntity updateThemeEntity = new UpdateThemeEntity();
updateThemeEntity.setId(THEME_ID);
updateThemeEntity.setName("NAME");
updateThemeEntity.setDefinition(themeDefinition);
final Theme updatedTheme = new Theme();
updatedTheme.setId(THEME_ID);
updatedTheme.setName("NAME");
updatedTheme.setDefinition(definition);
updatedTheme.setCreatedAt(new Date());
updatedTheme.setUpdatedAt(new Date());
when(themeRepository.update(any())).thenReturn(updatedTheme);
when(themeRepository.findById(THEME_ID)).thenReturn(of(updatedTheme));
final ThemeEntity themeEntity = themeService.update(updateThemeEntity);
assertNotNull(themeEntity.getId());
assertEquals("NAME", themeEntity.getName());
assertEquals(definition, definitionMapper.writeValueAsString(themeEntity.getDefinition()));
assertNotNull(themeEntity.getCreatedAt());
assertNotNull(themeEntity.getUpdatedAt());
final Theme theme = new Theme();
theme.setName("NAME");
theme.setDefinition(definition);
theme.setReferenceId("REF_ID");
theme.setReferenceType(ENVIRONMENT.name());
verify(themeRepository, times(1)).update(argThat(argument -> "NAME".equals(argument.getName()) && argument.getDefinition() != null && "DEFAULT".equals(argument.getReferenceId()) && ENVIRONMENT.name().equals(argument.getReferenceType()) && THEME_ID.equals(argument.getId()) && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(THEME, THEME_ID)), eq(Theme.AuditEvent.THEME_UPDATED), any(Date.class), any(), any());
}
Aggregations