Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ plugins {
group = "org.zaproxy.gradle"
version = "0.13.1"

val functionalTest by sourceSets.creating {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}

val functionalTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}

val functionalTestRuntimeOnly by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}

dependencies {
implementation("commons-codec:commons-codec:1.17.1")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.2")
Expand All @@ -29,6 +42,23 @@ dependencies {
exclude(group = "org.jenkins-ci")
}
implementation("com.github.zafarkhaja:java-semver:0.10.2")
testImplementation("org.assertj:assertj-core:3.27.7")
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

val functionalTestTask =
tasks.register<Test>("functionalTest") {
description = "Runs the functional tests."
group = "verification"
testClassesDirs = functionalTest.output.classesDirs
classpath = functionalTest.runtimeClasspath
useJUnitPlatform()
mustRunAfter(tasks.test)
}

tasks.check {
dependsOn(functionalTestTask)
}

tasks.jar {
Expand Down Expand Up @@ -62,6 +92,7 @@ gradlePlugin {
tags.set(listOf("zap", "zaproxy"))
}
}
testSourceSets(functionalTest)
}

spotless {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Zed Attack Proxy (ZAP) and its related class files.
*
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
*
* Copyright 2026 The ZAP Development Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.gradle.addon;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Files;
import java.nio.file.Path;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.io.TempDir;

public abstract class FunctionalTest {

@TempDir protected Path projectDir;

protected static void createFile(String content, Path file) throws Exception {
Files.createDirectories(file.getParent());
Files.writeString(file, content);
}

protected void buildFile(String content) throws Exception {
createFile(content, projectDir.resolve("build.gradle.kts"));
}

protected BuildResult build(String... arguments) throws Exception {
return GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(arguments)
.withPluginClasspath()
.build();
}

protected BuildResult buildAndFail(String... arguments) throws Exception {
return GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(arguments)
.withPluginClasspath()
.buildAndFail();
}

protected static void assertTaskSuccess(BuildResult result, String taskName) {
assertTaskOutcome(result, taskName, TaskOutcome.SUCCESS);
}

protected static void assertTaskFailed(BuildResult result, String taskName) {
assertTaskOutcome(result, taskName, TaskOutcome.FAILED);
}

private static void assertTaskOutcome(
BuildResult result, String taskName, TaskOutcome outcome) {
assertThat(result.task(taskName)).extracting(BuildTask::getOutcome).isEqualTo(outcome);
}
}
Loading