use of io.gravitee.repository.management.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldThrowDuplicateThemeNameExceptionOnUpdate.
@Test(expected = DuplicateThemeNameException.class)
public void shouldThrowDuplicateThemeNameExceptionOnUpdate() throws TechnicalException {
final Theme theme = mock(Theme.class);
when(theme.getId()).thenReturn(THEME_ID);
when(theme.getName()).thenReturn("NAME");
when(theme.getDefinition()).thenReturn(themeServiceImpl.getDefaultDefinition());
final Theme theme2 = mock(Theme.class);
when(theme2.getId()).thenReturn("foobar");
when(theme2.getName()).thenReturn("NAME");
when(theme2.getDefinition()).thenReturn(themeServiceImpl.getDefaultDefinition());
when(themeRepository.findById(THEME_ID)).thenReturn(of(theme));
when(themeRepository.findByReferenceIdAndReferenceType(GraviteeContext.getCurrentEnvironment(), ENVIRONMENT.name())).thenReturn(new HashSet(asList(theme, theme2)));
final UpdateThemeEntity updateThemeEntity = new UpdateThemeEntity();
updateThemeEntity.setId(THEME_ID);
updateThemeEntity.setName("NAME");
themeService.update(updateThemeEntity);
}
use of io.gravitee.repository.management.model.Theme 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.model.Theme in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceTest method shouldResetToDefaultTheme.
@Test
public void shouldResetToDefaultTheme() throws TechnicalException, JsonProcessingException {
ThemeDefinition themeDefinition = new ThemeDefinition();
themeDefinition.setData(Collections.EMPTY_LIST);
final Theme theme = new Theme();
theme.setId(THEME_ID);
theme.setName("NAME");
theme.setDefinition(themeServiceImpl.getDefinition(THEMES_PATH + "/custom-definition.json"));
theme.setReferenceId("DEFAULT");
theme.setReferenceType(ENVIRONMENT.name());
theme.setCreatedAt(new Date());
theme.setUpdatedAt(new Date());
themeService.resetToDefaultTheme(THEME_ID);
verify(themeRepository, times(1)).delete(THEME_ID);
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(THEME, THEME_ID)), eq(Theme.AuditEvent.THEME_RESET), any(Date.class), any(), any());
}
use of io.gravitee.repository.management.model.Theme 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.model.Theme 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