Search in sources :

Example 6 with ThemeDefinitionMapper

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());
}
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 7 with ThemeDefinitionMapper

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());
}
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 8 with ThemeDefinitionMapper

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());
}
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)

Example 9 with ThemeDefinitionMapper

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());
}
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 10 with ThemeDefinitionMapper

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");
}
Also used : ThemeDefinitionMapper(io.gravitee.rest.api.service.impl.ThemeServiceImpl.ThemeDefinitionMapper) Test(org.junit.Test)

Aggregations

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