Skip to content

Commit a1dd951

Browse files
committed
Test manifest generation
Test the generation of the add-on manifest. Signed-off-by: thc202 <thc202@gmail.com>
1 parent 870ea53 commit a1dd951

3 files changed

Lines changed: 1205 additions & 0 deletions

File tree

build.gradle.kts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ plugins {
99
group = "org.zaproxy.gradle"
1010
version = "0.13.1"
1111

12+
val functionalTest by sourceSets.creating {
13+
compileClasspath += sourceSets.main.get().output
14+
runtimeClasspath += sourceSets.main.get().output
15+
}
16+
17+
val functionalTestImplementation by configurations.getting {
18+
extendsFrom(configurations.testImplementation.get())
19+
}
20+
21+
val functionalTestRuntimeOnly by configurations.getting {
22+
extendsFrom(configurations.testRuntimeOnly.get())
23+
}
24+
1225
dependencies {
1326
implementation("commons-codec:commons-codec:1.17.1")
1427
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.2")
@@ -29,6 +42,23 @@ dependencies {
2942
exclude(group = "org.jenkins-ci")
3043
}
3144
implementation("com.github.zafarkhaja:java-semver:0.10.2")
45+
testImplementation("org.assertj:assertj-core:3.27.7")
46+
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
47+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
48+
}
49+
50+
val functionalTestTask =
51+
tasks.register<Test>("functionalTest") {
52+
description = "Runs the functional tests."
53+
group = "verification"
54+
testClassesDirs = functionalTest.output.classesDirs
55+
classpath = functionalTest.runtimeClasspath
56+
useJUnitPlatform()
57+
mustRunAfter(tasks.test)
58+
}
59+
60+
tasks.check {
61+
dependsOn(functionalTestTask)
3262
}
3363

3464
tasks.jar {
@@ -62,6 +92,7 @@ gradlePlugin {
6292
tags.set(listOf("zap", "zaproxy"))
6393
}
6494
}
95+
testSourceSets(functionalTest)
6596
}
6697

6798
spotless {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Zed Attack Proxy (ZAP) and its related class files.
3+
*
4+
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
5+
*
6+
* Copyright 2026 The ZAP Development Team
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.zaproxy.gradle.addon;
21+
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
26+
import org.gradle.testkit.runner.BuildResult;
27+
import org.gradle.testkit.runner.BuildTask;
28+
import org.gradle.testkit.runner.GradleRunner;
29+
import org.gradle.testkit.runner.TaskOutcome;
30+
import org.junit.jupiter.api.io.TempDir;
31+
32+
public abstract class FunctionalTest {
33+
34+
@TempDir protected Path projectDir;
35+
36+
protected static void createFile(String content, Path file) throws Exception {
37+
Files.createDirectories(file.getParent());
38+
Files.writeString(file, content);
39+
}
40+
41+
protected void buildFile(String content) throws Exception {
42+
createFile(content, projectDir.resolve("build.gradle.kts"));
43+
}
44+
45+
protected BuildResult build(String... arguments) throws Exception {
46+
return GradleRunner.create()
47+
.withProjectDir(projectDir.toFile())
48+
.withArguments(arguments)
49+
.withPluginClasspath()
50+
.build();
51+
}
52+
53+
protected BuildResult buildAndFail(String... arguments) throws Exception {
54+
return GradleRunner.create()
55+
.withProjectDir(projectDir.toFile())
56+
.withArguments(arguments)
57+
.withPluginClasspath()
58+
.buildAndFail();
59+
}
60+
61+
protected static void assertTaskSuccess(BuildResult result, String taskName) {
62+
assertTaskOutcome(result, taskName, TaskOutcome.SUCCESS);
63+
}
64+
65+
protected static void assertTaskFailed(BuildResult result, String taskName) {
66+
assertTaskOutcome(result, taskName, TaskOutcome.FAILED);
67+
}
68+
69+
private static void assertTaskOutcome(
70+
BuildResult result, String taskName, TaskOutcome outcome) {
71+
assertThat(result.task(taskName)).extracting(BuildTask::getOutcome).isEqualTo(outcome);
72+
}
73+
}

0 commit comments

Comments
 (0)