Search in sources :

Example 11 with Theme

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());
}
Also used : Theme(io.gravitee.repository.management.model.Theme) ThemeDefinitionMapper(io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Theme

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());
}
Also used : Theme(io.gravitee.repository.management.model.Theme) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Theme

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());
}
Also used : Theme(io.gravitee.repository.management.model.Theme) ThemeDefinitionMapper(io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Theme

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());
}
Also used : Theme(io.gravitee.repository.management.model.Theme) Test(org.junit.Test)

Example 15 with Theme

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());
}
Also used : Optional.empty(java.util.Optional.empty) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Theme(io.gravitee.repository.management.model.Theme) Date(java.util.Date) Mock(org.mockito.Mock) ENVIRONMENT(io.gravitee.repository.management.model.ThemeReferenceType.ENVIRONMENT) Optional.of(java.util.Optional.of) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) HashSet(java.util.HashSet) Collections.singleton(java.util.Collections.singleton) Arrays.asList(java.util.Arrays.asList) DuplicateThemeNameException(io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException) ThemeNotFoundException(io.gravitee.rest.api.service.exceptions.ThemeNotFoundException) Before(org.junit.Before) THEME(io.gravitee.repository.management.model.Audit.AuditProperties.THEME) InjectMocks(org.mockito.InjectMocks) PictureEntity(io.gravitee.rest.api.model.PictureEntity) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Test(org.junit.Test) ThemeRepository(io.gravitee.repository.management.api.ThemeRepository) UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) ThemeDefinitionMapper(io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper) Mockito(org.mockito.Mockito) io.gravitee.rest.api.model.theme(io.gravitee.rest.api.model.theme) ThemeServiceImpl(io.gravitee.rest.api.service.impl.ThemeServiceImpl) Assert(org.junit.Assert) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Theme(io.gravitee.repository.management.model.Theme) ThemeDefinitionMapper(io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Theme (io.gravitee.repository.management.model.Theme)24 Test (org.junit.Test)17 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)10 Date (java.util.Date)10 InlinePictureEntity (io.gravitee.rest.api.model.InlinePictureEntity)8 PictureEntity (io.gravitee.rest.api.model.PictureEntity)8 UrlPictureEntity (io.gravitee.rest.api.model.UrlPictureEntity)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 DuplicateThemeNameException (io.gravitee.rest.api.service.exceptions.DuplicateThemeNameException)7 ThemeDefinitionMapper (io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper)7 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)6 ThemeNotFoundException (io.gravitee.rest.api.service.exceptions.ThemeNotFoundException)6 IOException (java.io.IOException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ThemeRepository (io.gravitee.repository.management.api.ThemeRepository)5 THEME (io.gravitee.repository.management.model.Audit.AuditProperties.THEME)5 io.gravitee.rest.api.model.theme (io.gravitee.rest.api.model.theme)5 GraviteeContext (io.gravitee.rest.api.service.common.GraviteeContext)5 HashSet (java.util.HashSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4