Skip to content

Commit 27e2247

Browse files
committed
NCLSUP-535 Rewrite war test
1 parent 455be28 commit 27e2247

6 files changed

Lines changed: 113 additions & 45 deletions

File tree

analyzer/src/functTest/java/org/jboss/pnc/gradlemanipulator/analyzer/alignment/WarFunctionalTest.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,16 @@
1010
import java.io.IOException;
1111
import java.net.URISyntaxException;
1212
import java.nio.file.Path;
13-
import java.nio.file.Paths;
14-
import java.util.Collection;
1513
import java.util.Collections;
16-
import java.util.Comparator;
1714
import java.util.HashMap;
1815
import java.util.Map;
19-
import java.util.Objects;
20-
import java.util.zip.ZipEntry;
21-
import java.util.zip.ZipFile;
2216
import kong.unirest.ContentType;
2317
import kong.unirest.HeaderNames;
2418
import kong.unirest.HttpStatus;
2519
import org.commonjava.atlas.maven.ident.ref.ProjectVersionRef;
2620
import org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef;
27-
import org.eclipse.jgit.api.Git;
2821
import org.eclipse.jgit.api.errors.GitAPIException;
29-
import org.eclipse.jgit.lib.Ref;
3022
import org.gradle.api.Project;
31-
import org.gradle.testkit.runner.BuildResult;
32-
import org.gradle.testkit.runner.TaskOutcome;
3323
import org.jboss.pnc.gradlemanipulator.analyzer.alignment.TestUtils.TestManipulationModel;
3424
import org.jboss.pnc.gradlemanipulator.common.Configuration;
3525
import org.jboss.pnc.gradlemanipulator.common.utils.FileUtils;
@@ -105,18 +95,6 @@ public void verifyWar()
10595
final Path projectRoot = tempDir.newFolder(PROJECT_NAME).toPath();
10696
final Map<String, String> properties = new HashMap<>();
10797

108-
// On a new release the SNAPSHOT artifact (e.g. 3.2-SNAPSHOT) for the manipulation library
109-
// may not be available causing this to fail. We can't do the same as DifferentJVMTest as
110-
// we need the manipulation library built. Hence, we'll use JGit to establish the last tag
111-
// (i.e. release) and use that.
112-
Collection<Ref> refs2 = Git.lsRemoteRepository()
113-
.setRemote("https://github.com/project-ncl/gradle-manipulator.git")
114-
.setTags(true)
115-
.call();
116-
@SuppressWarnings("OptionalGetWithoutIsPresent")
117-
String name = refs2.stream().map(Ref::getName).max(Comparator.naturalOrder()).get();
118-
properties.put("manipulationVersion", name.substring(name.lastIndexOf('/') + 1));
119-
12098
final TestManipulationModel alignmentModel = TestUtils.align(
12199
projectRoot.toFile(),
122100
projectRoot.getFileName().toString(),
@@ -132,28 +110,5 @@ public void verifyWar()
132110
.contains("Passing 1 GAVs into the REST client api [" + GAV + "]");
133111
assertThat(alignmentModel).isNotNull();
134112
assertThat(alignmentModel.getAlignedDependencies()).containsExactlyEntriesOf(DEPENDENCIES);
135-
136-
verifyWar(projectRoot);
137-
}
138-
139-
private static void verifyWar(Path projectRoot) throws IOException {
140-
final BuildResult buildResult = TestUtils.createGradleRunner(projectRoot.toFile(), Collections.emptyMap())
141-
.withArguments("war")
142-
.build();
143-
144-
assertThat(Objects.requireNonNull(buildResult.task(":war")).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
145-
146-
final Path warPath = Paths.get("build", "libs", PROJECT_NAME + ".war");
147-
final Path warFile = projectRoot.resolve(warPath);
148-
149-
assertThat(warFile).isRegularFile().isReadable();
150-
151-
try (final ZipFile zipFile = new ZipFile(warFile.toFile())) {
152-
assertThat(
153-
zipFile.stream()
154-
.filter(zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().endsWith(".jar"))
155-
.map(ZipEntry::getName))
156-
.containsExactly("WEB-INF/lib/" + ARTIFACT_ID + "-" + VERSION_NEW + ".jar");
157-
}
158113
}
159114
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.jboss.pnc.gradlemanipulator.manipulation;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
import java.util.Objects;
11+
import java.util.zip.ZipEntry;
12+
import java.util.zip.ZipFile;
13+
import org.gradle.testkit.runner.BuildResult;
14+
import org.gradle.testkit.runner.TaskOutcome;
15+
import org.junit.Rule;
16+
import org.junit.Test;
17+
import org.junit.rules.TemporaryFolder;
18+
import org.junit.rules.TestRule;
19+
import uk.org.webcompere.systemstubs.rules.SystemOutRule;
20+
import uk.org.webcompere.systemstubs.rules.SystemPropertiesRule;
21+
22+
public class WarFunctionalTest {
23+
@Rule
24+
public final SystemOutRule systemOutRule = new SystemOutRule();
25+
26+
@Rule
27+
public final TestRule restoreSystemProperties = new SystemPropertiesRule();
28+
29+
@Rule
30+
public TemporaryFolder tempDir = new TemporaryFolder();
31+
32+
private static final String PROJECT_NAME = "war-project";
33+
34+
private static final String ARTIFACT_ID = "jboss-servlet-api_2.5_spec";
35+
36+
private static final String VERSION_NEW = "1.0.1.Final";
37+
38+
@Test
39+
public void verifyWar() throws IOException, URISyntaxException {
40+
41+
final File projectRoot = tempDir.newFolder("war-project");
42+
TestUtils.copyDirectory("war-project", projectRoot);
43+
assertThat(projectRoot.toPath().resolve("build.gradle")).exists();
44+
45+
final File publishDirectory = tempDir.newFolder("publish");
46+
System.setProperty("AProxDeployUrl", "file://" + publishDirectory.toString());
47+
48+
final BuildResult buildResult = TestUtils.createGradleRunner()
49+
.withProjectDir(projectRoot)
50+
.withArguments("--info", "assemble", "publish")
51+
.forwardOutput()
52+
.withPluginClasspath()
53+
.build();
54+
55+
assertThat(Objects.requireNonNull(buildResult.task(":war")).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
56+
57+
final Path warPath = Paths.get("build", "libs", PROJECT_NAME + ".war");
58+
final Path warFile = projectRoot.toPath().resolve(warPath);
59+
60+
assertThat(warFile).isRegularFile().isReadable();
61+
62+
try (final ZipFile zipFile = new ZipFile(warFile.toFile())) {
63+
assertThat(
64+
zipFile.stream()
65+
.filter(zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().endsWith(".jar"))
66+
.map(ZipEntry::getName))
67+
.containsExactly("WEB-INF/lib/" + ARTIFACT_ID + "-" + VERSION_NEW + ".jar");
68+
}
69+
}
70+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
// including this plugin directly instead of by an init script, which allows to use the freshly build version
3+
id 'org.jboss.pnc.gradle-manipulator.manipulation'
4+
id 'war'
5+
}
6+
7+
apply plugin: 'org.jboss.pnc.gradle-manipulator.manipulation'
8+
apply plugin: 'maven-publish'
9+
10+
java {
11+
sourceCompatibility = JavaVersion.VERSION_1_8
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
maven {
17+
url 'https://maven.repository.redhat.com/ga/'
18+
}
19+
}
20+
21+
dependencies {
22+
implementation 'org.jboss.spec.javax.servlet:jboss-servlet-api_2.5_spec:1.0.1.Final'
23+
}
24+
25+
war {
26+
archiveFileName = 'war-project.war'
27+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
group=org.acme.gradle
2+
version=1.0.1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"group": "org.acme.gradle",
3+
"name": "root",
4+
"version": "1.0.2.redhat-00001",
5+
"originalVersion" : "1.0.2",
6+
"alignedDependencies": {
7+
"org.jboss.spec.javax.servlet:jboss-servlet-api_2.5_spec:1.0.0.Final": {
8+
"groupId": "org.jboss.spec.javax.servlet",
9+
"artifactId": "jboss-servlet-api_2.5_spec",
10+
"version": "1.0.1.Final"
11+
}
12+
}
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'root'

0 commit comments

Comments
 (0)