Forum Discussion

RazorShharp's avatar
RazorShharp
New Contributor
9 years ago

Dynamic global properties

I have a service that is secured using a signature and timestamp in the header values.  The values timeout after a minute.  I've created global properties and I reference them in the tests.  I've created a batch job that updates the SoapUI properties file (soapui-settings.xml) with new values (basically copies the entire properties file line by line and updates these values when those lines comes up during the copy).  This is working great--except I need to restart SoapUI for it to use the updated values.  Very annoying to have to shut down SoapUI, run my batch app and restart SoapUI every minute!

 

Any idea how I can automatically re-read the global properties values while SoapUI is running?

 

P.S. I am open to other solutions.  I don't like copying the properties file--scares me that I'll corrupt it someday.  Is there a better way?  I'm thinking some syntax to tell SoapUI to read the global property value from a file at run-time or something?  . . . maybe like this:

 

${file://someDir/currentSignature.txt}

 

Thanks in advance!

5 Replies

  • Ton646's avatar
    Ton646
    Occasional Contributor

    I hope I understand your problem correctly and you want to essentially have a global property that changes each time you use it?

     

    Using a timestamp for example, this is what I have for a property 'epoch'

     

    ${=Calendar c = Calendar.getInstance(); c.add(Calendar.DATE,0); c.getTimeInMillis()}

     

    When I use ${#Project#epoch} as input in a call, each time I invoke that call it will have a new value.

     

    Here is another example (not a property but set on the input for a particular api call) where I use a timestamp in a call with an additional identifier (the test name with spaces removed)

     

    ${=import java.text.SimpleDateFormat ;  "MYPREFEX-" + context.getTestCase().getLabel().replaceAll("\\s+","") + "-" + new SimpleDateFormat("YYYYMMdd-HHmmssSSS").format(new Date()) }

     

    Hopefully that is helpful to you.

     

    • RazorShharp's avatar
      RazorShharp
      New Contributor

      Right.  The value might not change every time but it isn't known when it will change--so updating it with the current value every time is what I am looking for.

       

      Is that Java code you are using?  So, generically, I can do this: ${java code}?  If so, I think we're on the right track.  It takes several lines of code to generate the values I need though--and there are references to external JAR files.  Can I create a JAR file with a main method that returns what I need in System.out and then put my JAR (and other external JARs) somewhere that SoapUI can find them . . . then do something like this:

       

      ${mainClassInJarFile}

       

      Or is there some other way I can execute some external process to get the values?

      • Ton646's avatar
        Ton646
        Occasional Contributor

        Ah, got it now - something like an access token that changes every x seconds... I'm afraid that is beyond what I have tried so far, sorry. However, it would seem that you should be able to code that in a similar way? I used several lines in the epoch parameter for example.     

         

        Just because I cant leave well enough alone - this might be another solution, albeit rather hacky and probably fraught with risks... but if you had an external file that held the current value to use, you might be able to use a system command to echo it and use the input?  Just a quick example that would insert the contents of tokenfile on my (Linux) system...

         

        ${="cat tokenfile".execute().text}

         

        Edit - on second reading, that might be exactly what you need if you had an external script that would generate the value in stdout?

         

        (As you can tell - I am less of a developer than a tester ... )