Add missing PluginProcessor tests

This commit is contained in:
Sebastian Sdorra
2020-08-07 08:13:52 +02:00
parent 8b8ef7f826
commit 49c980e9af
4 changed files with 168 additions and 1 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
@@ -37,6 +37,8 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
import javax.xml.bind.JAXB;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@@ -53,6 +55,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
*
@@ -96,8 +100,40 @@ public class PluginProcessorTest
new PluginResource("sonia/scm/plugin/scm-f-plugin-1.0.1.smp",
"scm-f-plugin.smp", "scm-f-plugin:1.0.1");
private static final String PLUGIN_G = "sonia/scm/plugin/scm-g-plugin.xml";
private static final String PLUGIN_H = "sonia/scm/plugin/scm-h-plugin.xml";
private static final String PLUGIN_I = "sonia/scm/plugin/scm-i-plugin.xml";
//~--- methods --------------------------------------------------------------
@Test(expected = PluginConditionFailedException.class)
public void testFailedPluginCondition() throws IOException {
createPlugin(PLUGIN_G);
collectPlugins();
}
@Test(expected = DependencyVersionMismatchException.class)
public void testWrongVersionOfDependency() throws IOException {
createPlugin(PLUGIN_H);
createPlugin(PLUGIN_I);
collectPlugins();
}
@SuppressWarnings("UnstableApiUsage")
private void createPlugin(String descriptorResource) throws IOException {
URL resource = Resources.getResource(descriptorResource);
InstalledPluginDescriptor descriptor = JAXB.unmarshal(resource, InstalledPluginDescriptor.class);
File file = new File(pluginDirectory, descriptor.getInformation().getName() + ".smp");
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(file))) {
zip.putNextEntry(new ZipEntry("META-INF/scm/plugin.xml"));
Resources.copy(resource, zip);
}
}
/**
* Method description
*

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ MIT License
~
~ Copyright (c) 2020-present Cloudogu GmbH and Contributors
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<plugin>
<scm-version>2</scm-version>
<information>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-g-plugin</artifactId>
<version>1.0.0</version>
<name>scm-g-plugin</name>
<description>Plugin g has a min version over 9000</description>
</information>
<conditions>
<min-version>9000.0.0</min-version>
</conditions>
<packages>
<package>sonia.scm.plugins</package>
</packages>
</plugin>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ MIT License
~
~ Copyright (c) 2020-present Cloudogu GmbH and Contributors
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<plugin>
<scm-version>2</scm-version>
<information>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-h-plugin</artifactId>
<version>1.0.0</version>
<name>scm-h-plugin</name>
<description>Plugin h is nothing special</description>
</information>
<packages>
<package>sonia.scm.plugins</package>
</packages>
</plugin>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
~ MIT License
~
~ Copyright (c) 2020-present Cloudogu GmbH and Contributors
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<plugin>
<scm-version>2</scm-version>
<information>
<groupId>sonia.scm.plugins</groupId>
<artifactId>scm-i-plugin</artifactId>
<version>1.0.0</version>
<name>scm-i-plugin</name>
<description>Plugin i depends on h in version 1.2.0</description>
</information>
<packages>
<package>sonia.scm.plugins</package>
</packages>
<dependencies>
<dependency version="1.2.0">scm-h-plugin</dependency>
</dependencies>
</plugin>