Forum Discussion

zen_paul's avatar
zen_paul
Occasional Contributor
8 years ago

Schema Compliance Assertion setting Definition URL with Groovy

 

 

 

 

We have code which sets up our assertions for some of our regression tests like

 

assertion = tStep.addAssertion("XPath Match")
assertion.setName("matchAllExceptTimestamp")
assertion.path = assertionStatement
assertion.setAllowWildcards(true)
assertion.expectedContent = contentsFromFile

 

Now we want to create a new Schema Compliance assertion, 

where we will dynamically change the Definition URL to keep in line with the endpoint (which is  

assertion = tStep.addAssertion("Schema Compliance")
assertion.setName("Schema Compliance for " + endPointOrg)  // where endPointOrg is specific to the endpoint

assertion.??????? = myDynamicDefinitionURL

 

I know that the assertion can be changed using something like ${#project#myDynamicUrl}, but that means I have to change each test step, as opposed to just changing the groovy code to create the assertion as required.

 

So is there an assertion.?????? method I can use to set the value for the Definition URL to be used for that, how can it be done programatically in groovy.

 

So far I have trawled the community to find the magic incantation, but to no avail, (including trying to find it in the apidocs) so at last I will turn to you all and hope someone can help. 

 

Your help in this always appreciated  

  • zen_paul, in case you need to add your own URL of the WSDL, you can do it with the following code:

     

    SchemaComplianceAssertion sca = step.addAssertion('Schema Compliance')
    sca.setConfiguration(org.apache.xmlbeans.XmlObject.Factory.parse('<definition>http://myServiceURL?WSDL</definition>'))

    Karel

     

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    zen_paul, in case you need to add your own URL of the WSDL, you can do it with the following code:

     

    SchemaComplianceAssertion sca = step.addAssertion('Schema Compliance')
    sca.setConfiguration(org.apache.xmlbeans.XmlObject.Factory.parse('<definition>http://myServiceURL?WSDL</definition>'))

    Karel

     

    • zen_paul's avatar
      zen_paul
      Occasional Contributor

      Thanks, worked a treat.

       

      I would never have got that without working for another few days ... (or maybe never)

       

      Cheers

  • zen_paul's avatar
    zen_paul
    Occasional Contributor

    Just thought I'd put the code I got to work in my Groovy, just for completeness.

     

     

    import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SchemaComplianceAssertion.*
    .
    .
    .
    def scAssertName = 'isSchemaCompliantWith' + proj.getPropertyValue("useWsdl")
    def defUrl = 'http://anAddress:1111/'+ proj.getPropertyValue("useWsdl")+'/services/mystuff?wsdl'
    if (!tStep.getAssertionByName(scAssertName))
    	{
    	assertion = tStep.addAssertion("Schema Compliance")
    	assertion.setName(scAssertName)
    	assertion.setConfiguration(org.apache.xmlbeans.XmlObject.Factory.parse('<definition>'+defUrl+'</definition>'))
    	// assertion.setDisabled(true)			
    	}