use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper 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.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper 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.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper 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());
}
use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldThrowThemeNotFoundExceptionWhenThemeIsNotInDefaultEnv.
@Test(expected = ThemeNotFoundException.class)
public void shouldThrowThemeNotFoundExceptionWhenThemeIsNotInDefaultEnv() 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.getReferenceId()).thenReturn("NOT-DEFAULT");
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());
}
use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldMergeThemeDefinition.
@Test
public void shouldMergeThemeDefinition() throws IOException, TechnicalException {
ThemeDefinitionMapper mapper = new ThemeDefinitionMapper();
String def = themeServiceImpl.getDefinition(THEMES_PATH + "/base-definition.json");
ThemeDefinition baseDefinition = mapper.readValue(def, ThemeDefinition.class);
String customDef = themeServiceImpl.getDefinition(THEMES_PATH + "/custom-definition.json");
ThemeDefinition customDefinition = mapper.readValue(customDef, ThemeDefinition.class);
assertEquals(33, customDefinition.getData().size());
assertNull(mapper.getThemeComponentDefinition(baseDefinition, "gv-pagination"));
assertNotNull(mapper.getThemeComponentDefinition(customDefinition, "gv-pagination"));
assertEquals(mapper.getThemeComponentDefinition(baseDefinition, "gv-plans").getCss().size(), 5);
assertEquals(mapper.getThemeComponentDefinition(customDefinition, "gv-plans").getCss().size(), 4);
assertEquals(mapper.getThemeComponentDefinition(baseDefinition, "gv-popover").getCss().size(), 2);
assertEquals(mapper.getThemeComponentDefinition(customDefinition, "gv-popover").getCss().size(), 3);
ThemeCssDefinition gvThemeColor = mapper.getThemeCssDefinition(baseDefinition, "gv-theme", "--gv-theme-color");
assertNull(gvThemeColor.getDefaultValue());
assertEquals(gvThemeColor.getType(), ThemeCssType.COLOR);
assertEquals(gvThemeColor.getValue(), "#009B5B");
ThemeCssDefinition gvButtonFz = mapper.getThemeCssDefinition(baseDefinition, "gv-button", "--gv-button--fz");
assertNull(gvButtonFz.getDefaultValue());
assertEquals(gvButtonFz.getType(), ThemeCssType.LENGTH);
assertEquals(gvButtonFz.getValue(), "var(--gv-theme-font-size-m, 14px)");
assertEquals(gvButtonFz.getDescription(), "Font size");
ThemeDefinition mergedDefinition = mapper.merge(def, customDef);
assertEquals(34, mergedDefinition.getData().size());
assertNull(mapper.getThemeComponentDefinition(mergedDefinition, "gv-pagination"));
assertEquals(mapper.getThemeComponentDefinition(mergedDefinition, "gv-plans").getCss().size(), 5);
assertEquals(mapper.getThemeComponentDefinition(mergedDefinition, "gv-popover").getCss().size(), 2);
ThemeCssDefinition gvThemeColorMerged = mapper.getThemeCssDefinition(mergedDefinition, "gv-theme", "--gv-theme-color");
assertNull(gvThemeColorMerged.getDefaultValue());
assertEquals(gvThemeColorMerged.getType(), ThemeCssType.COLOR);
assertEquals(gvThemeColorMerged.getValue(), "#FAFAFA");
ThemeCssDefinition gvButtonFzMerged = mapper.getThemeCssDefinition(mergedDefinition, "gv-button", "--gv-button--fz");
assertNull(gvButtonFzMerged.getDefaultValue());
assertEquals(gvButtonFzMerged.getType(), ThemeCssType.LENGTH);
assertEquals(gvButtonFzMerged.getValue(), "200px");
assertEquals(gvButtonFzMerged.getDescription(), "Font size");
}
Aggregations