Forum Discussion

DMc-Cabe's avatar
DMc-Cabe
Occasional Contributor
10 years ago

Variable endpoint support?

Hi There

I am trying to create a test suite which will allow passing of variable endpoint values from jenkins/maven

I have created a global property called ServiceEndpoint ${#Project#ServiceEndpoint} I am running into a number of issues when implementing this

1. I am unable to pass a value using the -Dmaven.soapui.test.serviceEndpoint=http://new.endpoint.com switch when running from the command line and or Jenkins. The value set in the xml file does not get overridden.

2. When creating Groovy assertions I am unable to pass the value of the variable endpoint to the holder.namespaces value

import com.eviware.soapui.support.XmlHolder

def serviceEndpoint = context.expand( '${#Project#ServiceEndpoint}' )

def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["ns1"] = "$serviceEndpoint/aopui-service/v1/rest/request"

It returns the following "Error org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String"

any suggestions on what I can do to over come these issues please?

7 Replies

  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    bump .... anyone able to shed any light on this issue at all pls?
  • I'd really appreciate it if someone from the support team could take a look at this query ... it's been almost a week
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    1. I am unable to pass a value using the -Dmaven.soapui.test.serviceEndpoint=http://new.endpoint.com switch when running from the command line and or Jenkins. The value set in the xml file does not get overridden.



    You will need to add this to your pom file under configurations with the other soapui settings.

    <projectProperties>
    <value>ServiceEndpoint=Hello World!</value>
    </projectProperties>

    Please see the example here http://www.soapui.org/Test-Automation/maven-2x.html


    2. When creating Groovy assertions I am unable to pass the value of the variable endpoint to the holder.namespaces value

    import com.eviware.soapui.support.XmlHolder

    def serviceEndpoint = context.expand( '${#Project#ServiceEndpoint}' )

    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    holder.namespaces["ns1"] = "$serviceEndpoint/aopui-service/v1/rest/request"

    It returns the following "Error org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String"


    I believe the problem is you are using the $ Groovy special character which is creating a Groovy String when a Java string is expected. You should do:
    holder.namespaces["ns1"] = serviceEndpoint + "/aopui-service/v1/rest/request"



    Regards,
    Marcus
    SmartBear Support
  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    Thank you for the response, that has solved the initial problem of building the namespaces url but when I try to extract the value of the node using :

    def node = holder.getDomNode( "//ns1:Response[1]/ns1:template[1]/ns1:templateId[1]" )

    it returns null - same for

    def node = holder.getNodeValue( "//ns1:Response[1]/ns1:template[1]/ns1:templateId[1]" )

    2. When creating Groovy assertions I am unable to pass the value of the variable endpoint to the holder.namespaces value

    import com.eviware.soapui.support.XmlHolder

    def serviceEndpoint = context.expand( '${#Project#ServiceEndpoint}' )

    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    holder.namespaces["ns1"] = "$serviceEndpoint/aopui-service/v1/rest/request"

    It returns the following "Error org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String"


    I believe the problem is you are using the $ Groovy special character which is creating a Groovy String when a Java string is expected. You should do:
    holder.namespaces["ns1"] = serviceEndpoint + "/aopui-service/v1/rest/request"



    Regards,
    Marcus
    SmartBear Support[/quote]
  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    ok - I have finally managed to remove all hardcoded endpoints from my tests and groovy scripts by using global properties.

    i have created 3 properties in my pom.xml file

    <projectProperties>
    <value>ServiceEndpoint=http://abc.test.com:8080</value>
    <value>assertEndpoint=http://xyz.test.com</value>
    <value>mongoHost=mongodb.test.com</value>
    </projectProperties>

    when I run from cmd line via mvn I try the following :

    mvn test -Dmaven.soapui.test.ServiceEndpoint=http://new.endpoint.com:8888

    but it doesn't seem to override the setting in the pom.xml - is this the correct way to pass these properties from maven?
  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    DMc-Cabe wrote:
    ok - I have finally managed to remove all hardcoded endpoints from my tests and groovy scripts by using global properties.

    i have created 3 properties in my pom.xml file

    <projectProperties>
    <value>ServiceEndpoint=http://abc.test.com:8080</value>
    <value>assertEndpoint=http://xyz.test.com</value>
    <value>mongoHost=mongodb.test.com</value>
    </projectProperties>

    when I run from cmd line via mvn I try the following :

    mvn test -Dmaven.soapui.test.ServiceEndpoint=http://new.endpoint.com:8888

    but it doesn't seem to override the setting in the pom.xml - is this the correct way to pass these properties from maven?


    anyone able to help me out with this problem please?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    mvn test -Dmaven.soapui.test.ServiceEndpoint=http://new.endpoint.com:8888


    I do not believe this will override the property on the command line. The properties are being set in the pom file, if you want to override them in the pom file you will need to create custom maven properties in your pom file and then you can override them on the command line. An example below.

    <project>
    ...
    <properties>
    <service.endpont>http://abc.test.com:8080</service.endpoint>
    </properties>
    ...
    <projectProperties>
    <value>ServiceEndpoint=${service.endpoint}</value>
    ....
    </projectProperties>
    </project>

    To override the property on the command line you would do, mvn test -Dservice.endpoint=http://new.endpoint.com:8888


    Regards,
    Marcus
    SmartBear Support