These are my ext program variables:
ext {
skipIntegrationTests = 'false'
skipUnitTests = 'false'
localEnv = 'false'
xmakeEnv = 'false'
encoding = 'UTF-8'
integrationEnvDir = 'integration-env'
zapVersion = '2.12.0'
itsVersion = '0.0.17'
spotlessPhase = 'none'
depxmlcontent = null
extfiles = null
zapPort = null
jettyPort = null
}
I have a gradle task called reservePorts as follows:
task reservePorts(dependsOn: generateFioriPythonApi) {
doLast {
def zapPort = reservePort('zapDynPort')
def jettyPort = reservePort('jettyDynPort')
project.ext.zapPort = zapPort.toString()
project.ext.jettyPort = jettyPort.toString()
println "Reserved ports for zapDynPort: ${project.ext.zapPort} and jettyDynPort: ${project.ext.jettyPort}"
}
}
Which gives the following output:
Task :reservePorts Reserved ports for zapDynPort: 54772 and jettyDynPort: 54773
I have a task in gradle for running the Integration Test as follows:
task integrationTest(type: Test, dependsOn: downloadFioridastItsWar) {
System.setProperty("zap.port", "${project.ext.zapPort}")
System.setProperty("jetty.port", "${project.ext.jettyPort}")
ignoreFailures = true
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
testLogging {
events 'PASSED', 'FAILED', 'SKIPPED'
}
}
When I print the value of System.getProperty("zap.port") in gradle I get value for zap.port as 54772 which is correct which means that the value for zap.port is getting set is System Property correctly.
But when i run the Integration Test it gives the foloowing error:
Task :integrationTest
org.zaproxy.zap.extension.fioriscanner.api.BasicAPIUsageIntegrationTest > classMethod FAILED java.lang.NumberFormatException at BasicAPIUsageIntegrationTest.java:22
org.zaproxy.zap.extension.fioriscanner.dynamic.DynamicAppsIntegrationTest > classMethod FAILED java.lang.NumberFormatException at DynamicAppsIntegrationTest.java:53
Now the BasicAPIUsageIntegrationTest.java class where this fails looks like this:
public class BasicAPIUsageIntegrationTest {
private static final ZAPHelper ZAP_HELPER = new ZAPHelper();
private static ClientApi zapClientApi = null;
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Before BasicAPIUsageIntegrationTest");
zapClientApi = ZAP_HELPER.startZAP(true); //this is the line which gives error
}
And the ZAPHelper.java class which is called above is the source of the error which actually calls the system.getProperty("zap.port") as follows:
public class ZAPHelper {
public ClientApi startZAP(boolean asDaemon) throws Exception {
if (zapProcess != null) {
stopZAPProcess();
}
zapProcess =
BOOTSTRAP_HELPER.startZAP(
new String[] {
// "-Xdebug",
// "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
},
new ZAPStartOptions(
asDaemon,
null,
Integer.valueOf(System.getProperty("zap.port")), //THIS IS THE LINE WHICH FAILS
homePath,
true));
How do i resolve this issue??
I have tried all the solutions mentioned in this post:
How to set system property using gradle?
and,