I have a junit test suite, that i need to run with several different properties, so that i can have only 1 test suite, but run it several times but with different data on it.
I can make the test suite read the properties from a properties file, that i can change with an environment variable, matching that with the filename of the properties file:
$ export OPERATOR=myoper
and in my java code:
String operator = System.getenv("OPERATOR");
//Reading properties file in Java example
Properties props = new Properties();
//String propertiesFile = "src/test/resources/data" + operator + ".properties";
FileInputStream fis = new FileInputStream("src/test/resources/data" + operator + ".properties");
//loading properites from properties file
props.load(fis);
But I cannot seem to find a way to iterate for all the properties files i could have, so, if i have say, 10 different properties files, that the test suite get executed that many times with all the different set of properties on the files.
I'm using maven and junit4 to run the suites, with the command:
mvn test -Dtest=TestSuite#testCase
I'll be launching the command from a Jenkins Job.
Thanks in advance!
Well after a little research i came up with the following command:
$ export OPERATOR=dataWeb*
$ for f in src/test/resources/$OPERATOR ; do export OPERATOR=$(basename "$f" | cut -d. -f1) && mvn test -Dtest=$TESTSUITE#$TESTCASE -q ; done
Which takes the environment variable of the operator, that is taken by the test suite to select the corresponding properties file, iterating in as many files exists in the directory with that pattern.
Hope it helps other people in the same situation. Maybe it's a better way to achieve this with the Junit + Maven + Jenkins combo that i'm not aware of.
Related
Im have a producer and consumer java code and Im trying to upgrade it to connect with the Kafka which is secured with SSL. I'm in a situation that the ssl related passwords should be given only via environmental variables.
So is it possible to directly refer to the values refered by Environmental variables in the KafkaProducer.properties and KafkaConsumer.properties files
For Example:
I declare an environmental variable in linux system SSL_KEY_PASSWORD=password
And inside the KafkaProducer/Consumer properties, I declare as,
''' ssl.key.password=${SSL_KEY_PASSWORD} '''
Sample KAFKA Consumer/Producer property file config may look like,
# For SSL
security.protocol=SSL
ssl.truststore.location=/var/private/ssl/client.truststore.jks
ssl.truststore.password=${TRUSTSTORE_PASS_ENV_VARIABLE}
# For SSL auth
ssl.keystore.location=/var/private/ssl/client.keystore.jks
ssl.keystore.password=${KEYSTORE_PASS_ENV_VARIABLE}
ssl.key.password=${KEY_PASS_ENV_VARIABLE}
No, they cannot.
Unclear how you are using the files or Kafka clients. If from the shell commands, you should create a bash wrapper around the command you're running that uses sed or other templating scripts that generates the files before running the final command.
If you are actually writing Java code, then build the Properties from the environment there, and not using files.
Don't think properties file values are interpolated but probably you can test it once. Alternatively you can also remove these lines from property file and do it from code something like below...
final Properties properties = new Properties();
final FileInputStream input = new FileInputStream(yourExistingFile);
properties.load(input);
properties.put("ssl.key.password",System.getenv("SSL_KEY_PASSWORD"));//this is additional property
Trying to do the swagger OAuth configuration in the latest version of Micronaut, as per the micronuat documentation
https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html#enableendpoints
swagger-ui.oauth2RedirectUrl
swagger-ui.oauth2.clientId
swagger-ui.oauth2.clientSecret
swagger-ui.oauth2.realm
swagger-ui.oauth2.appName
swagger-ui.oauth2.scopeSeparator
swagger-ui.oauth2.scopes
swagger-ui.oauth2.additionalQueryStringParams
swagger-ui.oauth2.useBasicAuthenticationWithAccessCodeGrant
swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant
When setting any of those properties, Micronaut will generate not only a swagger-ui/index.html file, but also a swagger-ui/oauth2-redirect.html one
I can see it has created the file oauth2-redirect.html with below code
tasks.withType(JavaCompile).all {
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=swagger-ui.enabled=true,swagger-ui.theme=flattop,swagger-ui.oauth2RedirectUrl=http://localhost:8080/swagger-ui/oauth2-redirect.html,swagger-ui.oauth2.clientId=myClientId,swagger-ui.oauth2.scopes=openid,swagger-ui.oauth2.usePkceWithAuthorizationCodeGrant=true'
}
For the oauth2.clientId, oauth2RedirectUrl and oauth2.clientSecret these values differs for each environment PROD, TEST, DEV, UAT. By setting the value like above code it is hard to configure for each enviroment. Is there any better way to do this?
In my project it was solved by creating different property files for each env and steering the compilation with parameters
tasks.withType(JavaCompile) {
String openapiPropertyFile = 'openapi/openapi-dev.properties'
if(project.hasProperty("openapiPropertyFile")){
openapiPropertyFile = project.property('openapiPropertyFile')
}
options.fork = true
options.forkOptions.jvmArgs << "-Dmicronaut.openapi.config.file=$openapiPropertyFile"
}
and then you build it like this
$ sh ./gradlew clean jib -PopenapiPropertyFile=openapi/openapi-uat.properties -PimageSuffix=-uat
Although I'd like to know how to do this post compilation because in my case it forces creation of separate docker images where I'd like to have one and mount those properties afterwards.
i want to run my test script written in Java+Selenium+TestNG in HP ALM. I created Vapi-XP test and batch file which run my test. But if test failed it will report a pass. How to uploading test result?
mycommand = "C:\PSelenium\RunVapi.bat"
TDOutput.Print "Starting " & mycommand
result=run(mycommand,0,true)
TDOutput.Print "Test ended with " & result
You might want to check Agiletestware Bumblebee integration platform which can help you to automate exporting results of Java+Selenium+TestNG tests into HP ALM. Check out this and this also.
Disclaimer: I'm developer of Bumblebee
You have 2 Global Objects in the scope of a VAPI-XP Test: CurrentRun, CurrentTest. They correspond to the Run and Test interfaces respectively. Setting the Status property on Both Objects should be the way.
The below code works fine when I start project with play start
object LogFile {
implicit val formats = DefaultFormats
private var fileInput = new FileInputStream("./conf/log4j.properties");
private val properties = new Properties
properties.load(fileInput);
def test(head: String, data: String) {
System.setProperty("my.log", "scala.txt")
PropertyConfigurator.configure(properties)
val log = Logger.getLogger(head)
log.error(data)
}
}
but when I am using sudo /home/ubuntu/play/play dist
and run that I got:
[error] play - Cannot invoke the action, eventually got an error:
java.io.FileNotFoundException: ./conf/log4j.properties (No such file or directory)
What am I doing wrong?
I am using Scala 2.10 with play framework 2.2
You're missing the Log4j Properties file
./conf/log4j.properties
You're probably missing the file:
/home/ubuntu/project/conf/log4j.properties
sudo command changes the user that you are executing as. So the new user possibly has different environment variables.
note: project is application name.
Also, you're using a relative path ./conf/log4j.properties, the root of which will be resolved at runtime based on the home directory that you are executing in.
Possible solutions:
1) Don't use a relative path, rather use an absolute path
2) Change the home directory in the profile of the user that you are executing
your application as ( root user?)
3) Copy the missing file to the directory where your application is looking for the file
I have a maven project which will generate a JAR file, if you build it as Maven Install.
Inside this project, I have a code like this -
public class GameBot extends GameController {
public int botNumber = 1
Static String botName = "Bot1";
...// Rest of the code..
}
I want to create around 150 JAR files from this project with incremented botNumbers. For example - JAR File 1 should contain botNumber = 1 and botName = Bot1
JAR file 2 should contain botNumber = 2 and BotName = Bot2 .. So on till 150.
I used to build each of these manually and now it looks cumbersome to build each time this way. Because, if I make any small change in the code, I have to build all 150 Files again.
Does any one have some suggestions as in Can I automate the process and get all 150 JAR in a folder built for me?
Thanks.
Why dont you externalize the botNumber to a property file and using shell script or batch file create the property file and build the maven project.
Java Code
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("/bottest.properties"));
botNumber = Integer.parseInt(properties.getProperty("botnumber"));
botName = "Bot"+botNumber;
Shell Script
#!/bin/sh
mvn clean;
for i in {1..5}
do
echo "botnumber=$i" > ./src/main/resources/bottest.properties;
mvn install -Dmaven.test.skip;
cp target/bottest-1.0-SNAPSHOT.jar target/bootest$i.jar
done
Batch File
echo off
call mvn clean
for /l %%x in (1, 1, 5) do (
echo botnumber=%%x > .\src\main\resources\bottest.properties
call mvn install -Dmaven.test.skip
copy target\bottest-1.0-SNAPSHOT.jar target\bootest%%x.jar
)
The above example is for 5 times.