mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
use mapstruct for dto mapping and fix missing fields
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.plugin.PluginInformation;
|
||||
import sonia.scm.plugin.PluginState;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PluginDtoMapperTest {
|
||||
|
||||
@SuppressWarnings("unused") // Is injected
|
||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(URI.create("https://hitchhiker.com/"));
|
||||
|
||||
@InjectMocks
|
||||
private PluginDtoMapperImpl mapper;
|
||||
|
||||
@Test
|
||||
void shouldMapInformation() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
|
||||
PluginDto dto = mapper.map(information);
|
||||
|
||||
assertThat(dto.getName()).isEqualTo("scm-cas-plugin");
|
||||
assertThat(dto.getVersion()).isEqualTo("1.0.0");
|
||||
assertThat(dto.getDisplayName()).isEqualTo("CAS");
|
||||
assertThat(dto.getAuthor()).isEqualTo("Sebastian Sdorra");
|
||||
assertThat(dto.getCategory()).isEqualTo("Authentication");
|
||||
assertThat(dto.getAvatarUrl()).isEqualTo("https://avatar.scm-manager.org/plugins/cas.png");
|
||||
}
|
||||
|
||||
private PluginInformation createPluginInformation() {
|
||||
PluginInformation information = new PluginInformation();
|
||||
information.setName("scm-cas-plugin");
|
||||
information.setVersion("1.0.0");
|
||||
information.setDisplayName("CAS");
|
||||
information.setAuthor("Sebastian Sdorra");
|
||||
information.setCategory("Authentication");
|
||||
information.setAvatarUrl("https://avatar.scm-manager.org/plugins/cas.png");
|
||||
return information;
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendInstalledSelfLink() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
information.setState(PluginState.INSTALLED);
|
||||
|
||||
PluginDto dto = mapper.map(information);
|
||||
assertThat(dto.getLinks().getLinkBy("self").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/installed/scm-cas-plugin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendAvailableSelfLink() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
information.setState(PluginState.AVAILABLE);
|
||||
|
||||
PluginDto dto = mapper.map(information);
|
||||
assertThat(dto.getLinks().getLinkBy("self").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/available/scm-cas-plugin/1.0.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendInstallLink() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
information.setState(PluginState.AVAILABLE);
|
||||
|
||||
PluginDto dto = mapper.map(information);
|
||||
assertThat(dto.getLinks().getLinkBy("install").get().getHref())
|
||||
.isEqualTo("https://hitchhiker.com/v2/plugins/available/scm-cas-plugin/1.0.0/install");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnMiscellaneousIfCategoryIsNull() {
|
||||
PluginInformation information = createPluginInformation();
|
||||
information.setCategory(null);
|
||||
|
||||
PluginDto dto = mapper.map(information);
|
||||
assertThat(dto.getCategory()).isEqualTo("Miscellaneous");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sonia.scm.plugin.PluginInformation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -12,19 +10,11 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static sonia.scm.api.v2.resources.PluginCenterDto.Condition;
|
||||
import static sonia.scm.api.v2.resources.PluginCenterDto.Dependency;
|
||||
import static sonia.scm.api.v2.resources.PluginCenterDto.Plugin;
|
||||
import static sonia.scm.plugin.PluginCenterDto.Plugin;
|
||||
import static sonia.scm.plugin.PluginCenterDto.*;
|
||||
|
||||
class PluginCenterDtoMapperTest {
|
||||
|
||||
private PluginCenterDtoMapper pluginCenterDtoMapper;
|
||||
|
||||
@BeforeEach
|
||||
void initMapper() {
|
||||
pluginCenterDtoMapper = new PluginCenterDtoMapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMapSinglePlugin() {
|
||||
Plugin plugin = new Plugin(
|
||||
@@ -82,10 +72,10 @@ class PluginCenterDtoMapperTest {
|
||||
|
||||
Set<PluginInformation> resultSet = PluginCenterDtoMapper.map(Arrays.asList(plugin1, plugin2));
|
||||
|
||||
List pluginsList = new ArrayList(resultSet);
|
||||
List<PluginInformation> pluginsList = new ArrayList<>(resultSet);
|
||||
|
||||
PluginInformation pluginInformation1 = (PluginInformation) pluginsList.get(1);
|
||||
PluginInformation pluginInformation2 = (PluginInformation) pluginsList.get(0);
|
||||
PluginInformation pluginInformation1 = pluginsList.get(1);
|
||||
PluginInformation pluginInformation2 = pluginsList.get(0);
|
||||
|
||||
assertThat(pluginInformation1.getAuthor()).isEqualTo(plugin1.getAuthor());
|
||||
assertThat(pluginInformation1.getVersion()).isEqualTo(plugin1.getVersion());
|
||||
Reference in New Issue
Block a user