ComputerSpecific クラスの機能は、テストをどこで実行しているかを判別することです。
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* ComputerSpecific クラスの機能は、テストが実行されるホストの名前を判別し、
* ホスト名と IP アドレスをメッセージとしてテスト・ログに出力して、
* ホスト名に基づいてさまざまな文字列を戻すことです。
*/
/**
* @作成者 IBM カスタム・コード・サンプル
*/
public class ComputerSpecific implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* no-arg コンストラクターを使用してこのインスタンスを作成する。
*/
public ComputerSpecific() {
}
public String exec(ITestExecutionServices tes, String[] args) {
String hostName = "Unknown";
String hostAddress = "Unknown";
try {
hostName = InetAddress.getLocalHost().getHostName();
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
tes.getTestLogManager().reportMessage(
"Not able to obtain host information");
return null;
}
tes.getTestLogManager().reportMessage("The hostname is " + hostName +
"; IP address is " + hostAddress);
if (hostName.equals("host-1234"))
return "Special";
else
return "Normal";
}
}