Forum Discussion

casp8's avatar
casp8
Occasional Contributor
7 years ago
Solved

Adding a keystore/groovy script to single request through Java

Hi all, 

I have a testsituation in which I want to have requests with and without the use of a keystore in a single testcase. I'm generating soapuiprojects through the Java package com.eviware.soapui.

 

I found a way to add a certificate in java using this code;

SoapUI.getSettings().setString(SSLSettings.KEYSTORE,
"pathToKeystore");
SoapUI.getSettings().setString(SSLSettings.KEYSTORE_PASSWORD,
"xxxxxxx");
SoapUI.getSettings().setBoolean(SSLSettings.CLIENT_AUTHENTICATION,
true);
SoapUI.saveSettings();

However, this adds the credentials to the whole project (logically), and therefore isn't usefull to me.

 

In the ReadyAPI user interface I can add credentials to a single request (with a request property), and a way to do this using the library would help me most!

 

An other option would be adding a groovy script to a testcase, and perform all the teststeps with a certificate after running this script. I did this in the user interface with this groovy script;

import com.eviware.soapui.settings.SSLSettings
import com.eviware.soapui.SoapUI

SoapUI.settings.setString( SSLSettings.KEYSTORE, "pathToKeyStore" )
SoapUI.settings.setString( SSLSettings.KEYSTORE_PASSWORD, "xxxxxxx" )

 

However, I do not know how to add this groovy script to a testcase using the package in Java Code. So any help with this would be appriaciated as well!

 

Thanks in advance!

 

  • Try writing the above code inside TestCase level TearDown script. Hope it helps.