Forum Discussion

ancm's avatar
ancm
Occasional Contributor
6 years ago
Solved

Update definition with active environment

I am trying to update interface definition of my soap services with this script  :    import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests import stati...
  • ancm's avatar
    ancm
    6 years ago

    I managed to do what i want with the following code :

     

    import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
    import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests
    import com.eviware.soapui.model.ModelItem
    import com.eviware.soapui.impl.wsdl.WsdlRequest
    import com.eviware.soapui.model.iface.Request
    import com.eviware.soapui.impl.wsdl.WsdlInterface
    import com.eviware.soapui.model.iface.Operation
    import com.eviware.soapui.impl.wsdl.WsdlOperation
    import  com.eviware.soapui.impl.wsdl.actions.*
    
    def project = testRunner.testCase.testSuite.project
    def ifaceList = project.getInterfaceList()
    
    //Mise a jour de toutes les interfaces
    ifaceList.each{
    	iface->
    	//Recuperation de l'url du wsdl utilise pour la création du service
    	def oldWsdlUrl = iface.definition
    	//Récupération du nom du service SOAP
    	def serviceName = iface.getName()
    	//Debut de la MAJ de la definition du service
    	log.info "Debut mise a jour du wsdl avec l'ancienne addresse : " + oldWsdlUrl 
    	//recuperation du nouveau endpoint du service
    	String newEnpointUrl = context.expand(project.getActiveEnvironment().getSoapServiceByName(serviceName).getEndpoint().getConfig().getStringValue());
    	//Extraire domain du nouveau endpoint
    	int slashslash = newEnpointUrl.indexOf("//") + 2;
    	String newDomain = newEnpointUrl.substring(slashslash,newEnpointUrl.indexOf('/', slashslash));
    	//Remplacer le domain du wsdl par le nouveau correspondant à l'environnement
    	slashslash = oldWsdlUrl.indexOf("//") + 2;
    	String newWsdlUrl = oldWsdlUrl.substring(0,slashslash) + newDomain + oldWsdlUrl.substring(oldWsdlUrl.indexOf('/', slashslash));
    	//Mise a jour
    	iface.updateDefinition( newWsdlUrl, false)
    	//on force le renomage original
    	iface.setName(serviceName)
    	List<ModelItem> updated = new ArrayList<ModelItem>()
    	updated.addAll(recreateRequests(iface, true, false, true, false))
    	log.info "Fin de la mise a jour du wsdl  avec la nouvelle addresse  : " + newWsdlUrl
    }

     

     

    Thanks to @Nastya_Khovrina