How can a user set values for an attribute of type "Normal" using web services?

0 Likes

Problem:

How can a user set values for an attribute of type "Normal" using web services?

Resolution:

Using the SilkCentral Test Manager GUI, setting a value for attributes would be done in Test Manager | Settings | Attributes tab (see below):

Using Web Services you can also set values for an attribute of type "Normal". Please see example below that logs in as admin | admin and sets a Value ("IE 6") to the attribute "Browser"

Note: Attributes and their options must be defined by using the GUI before they can be used via web services

............................................

package com.borland.testmanager.democlient.samples;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import com.borland.testmanager.stubs.sccsystem.SystemService;
import com.borland.testmanager.stubs.sccsystem.SystemServiceServiceLocator;
import com.borland.testmanager.stubs.tmplanning.PlanningService;
import com.borland.testmanager.stubs.tmplanning.PlanningServiceServiceLocator;
import com.borland.testmanager.stubs.tmplanning.tm.PropertyValue;
import com.borland.testmanager.stubs.tmplanning.tm.TestPlanningNode;

public class SetBrowserAttributeNormalOption {

String host = "localhost";
int port = 19120;
String user = "admin";
String pwd = "admin";
int nodeId = 3; // see demo project: test definition "Correct Login data" (ID=3)
String browserOption = "IE 6";

/**
* @param args
*/
public static void main(String[] args) {

SetBrowserAttributeNormalOption optionsSetter = new SetBrowserAttributeNormalOption();

optionsSetter.processArguments(args);

try {
long sessionId = optionsSetter.login();


optionsSetter.setBrowserAttributeOption(sessionId);

TestPlanningNode node = optionsSetter.retrieveNode(sessionId);

boolean noAttributesFound = ReadAttributeOptions.printAttributes(node);

if (noAttributesFound) {
System.out.printf("no attributes found for node "%s" (ID=%d)%n", node.getName(), node.getId());
}

} catch (Exception e) {
e.printStackTrace();
}
}

private void setBrowserAttributeOption(long sessionId) throws MalformedURLException, ServiceException, RemoteException {
PlanningService planningService = new PlanningServiceServiceLocator().gettmplanning(new URL("http", host, port, "/services/tmplanning"));
planningService.updateProperties(sessionId, makeBrowserOption());
}

private PropertyValue[] makeBrowserOption() {
return new PropertyValue[] {
new PropertyValue() {
{
setPropertyTypeID("_attribute_");
setPropertyID ("_attribute_Browser");
setName ("Browser");
setValue (browserOption);
setNodeID (Integer.toString(nodeId));
setType (11); // attribute type NORMAL (see javadoc of PropertyMetaInfo)
}
}
};
}

private TestPlanningNode retrieveNode(long sessionId) throws ServiceException, MalformedURLException, RemoteException {
PlanningService planningService = new PlanningServiceServiceLocator().gettmplanning(new URL("http", host, port, "/services/tmplanning"));
TestPlanningNode node = planningService.getNode(sessionId, Integer.toString(nodeId));
return node;
}

private long login() throws ServiceException, MalformedURLException, RemoteException {
SystemService sccService = new SystemServiceServiceLocator().getsccsystem(new URL("http", host, port, "/services/sccsystem"));
long sessionId = sccService.logonUser(user, pwd);
return sessionId;
}

private void processArguments(String[] args) {
for (int i = 0; i
switch (i) {
case 0:
if ("help".equals(args)) {
System.out.println("valid arguments: host port user password nodeID browserOption");
System.exit(0);
} else {
host = args;
}
break;
case 1:
port = Integer.parseInt(args);
break;
case 2:
user = args;
break;
case 3:
pwd = args;
case 4:
nodeId = Integer.parseInt(args);
break;
case 5:
browserOption = args;
}
}
}

}

SetBrowserAttributeNormalOption.java
Old KB# 30288
Comment List
Related
Recommended