Forum Discussion

Usha_Kodali's avatar
Usha_Kodali
Frequent Contributor
16 years ago

updating endpoint dynamically

Hi,

I have about 50 webservices in a project. I have various test cases for those webservices.
I want to test the test cases against multiple environment.
Exp: Production,Dev,QA,Integration environments. How to achieve this?

I followed following thread and implemented
http://www.eviware.com/forums/index.php?topic=348.0

wanted to know if there is any other better way? I dont want to change the properties file everytime.
How to update the services before executing the test cases?How can I know if the endpoint the test cases are using is what I want?

7 Replies

  • Hi Usha,

    apart from the solution in the post you mentioned, you could try creating a setup script that somehow checks which endpoints that should be used and sets them accordingly; you could put this in an external component in the script-library, making it easy to re-use between projects.

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • Usha_Kodali's avatar
    Usha_Kodali
    Frequent Contributor
    Hi Ole,

    Can you give me more insight how to achieve this? I never used script-library...
  • Usha, the way the I am accomplishing this is to create a test case, and run it multiple times from command line (in my case from ant), passing in the host name that I want to execute against.
  • alibaba82's avatar
    alibaba82
    Super Contributor
    We basically have a switch statement that is part of the start up groovy script library
    swith (enviorment like prod,qa,etc)
    case prod:
    //setup your wsdl endpoints
    wsld1 = prod.domain.com/service1
    wsld2 = prod.domain.com/service2

    case: QA
    wsdl1 = qa.domain.com/service1
    wsdl2 = qa.domain.com/service2

    if( project.interfaces["wsld1 "] != null )
    project.interfaces["wsld1 "].definition =  context.expand('${#Project#wsld1 }') + '?wsdl';
  • Hi!

    Can't you always use property-expansion in all your endpoints and just update the property they are using?  (instead of removing the actual endpoint..)

    regards!

    /Ole
    eviware.com
  • Usha_Kodali's avatar
    Usha_Kodali
    Frequent Contributor
    Sharing the class for updating the endpoints dynamically

    class DynamicEndpoint{
    def log
    def context
    def envdym
    def project

    DynamicEndpoint(log,context,project){
    this.log = log
    this.context = context
    this.project = project
    }

    def ChangeEndPoint(envdym)
    {
    def filename
    def file
    def props
    def endpoint
    def urldef
    def currentendpoint
    def spliturl
    def jointlist

    log.info("Environment is"+" "+envdym)

    //reading the properties file
    filename = context.expand( '${projectDir}\\endpoint.properties' )
    log.info("Endpoint Properties filepath is:"+" "+filename)

    //creating file handle for reading the contents
    file = new java.io.File( filename )

    // if the file exists,read the file and set the endpoint according to the environment entered and finally close the file
    if( file.exists() )
    {
    FileReader r = null;
    r = new java.io.FileReader( file )
       
        props = new java.util.Properties()
        props.load(r)
     
        endpoint = props.get(envdym)
        log.info("Endpoint tobe changed to is : $endpoint")
       
        //Change the mainEndpoint property value in the Project
      if( endpoint != null && endpoint.trim().length() > 0 )
        {

          project.setPropertyValue( "mainEndpoint", endpoint ) //setting the new endpoint
          log.info( "Successfully Changed mainEndpoint to [" + endpoint + "]" )
        }
    else
    {
    log.info("Endpoint is not set")
    }

    log.info("**********************************************")

    // To update the WSDL's

              for(iface in project.getInterfaceList())
    {   

    //Get the current URL Definition
              urldef = iface.definition;
    log.info("Current URL is:"+urldef)

    //split the urldef to update the endpoint
              spliturl = urldef.split("/active-bpel/")
                log.info("Split URL is"+" "+spliturl.toString())

    //join the endpoint,urldef,biniding
              jointlist = [endpoint,'/active-bpel/',spliturl[1]]
                log.info("Joint List is:"+" "+jointlist);
             
      //create full url definition
      urldef = ""
    jointlist.each {
      urldef += it + ""
    }
    // log.info("Final endpoint is:"+fullString)
    //update definition with new endpoint
    // urldef = fullString   
    log.info("New URL is:"+urldef)     

    //set the binding definition with new endpoint
    iface.definition = urldef

    log.info("Finished updating endpoint of Service:"+" "+iface.getName())
    log.info("************************************************************")
            }

    r.close() //closing the file handle
    }
    else log.info( "Missing [" + filename + "]" )

    }
    }

    call following way in the Load Script section of the Project

    def m = new DynamicEndpoint(log,context,project)
    m. ChangeEndPoint('qa')