Forum Discussion

HaroldR's avatar
HaroldR
Contributor
7 years ago

Problem in iterating inside WsdlInterface Table

Hi,

I have linked my Readi Api jar file whithin my Eclipse IDE. Then, I'm able to write code use any native features from my ReadyApi which has been already implemented.

Today, I'm struggle with the importWsdl Method which come from WsdlImporter class.

The issue appears just after adding several wsdl to my project. Apparently, each time a wdsl is added to my project, index 0 of WsdlInterface table is systematically replaced by last wsdl.
Therefore, I am able to add several interfaces inside project but I am not able to use it to do some stuff with.
The only wsdl where we can iterate is placed at index 0, so in consequences, it is obvious that we could only use API features on last imported wsdl. For instance, if I try to iterate on an integer greater than 0, I will catch an ArrayIndexOutOfBoundsException. Well, I definitely don't understand what I did wrong in my code, and why I can not use other value of WsdlInterface table except 0.

Here I share my code for a better understanding :

package soapUiTreatments;

import com.eviware.soapui.SoapUI;
import com.eviware.soapui.StandaloneSoapUICore;
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.WsdlRequest;
import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;
import com.eviware.soapui.model.testsuite.TestSuite;
import java.util.*;
import java.io.File;

public class CreateSoapUiProject {
    
	public static void main(String[] args) {

        try {
        	String virtuLabel = "fr-virtu-label";
        	String projectVersion = "v1";
        	String projectLabel = "-soapui-project";
        	String extension = ".xml";
        	int countOperationsInInterface = 0;
        	int countTestSuiteInProject = 0;

        	File projectFile =new File(virtuLabel + projectLabel + extension + projectVersion);
        	
        	SoapUI.setSoapUICore(new StandaloneSoapUICore(true));      	
        	WsdlProject project = new WsdlProject(virtuLabel); //define project label

        	/*-----------------Define WSDL Urls-------------------------*/
        	ArrayList<String> allWsdlUrls = new ArrayList<String>();
        	String IWsConsultationCISSOAP11Binding = "http://eip-mediator-wsint-tstenv-sedc.applications.services.axa-tech.intraxa/ws/fr-cis-infocontrat-v1-vs?wsdl";
        	String EndpointRecupererSDM = "http://eip-med-tst-sesd.applications.services.axa-tech.intraxa/ws/fr-fca-sdm-cst-v2-vs?wsdl";
        	String IdentityCstServiceEndpoint = "http://eip-mediator-wsint-tstenv-sedc.applications.services.axa-tech.intraxa/ws/fr-acon-cst-enduseridentity-v1-vs?wsdl";
        	String BasicHttpBinding_IRoutageService = "http://eip-med-tst-sesd.applications.services.axa-tech.intraxa/ws/fr-bow-mng-soclederoutage-v1-vs?wsdl";
        	
        	/*-----------------Import WSDL Interfaces in Project-------------------------*/
        	WsdlInterface[] wsdls;
        	wsdls = WsdlImporter.importWsdl(project, IWsConsultationCISSOAP11Binding);
        	wsdls = WsdlImporter.importWsdl(project, IdentityCstServiceEndpoint);
        	wsdls = WsdlImporter.importWsdl(project, EndpointRecupererSDM);
        	wsdls = WsdlImporter.importWsdl(project, BasicHttpBinding_IRoutageService);
        	System.out.println("----------INTERFACE COUNT------------------"+project.getInterfaceCount());
        	System.out.println("---------------------------------------WSDL COUNT--------------------" + wsdls.length); //To get the number of  wsdl interfaces always return 1, why?
        	for (int wsdlCount = 0; wsdlCount < project.getInterfaceCount(); wsdlCount++){
        		WsdlInterface wsdl = wsdls[wsdlCount]; //HERE IS MY CAUGHT EXCEPTION ArrayIndexOutOfBoundsException
        		String soapVersion = wsdl.getSoapVersion().toString();
        		List<WsdlOperation> operations = wsdl.getAllOperations();
        		while (operations.size() > countOperationsInInterface){
        			wsdl.getProject().addNewTestSuite(operations.get(countOperationsInInterface)
        					.getName()+"TestSuite");
        			countOperationsInInterface++;
        		}
        		List<WsdlTestSuite> testSuiteList = wsdl.getProject().getTestSuiteList();
        		while (testSuiteList.size() > countTestSuiteInProject){
        			wsdl.getProject().getTestSuiteAt(countTestSuiteInProject)
        					.addNewTestCase(operations.get(countTestSuiteInProject)
        					.getName()+"-TestCase-"+"1");
        			countTestSuiteInProject++;
        		}
        		int countBindingOperations = wsdl.getOperationCount();
        		String reqContent="";
        		String result="";
        		for(int index = 0; index < countBindingOperations; index++){
        			WsdlOperation operationAtIndex = wsdl.getOperationAt(index);
        			String operationName = operationAtIndex.getName();
        			reqContent = operationAtIndex.createRequest(true);
        			WsdlRequest req = operationAtIndex.addNewRequest("Req_" + soapVersion
        					+ "_" + operationName);
        			req.setRequestContent(reqContent);
        		}	
        	}
        	project.saveIn(projectFile);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

My aim is to create a single testsuite and a testcase for each binding operation found after loading an interface. As all operations name, contained in all interfaces, are different, there should not occur any problem with this automatic process.

Regarding my issue, this automatic process is done only one time for the last imported wsdl whereas what I want is doing these for all imported wsdls.

I know it's a bit complicated and I am not so clear explaing the issue, but if you have any understanding problems, I could may be express that in a better way.


Thanks for your help

Harold

 

No RepliesBe the first to reply