Orkun
Orkun

Reputation: 7268

System properties in unit tests when run with intellij

I m running a unit test using the intellij runner.

In the main method of the app, we set the keystore to the value:

/home/oozen/workspace/wakeup/src/main/resources/Certif.p12

public void run(String... args){
        System.setProperty("javax.net.ssl.keyStore", vodafoneKeystore);
        System.setProperty("javax.net.ssl.keyStorePassword", vodafoneKeystorePassword);
        logger.info(" **************** WakeUpApp **************** ");
        logger.info("vodafoneKeystore is set to {}", vodafoneKeystore);
    }

This works ok on production. But not on unit tests when I run with intellij.

In the tests, when i log the result of getProperty, i see what we set in the code.

In the beginning of my test method, i can see the value is correctly set:

    logger.info(" ################## KEYSTORE : {}", System.getProperty("javax.net.ssl.keyStore"));

 ################## KEYSTORE : /home/oozen/workspace/wakeup/src/main/resources/Certif.p12

But during the handshake, i see the message: no certificate found resulting in failure in the authentication.

Any ideas as to why?

I know that I can run the test with an arg : ... -Djavax.net.ssl.keyStore=... But i donT want to.. :)

Also, @Thiru shows a way to set it externally, but my aim is to be able to set it from the code and to be able to rely on it in the unit tests.

Thanks in advance

Upvotes: 2

Views: 1996

Answers (1)

Thiru
Thiru

Reputation: 2709

You can accomplish using Path Variables in Preferences.

Follow the steps below:

  • Open Preference -> Path Variables
  • Click the + icon
  • Add the property name and value
  • Click apply

Please refer to the below image

image

Upvotes: 3

Related Questions