Created On:  02 November 2011

Problem:

When copying a Test Definition using the Web Services, any inherited parameters are recreated on the new Test Definition rather than being inherited from the parent node:

Orginal Test Definition:


Copied Test Definition:



How can I ensure that when copying Test Definitions via the Web Services, that parameters are inherited rather than recreated on the new Test Definition?

Resolution:

When a Test Definition is retrieved via the Web Services it will include information regarding the parameters that are currently associated with it, however there is no indication as to whether the parameter was inherited or not. The parameter information is held within an array of PropertyValue objects for a particular TestPlanningNode object retrieved via the tmplanning web service.

To ensure that parameters remain inherited, we must remove any "parameter PropertyValue" objects from the TestPlanningNodes property values. The following code demonstrates a simplistic approach of performing the said operation:

public static void copyNodeWithoutParameters(){
     try{

          SccsystemSoapBindingStub sccBind = (SccsystemSoapBindingStub) new SystemServiceServiceLocator().getsccsystem(new URL("http://bel-robertm7:19120/Services1.0/services/sccsystem?wsdl"));
          long lSession = sccBind.logonUser("admin", "admin");

          TmplanningSoapBindingStub plnBind = (TmplanningSoapBindingStub) new PlanningServiceServiceLocator().gettmplanning(new URL("http://bel-robertm7:19120/Services1.0/services/tmplanning?wsdl"));
          plnBind.setCurrentProject(lSession, "0"
);

          //Get the TestDefinition to copy and its PropertyValues
          TestPlanningNode test = plnBind.getNode(lSession, "112"
);
          PropertyValue[] props = test.getPropertyValues();

          //Create a Testplanning node that will contain the information to copy
          TestPlanningNode copyTo = new TestPlanningNode();
          ArrayList copyProps = new ArrayList();

          for(int i=0; i<>length; i++){

               //If the PropertValue is not a paramater
               if(!props.getPropertyID().contains("_parameter_")){

                    //Add the PropertyValue to the PropertValue's to be copied
                    copyProps.add(props);
               }
          }

          PropertyValue[] copy = new PropertyValue[copyProps.size()];
          copyProps.toArray(copy);

          //Set the PropertyValue's for the new TestDefinition minus the paramaters
          copyTo.setPropertyValues(copy);

          //Set the type to TestDefinition
          copyTo.setKind(3);

          //Add the copied node to the Testplan
          plnBind.addNode(lSession, 111, copyTo,
false);
     }
     catch(Exception e){
          e.printStackTrace();
     }
}