Created On:  25-05-2010

Problem:

When using SilkCentral Test Manager 2009 Web Services to import JUnit Test Definitions to a testplan; how can I set the 'Inherited' property for the newly imported Test Definition nodes?

Resolution:

The following example Java code used to import test definitions via SilkCentral's Web Services:
 
@Test
  public void testCustomerIssue() throws RemoteException {
    TestPlanningNode nodeAlsJUnitTest = getWebService().getNode(getSessionId(), "34");
                PropertyValue[] jUnitTestProps = nodeAlsJUnitTest.getPropertyValues();
                ArrayList newProps = new ArrayList();
 
                String testspezifikationen[] = new String[]{"a", "lot", "of", "Testspezifikationen", "(approx. 600")};
 
                TestPlanningNode node;
 
                                for(int i=0; i
                                                node = new TestPlanningNode();
 
                                for(int j=0; j
                                                if(jUnitTestProps.getPropertyID().equals("_junit_ClassFile")){
jUnitTestProps.setValue("StartSkripte_Akzeptanz.ZVD." + testspezifikationen);
                                                                }
                                                }
                                node.setPropertyValues(jUnitTestProps);
                                node.setName(testspezifikationen);
                                node.setDescription(testspezifikationen+ " - per Webservice created.");
                                node.setKind(3);
                                mPlanningService.addNode(mSessionID, 4012, node, true);
 
 
In this scenario we want the imported test JUnit test definitions to inherit the '_junit_Classfile' property from the parent test folder or definition, rather than setting this property during the import, as in the sample script above. This can be achieved by modifying the code so as to not explicitly set the property during the import; which means the value will be inherited from the parent node:
 
@Test
  public void testCustomerIssue() throws RemoteException {
    TestPlanningNode nodeAlsJUnitTest = getWebService().getNode(getSessionId(), "34");
    PropertyValue[] jUnitTestProps = nodeAlsJUnitTest.getPropertyValues();
    ArrayList newProps = new ArrayList();
 
    String testspezifikationen[] = new String[]{"a", "lot", "of", "Testspezifikationen", "(approx. 600"};
 
    TestPlanningNode node;
    for(int i=0; i
      node = new TestPlanningNode();
 
      for(int j=0; j
        if(jUnitTestProps.getPropertyID().equals("_junit_ClassFile")){
          jUnitTestProps.setValue("StartSkripte_Akzeptanz.ZVD." + testspezifikationen);
        }
if(! jUnitTestProps.getPropertyID().equals("_junit_ClassPath")) { // don't set class path in new element (will then be inherited automatically when set on a parent element)
                 newProps.add(jUnitTestProps);
        }
      }
      node.setPropertyValues((PropertyValue[]) newProps.toArray(new PropertyValue[newProps.size()]));
      node.setName(testspezifikationen);
      node.setDescription(testspezifikationen+ " - per Webservice created.");
      node.setKind(3);
      getWebService().addNode(getSessionId(), 32, node, true);
    }
  }