dynamic load citrus.properties

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

dynamic load citrus.properties

mlybarger
from my citrus-context.xml i want to dynamically load a property file to use for expansion within the citrus-context.xml.

let's say i have:
src/citrus/resources/SETUPONE/
     citrus.properties
     global-variables.properties
and
src/citrus/resources/SETUPTWO/
     citrus.properties
     global-variables.properties

In citrus-context.xml, we have :
<context:property-placeholder location="classpath:/${environment.SETUP}/citrus.properties" />

where SETUP is passed as in put on command line as -DSETUP=SETUPONE or -DSETUP=SEUTPTWO

this requires the -D to always be passed in via the command line.  this method is being used to control hostnames and userid/creds that are used in different environments at we test against.  

is there a better way from citrus-context.xml to dynamically load property files based on (optional) input parameter?  I don't want to always have to specify -DSETUP, but I'm not sure how to make a default.

any help would be most appreciate!
Thanks,
-mark-
Reply | Threaded
Open this post in threaded view
|

Re: dynamic load citrus.properties

Christoph Deppisch
Administrator
Spring XML bean definition profiles should do the trick for you

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-definition-profiles-xml

Let me know if this is working out well for you
Reply | Threaded
Open this post in threaded view
|

Re: dynamic load citrus.properties

mlybarger
this worked for us. thanks for the tip!
Reply | Threaded
Open this post in threaded view
|

Re: dynamic load citrus.properties

antonela destito
This post was updated on .
In reply to this post by Christoph Deppisch
Hi!
I'm running a test with profile beans; but it doesn't work with Autowired variables, they are set as null.
I show you a piece of my files:

citrus-context.xml

<beans
       [...]>
  <beans profile="xmlJobFeed">
       
        <citrus:namespace-context>
            <citrus:namespace prefix="xmlJobFeed"/>
        </citrus:namespace-context>
        <context:property-placeholder location="classpath:citrus.properties"/>

      <citrus-docker:client id="dockerClient2"
                              url="<a href="http://localhost:2375&quot;">http://localhost:2375"
                              version="1.12"
                              username=""
                              password=""
                              email=""
                              cert-path=""
                              server-address="https://index.docker.io/v1/"
                              config-path="/var/integrations/integrations-cell-configs/localhost/xmljobfeed/"/>

    </beans>
</beans>

@ActiveProfiles(value = "xmlJobFeed")
@Test
public class SampleJavaIT extends TestNGCitrusTestDesigner {
    @Autowired
    HttpServer todoListServer2;
    @Autowired
    DockerClient dockerClient2; ----> this is set as null
[....]
   @CitrusTest
    @Parameters("context")
    public void xmlJobFeedPmi_test(@Optional @CitrusResource TestContext context) throws InterruptedException {
        imageName = context.getVariable("imageName"); ----> this are in correct value
        backupPath = context.getVariable("backupPath");
[....]
}

This happens when I want to run a test like this:

@ActiveProfiles(value = "xmlJobFeed")
@Test
public class RunAll extends TestNGCitrusTestDesigner {
    @CitrusTest
    @Parameters("context")
    public void SampleJavaITR(@Optional @CitrusResource com.consol.citrus.context.TestContext context) throws InterruptedException  {
        SampleJavaIT s = new SampleJavaIT();
        s.xmlJobFeedPmi_test(context);
    }
}

I do that RunALL function with the idea of running two tests that are in separate files (SampleJavaIT and SampleJavaIT2) and with two profile context (xmlJobFeed and empi9).

Thanks in advanced.
Reply | Threaded
Open this post in threaded view
|

Re: dynamic load citrus.properties

mlybarger
this is OT. you might want to start a new thread.