mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
Merge with default
This commit is contained in:
@@ -32,18 +32,23 @@ class PluginInstallerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private AdvancedHttpClient client;
|
||||
|
||||
@Mock
|
||||
private SmpDescriptorExtractor extractor;
|
||||
|
||||
@InjectMocks
|
||||
private PluginInstaller installer;
|
||||
|
||||
private Path directory;
|
||||
|
||||
@BeforeEach
|
||||
void setUpContext(@TempDirectory.TempDir Path directory) {
|
||||
void setUpContext(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
this.directory = directory;
|
||||
lenient().when(context.resolve(any())).then(ic -> {
|
||||
Path arg = ic.getArgument(0);
|
||||
return directory.resolve(arg);
|
||||
});
|
||||
InstalledPluginDescriptor supportedPlugin = createPluginDescriptor(true);
|
||||
lenient().when(extractor.extractPluginDescriptor(any())).thenReturn(supportedPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,6 +110,15 @@ class PluginInstallerTest {
|
||||
assertThat(directory.resolve("plugins").resolve("scm-git-plugin.smp")).doesNotExist();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailForUnsupportedPlugin() throws IOException {
|
||||
mockContent("42");
|
||||
InstalledPluginDescriptor supportedPlugin = createPluginDescriptor(false);
|
||||
when(extractor.extractPluginDescriptor(any())).thenReturn(supportedPlugin);
|
||||
|
||||
assertThrows(PluginConditionFailedException.class, () -> installer.install(createGitPlugin()));
|
||||
assertThat(directory.resolve("plugins").resolve("scm-git-plugin.smp")).doesNotExist();
|
||||
}
|
||||
|
||||
private AvailablePlugin createPlugin(String name, String url, String checksum) {
|
||||
PluginInformation information = new PluginInformation();
|
||||
@@ -114,4 +128,11 @@ class PluginInstallerTest {
|
||||
);
|
||||
return new AvailablePlugin(descriptor);
|
||||
}
|
||||
|
||||
private InstalledPluginDescriptor createPluginDescriptor(boolean supported) {
|
||||
InstalledPluginDescriptor installedPluginDescriptor = mock(InstalledPluginDescriptor.class, RETURNS_DEEP_STUBS);
|
||||
lenient().when(installedPluginDescriptor.getCondition().isSupported()).thenReturn(supported);
|
||||
lenient().when(installedPluginDescriptor.getInformation().getId()).thenReturn("scm-git-plugin");
|
||||
return installedPluginDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class SmpDescriptorExtractorTest {
|
||||
|
||||
private static final String PLUGIN_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
|
||||
"<plugin>\n" +
|
||||
"\n" +
|
||||
" <scm-version>2</scm-version>\n" +
|
||||
"\n" +
|
||||
" <information>\n" +
|
||||
" <displayName>Test</displayName>\n" +
|
||||
" <author>Cloudogu GmbH</author>\n" +
|
||||
" <category>Testing</category>\n" +
|
||||
" <name>scm-test-plugin</name>\n" +
|
||||
"<version>2.0.0</version>\n" +
|
||||
"<description>Collects information for support cases</description>\n" +
|
||||
"</information>\n" +
|
||||
"\n" +
|
||||
" <conditions>\n" +
|
||||
" <min-version>2.0.0-rc1</min-version>\n" +
|
||||
" </conditions>\n" +
|
||||
"\n" +
|
||||
" <resources>\n" +
|
||||
" <script>assets/scm-support-plugin.bundle.js</script>\n" +
|
||||
" </resources>\n" +
|
||||
"\n" +
|
||||
"</plugin>\n";
|
||||
|
||||
@Test
|
||||
void shouldExtractPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/scm/plugin.xml", PLUGIN_XML);
|
||||
|
||||
InstalledPluginDescriptor installedPluginDescriptor = new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile);
|
||||
|
||||
Assertions.assertThat(installedPluginDescriptor.getInformation().getName()).isEqualTo("scm-test-plugin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithoutPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/wrong/plugin.xml", PLUGIN_XML);
|
||||
|
||||
assertThrows(IOException.class, () -> new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithIllegalPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/scm/plugin.xml", "<not><parsable>content</parsable></not>");
|
||||
|
||||
assertThrows(IOException.class, () -> new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile));
|
||||
}
|
||||
|
||||
Path createZipFile(Path tempDir, String internalFileName, String content) throws IOException {
|
||||
Path pluginFile = tempDir.resolve("scm-test-plugin.smp");
|
||||
ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(pluginFile), UTF_8);
|
||||
zipOutputStream.putNextEntry(new ZipEntry(internalFileName));
|
||||
zipOutputStream.write(content.getBytes(UTF_8));
|
||||
zipOutputStream.closeEntry();
|
||||
zipOutputStream.close();
|
||||
return pluginFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user