2

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,

How to give System property to my test via Gradle

Deev Pal
  • 21
  • 1

1 Answers1

0

I think your problem is when you call

System.setProperty("zap.port", "${project.ext.zapPort}")
System.setProperty("jetty.port", "${project.ext.jettyPort}")

you are setting the properties in the process running the Gradle script, rather than in the test process.

Try replacing those lines with this, using the systemProperty method from Test:

systemProperty("zap.port", "${project.ext.zapPort}")
systemProperty("jetty.port", "${project.ext.jettyPort}")
Simon Jacobs
  • 1,147
  • 7
  • 7
  • This did not work, Gives the same error with the following Stack Trace: **java.lang.NumberFormatException: For input string: "null"** at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.valueOf(Integer.java:983) at org.zaproxy.zap.extension.fioriscanner.internal.ZAPHelper.startZAP(ZAPHelper.java:62) at org.zaproxy.zap.extension.fioriscanner.api.BasicAPIUsageIntegrationTest.setUp(BasicAPIUsageIntegrationTest.java:22) – Deev Pal Jun 20 '23 at 06:03
  • I suggest printing out "${project.ext.zapPort}" before the systemProperty call to ensure it is set correctly. – Simon Jacobs Jun 20 '23 at 19:09
  • Yes I did that and value is set correctly for project.ext.zapPort – Deev Pal Jun 26 '23 at 06:42