Skip to content

Commit

Permalink
Re-introduce test coverage (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Feb 28, 2023
1 parent 87a3c25 commit 83be838
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
82 changes: 81 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/plugin-compat-tester</gitHubRepo>
<jenkins.version>2.392</jenkins.version>
<picocli.version>4.7.1</picocli.version>
<slf4j.version>2.0.6</slf4j.version>
<spotbugs.effort>Max</spotbugs.effort>
Expand Down Expand Up @@ -114,6 +115,19 @@
<artifactId>test-annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-war</artifactId>
<version>${jenkins.version}</version>
<type>executable-war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>text-finder</artifactId>
<version>1.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -163,7 +177,6 @@
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<sortDependencies>scope,groupId,artifactId</sortDependencies>
<sortDependencyExclusions>groupId,artifactId</sortDependencyExclusions>
<sortPlugins>groupId,artifactId</sortPlugins>
<sortModules>true</sortModules>
<sortExecutions>true</sortExecutions>
</sortPom>
Expand Down Expand Up @@ -196,6 +209,73 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<!-- Version specified in parent POM -->
<extensions>true</extensions>
<executions>
<execution>
<id>prepare-test-plugins</id>
<goals>
<goal>resolve-test-dependencies</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- Version specified in parent POM -->
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<includeTypes>executable-war</includeTypes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>prepare-megawar</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<target>
<!-- Keep in sync with logic in jenkinsci/bom/prep.sh -->
<mkdir dir="${project.build.directory}/jenkins" />
<echo file="${project.build.directory}/jenkins/split-plugins.txt"># nothing</echo>
<delete dir="${project.build.directory}/megawar" />
<unzip dest="${project.build.directory}/megawar" src="${project.build.directory}/jenkins-war-${jenkins.version}.war" />
<jar basedir="${project.build.directory}" destfile="${project.build.directory}/megawar/WEB-INF/lib/jenkins-core-${jenkins.version}.jar" includes="jenkins/split-plugins.txt" update="true" />
<copy todir="${project.build.directory}/megawar/WEB-INF/plugins">
<fileset dir="${project.build.directory}/test-classes/test-dependencies">
<include name="**/*.hpi" />
</fileset>
</copy>
<delete dir="${project.build.directory}/megawar/WEB-INF/detached-plugins" />
<delete file="${project.build.directory}/megawar/META-INF/JENKINS.RSA" />
<delete file="${project.build.directory}/megawar/META-INF/JENKINS.SF" />
<war destfile="${project.build.directory}/megawar.war">
<fileset dir="${project.build.directory}/megawar" />
</war>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/jenkins/tools/test/PluginCompatTesterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.jenkins.tools.test.model.PluginCompatTesterConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.jvnet.hudson.test.Issue;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
* Main test class for plugin compatibility test frontend
Expand All @@ -43,6 +55,37 @@
*/
class PluginCompatTesterTest {

@Test
void smokes(@TempDir File tempDir) throws Exception {
PluginCompatTesterConfig config =
new PluginCompatTesterConfig(
new File("target", "megawar.war").getAbsoluteFile(), tempDir);
config.setMavenProperties(Map.of("test", "InjectedTest"));
PluginCompatTester tester = new PluginCompatTester(config);
tester.testPlugins();
Path report =
tempDir.toPath()
.resolve("text-finder")
.resolve("target")
.resolve("surefire-reports")
.resolve("TEST-InjectedTest.xml");
assertTrue(Files.exists(report));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(report.toFile());
Element element = document.getDocumentElement();
int tests = Integer.parseInt(element.getAttribute("tests"));
assertNotEquals(0, tests);
int errors = Integer.parseInt(element.getAttribute("errors"));
assertEquals(0, errors);
int skipped = Integer.parseInt(element.getAttribute("skipped"));
assertEquals(0, skipped);
int failures = Integer.parseInt(element.getAttribute("failures"));
assertEquals(0, failures);
}

@Test
void testMatcher() {

Expand Down

0 comments on commit 83be838

Please sign in to comment.