use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldMergeThemeDefinitionWithLegacy.
@Test
public void shouldMergeThemeDefinitionWithLegacy() throws IOException, TechnicalException {
ThemeDefinitionMapper mapper = new ThemeDefinitionMapper();
String def = themeServiceImpl.getDefaultDefinition();
ThemeDefinition themeDefinition = mapper.readValue(def, ThemeDefinition.class);
String customDef = themeServiceImpl.getDefinition(THEMES_PATH + "/legacy-definition.json");
ThemeDefinition legacyDefinition = mapper.readValue(customDef, ThemeDefinition.class);
assertEquals(38, themeDefinition.getData().size());
assertEquals(35, legacyDefinition.getData().size());
ThemeDefinition mergedDefinition = mapper.merge(def, customDef);
assertNotNull(mergedDefinition);
assertEquals(38, mergedDefinition.getData().size());
assertNotNull(mapper.getThemeCssDefinition(legacyDefinition, "gv-theme", "--gv-theme--c"));
assertNull(mapper.getThemeCssDefinition(themeDefinition, "gv-theme", "--gv-theme--c"));
assertNull(mapper.getThemeCssDefinition(mergedDefinition, "gv-theme", "--gv-theme--c"));
assertNull(mapper.getThemeCssDefinition(legacyDefinition, "gv-theme", "--gv-theme-color"));
assertNotNull(mapper.getThemeCssDefinition(themeDefinition, "gv-theme", "--gv-theme-color"));
assertNotNull(mapper.getThemeCssDefinition(mergedDefinition, "gv-theme", "--gv-theme-color"));
}
use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldCompareDefinition.
@Test
public void shouldCompareDefinition() throws IOException, TechnicalException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
String definition = themeServiceImpl.getDefaultDefinition();
ThemeDefinition themeDefinition = definitionMapper.readDefinition(definition);
String formattedDefinition = definitionMapper.writerWithDefaultPrettyPrinter().writeValueAsString(themeDefinition);
assertNotEquals(definition, formattedDefinition);
assertTrue(definitionMapper.isSame(definition, formattedDefinition));
assertFalse(definitionMapper.isSame(definition, themeServiceImpl.getDefinition(THEMES_PATH + "/custom-definition.json")));
}
use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldUpdateDefaultTheme.
@Test
public void shouldUpdateDefaultTheme() throws TechnicalException, IOException {
ObjectMapper mapper = new ObjectMapper();
ThemeDefinitionMapper themeDefinitionMapper = new ThemeDefinitionMapper();
String definition = themeServiceImpl.getDefaultDefinition();
final Theme theme = mock(Theme.class);
when(theme.getDefinition()).thenReturn(definition);
final Theme theme2 = mock(Theme.class);
when(theme2.getId()).thenReturn(THEME_ID);
when(theme2.getName()).thenReturn("NAME");
String customDefinition = themeServiceImpl.getDefinition(THEMES_PATH + "/custom-definition.json");
when(theme2.getDefinition()).thenReturn(customDefinition);
when(theme2.getReferenceType()).thenReturn(ENVIRONMENT.name());
when(theme2.getReferenceId()).thenReturn("DEFAULT");
when(theme2.getCreatedAt()).thenReturn(new Date(1));
when(theme2.getUpdatedAt()).thenReturn(new Date(2));
when(themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ENVIRONMENT.name())).thenReturn(new HashSet(asList(theme, theme2)));
String mergeDefinition = themeDefinitionMapper.writeValueAsString(themeDefinitionMapper.merge(definition, customDefinition));
themeService.updateDefaultTheme();
verify(themeRepository, times(1)).update(argThat(argument -> {
try {
return ("NAME".equals(argument.getName()) && mapper.readTree(argument.getDefinition()).equals(mapper.readTree(mergeDefinition)) && "DEFAULT".equals(argument.getReferenceId()) && ENVIRONMENT.name().equals(argument.getReferenceType()) && !argument.getId().isEmpty() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}));
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 shouldCreateDefaultTheme.
@Test
public void shouldCreateDefaultTheme() throws TechnicalException, IOException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
String definition = themeServiceImpl.getDefaultDefinition();
final UpdateThemeEntity themeToCreate = new UpdateThemeEntity();
themeToCreate.setId(THEME_ID);
themeToCreate.setName("Default");
themeToCreate.setDefinition(definitionMapper.readDefinition(definition));
final Theme createdTheme = new Theme();
createdTheme.setId(THEME_ID);
createdTheme.setName("Default");
createdTheme.setDefinition(definition);
createdTheme.setCreatedAt(new Date());
createdTheme.setUpdatedAt(new Date());
when(themeRepository.create(any())).thenReturn(createdTheme);
assertEquals(definitionMapper.readTree(definition), definitionMapper.readTree(definition));
assertEquals(definition, definition);
themeService.update(themeToCreate);
verify(themeRepository, times(1)).create(argThat(argument -> {
try {
return ("Default".equals(argument.getName()) && definitionMapper.readTree(argument.getDefinition()).equals(definitionMapper.readTree(definition)) && "DEFAULT".equals(argument.getReferenceId()) && ENVIRONMENT.name().equals(argument.getReferenceType()) && !argument.getId().isEmpty() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null);
} catch (IOException e) {
e.printStackTrace();
}
return false;
}));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(THEME, THEME_ID)), eq(Theme.AuditEvent.THEME_CREATED), any(Date.class), isNull(), any());
}
use of io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException, IOException {
ThemeDefinitionMapper definitionMapper = new ThemeDefinitionMapper();
ThemeDefinition themeDefinition = new ThemeDefinition();
themeDefinition.setData(Collections.EMPTY_LIST);
String definition = definitionMapper.writeValueAsString(themeDefinition);
final NewThemeEntity newThemeEntity = new NewThemeEntity();
newThemeEntity.setName("NAME");
newThemeEntity.setDefinition(themeDefinition);
final Theme createdTheme = new Theme();
createdTheme.setId(THEME_ID);
createdTheme.setName("NAME");
createdTheme.setDefinition(definition);
createdTheme.setCreatedAt(new Date());
createdTheme.setUpdatedAt(new Date());
when(themeRepository.create(any())).thenReturn(createdTheme);
final ThemeEntity themeEntity = themeService.create(newThemeEntity);
assertNotNull(themeEntity.getId());
assertEquals("NAME", themeEntity.getName());
assertNotNull(themeEntity.getDefinition());
assertEquals(0, themeEntity.getDefinition().getData().size());
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)).create(argThat(argument -> {
return ("NAME".equals(argument.getName()) && argument.getDefinition() != null && "DEFAULT".equals(argument.getReferenceId()) && ENVIRONMENT.name().equals(argument.getReferenceType()) && !argument.getId().isEmpty() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null);
}));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(THEME, THEME_ID)), eq(Theme.AuditEvent.THEME_CREATED), any(Date.class), isNull(), any());
}
Aggregations