use of io.gravitee.repository.management.api.ThemeRepository 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.repository.management.api.ThemeRepository 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.repository.management.api.ThemeRepository 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());
}
use of io.gravitee.repository.management.api.ThemeRepository 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