2019-08-15 17:01:15 +02:00
|
|
|
package sonia.scm.plugin;
|
2019-07-31 16:59:13 +02:00
|
|
|
|
2019-08-20 07:53:17 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2019-07-31 16:59:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2019-08-20 12:29:59 +02:00
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
|
import org.mockito.Answers;
|
|
|
|
|
import org.mockito.InjectMocks;
|
|
|
|
|
import org.mockito.Mock;
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
2019-07-31 16:59:13 +02:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
2019-08-20 12:29:59 +02:00
|
|
|
import static org.mockito.Mockito.when;
|
2019-08-15 17:01:15 +02:00
|
|
|
import static sonia.scm.plugin.PluginCenterDto.Plugin;
|
|
|
|
|
import static sonia.scm.plugin.PluginCenterDto.*;
|
2019-07-31 16:59:13 +02:00
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
@ExtendWith(MockitoExtension.class)
|
2019-07-31 16:59:13 +02:00
|
|
|
class PluginCenterDtoMapperTest {
|
|
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
|
|
|
private PluginCenterDto dto;
|
|
|
|
|
|
|
|
|
|
@InjectMocks
|
|
|
|
|
private PluginCenterDtoMapperImpl mapper;
|
|
|
|
|
|
2019-07-31 16:59:13 +02:00
|
|
|
@Test
|
|
|
|
|
void shouldMapSinglePlugin() {
|
|
|
|
|
Plugin plugin = new Plugin(
|
|
|
|
|
"scm-hitchhiker-plugin",
|
|
|
|
|
"SCM Hitchhiker Plugin",
|
|
|
|
|
"plugin for hitchhikers",
|
|
|
|
|
"Travel",
|
|
|
|
|
"2.0.0",
|
|
|
|
|
"trillian",
|
2019-08-12 11:16:47 +02:00
|
|
|
"http://avatar.url",
|
2019-07-31 16:59:13 +02:00
|
|
|
"555000444",
|
2019-08-12 11:16:47 +02:00
|
|
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
2019-08-20 07:53:17 +02:00
|
|
|
ImmutableSet.of("scm-review-plugin"),
|
2019-07-31 16:59:13 +02:00
|
|
|
new HashMap<>());
|
|
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
when(dto.getEmbedded().getPlugins()).thenReturn(Collections.singletonList(plugin));
|
|
|
|
|
AvailablePluginDescriptor descriptor = mapper.map(dto).iterator().next().getDescriptor();
|
|
|
|
|
PluginInformation information = descriptor.getInformation();
|
|
|
|
|
PluginCondition condition = descriptor.getCondition();
|
2019-07-31 16:59:13 +02:00
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
assertThat(information.getAuthor()).isEqualTo(plugin.getAuthor());
|
|
|
|
|
assertThat(information.getCategory()).isEqualTo(plugin.getCategory());
|
|
|
|
|
assertThat(information.getVersion()).isEqualTo(plugin.getVersion());
|
|
|
|
|
assertThat(condition.getArch()).isEqualTo(plugin.getConditions().getArch());
|
|
|
|
|
assertThat(condition.getMinVersion()).isEqualTo(plugin.getConditions().getMinVersion());
|
|
|
|
|
assertThat(condition.getOs().iterator().next()).isEqualTo(plugin.getConditions().getOs().iterator().next());
|
|
|
|
|
assertThat(information.getDescription()).isEqualTo(plugin.getDescription());
|
|
|
|
|
assertThat(information.getName()).isEqualTo(plugin.getName());
|
2019-07-31 16:59:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void shouldMapMultiplePlugins() {
|
|
|
|
|
Plugin plugin1 = new Plugin(
|
2019-08-12 11:16:47 +02:00
|
|
|
"scm-review-plugin",
|
2019-07-31 16:59:13 +02:00
|
|
|
"SCM Hitchhiker Plugin",
|
|
|
|
|
"plugin for hitchhikers",
|
|
|
|
|
"Travel",
|
2019-08-12 11:16:47 +02:00
|
|
|
"2.1.0",
|
|
|
|
|
"trillian",
|
|
|
|
|
"https://avatar.url",
|
|
|
|
|
"12345678aa",
|
|
|
|
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
2019-08-20 07:53:17 +02:00
|
|
|
ImmutableSet.of("scm-review-plugin"),
|
2019-07-31 16:59:13 +02:00
|
|
|
new HashMap<>());
|
|
|
|
|
|
|
|
|
|
Plugin plugin2 = new Plugin(
|
2019-08-12 11:16:47 +02:00
|
|
|
"scm-hitchhiker-plugin",
|
2019-07-31 16:59:13 +02:00
|
|
|
"SCM Hitchhiker Plugin",
|
|
|
|
|
"plugin for hitchhikers",
|
|
|
|
|
"Travel",
|
2019-08-12 11:16:47 +02:00
|
|
|
"2.0.0",
|
|
|
|
|
"dent",
|
|
|
|
|
"http://avatar.url",
|
|
|
|
|
"555000444",
|
|
|
|
|
new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
|
2019-08-20 07:53:17 +02:00
|
|
|
ImmutableSet.of("scm-review-plugin"),
|
2019-07-31 16:59:13 +02:00
|
|
|
new HashMap<>());
|
|
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
when(dto.getEmbedded().getPlugins()).thenReturn(Arrays.asList(plugin1, plugin2));
|
|
|
|
|
|
|
|
|
|
Set<AvailablePlugin> resultSet = mapper.map(dto);
|
2019-07-31 16:59:13 +02:00
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
List<AvailablePlugin> pluginsList = new ArrayList<>(resultSet);
|
2019-07-31 16:59:13 +02:00
|
|
|
|
2019-08-20 12:29:59 +02:00
|
|
|
PluginInformation pluginInformation1 = pluginsList.get(1).getDescriptor().getInformation();
|
|
|
|
|
PluginInformation pluginInformation2 = pluginsList.get(0).getDescriptor().getInformation();
|
2019-07-31 16:59:13 +02:00
|
|
|
|
|
|
|
|
assertThat(pluginInformation1.getAuthor()).isEqualTo(plugin1.getAuthor());
|
|
|
|
|
assertThat(pluginInformation1.getVersion()).isEqualTo(plugin1.getVersion());
|
|
|
|
|
assertThat(pluginInformation2.getAuthor()).isEqualTo(plugin2.getAuthor());
|
|
|
|
|
assertThat(pluginInformation2.getVersion()).isEqualTo(plugin2.getVersion());
|
|
|
|
|
assertThat(resultSet.size()).isEqualTo(2);
|
|
|
|
|
}
|
|
|
|
|
}
|