package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* @author unknown
*/
public class HTMLEncode implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public HTMLEncode() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
String _wresult = args[0];
String decodedString = _wresult.replaceAll("&", "&");
decodedString = decodedString.replaceAll(""", "\"");
decodedString = decodedString.replaceAll("<", "<");
decodedString = decodedString.replaceAll(">", ">");
//tes.setValue("wresult",ITestExecutionServices.STORAGE_USER,decodedString);
return decodedString;
}
}
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* @author unknown
*/
public class UnescapeHex implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public UnescapeHex() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
String strInput = args[0];
String strHex;
String strHexValue;
int intDecimal;
char charDec;
while (strInput.indexOf("\\x") >= 0) {
strHex = strInput.substring(strInput.indexOf("\\x"), strInput.indexOf("\\x")+4);
strHexValue = strHex.replace("\\x", "");
intDecimal = Integer.parseInt(strHexValue, 16);
charDec = (char)intDecimal;
strInput = strInput.replace(strHex, String.valueOf(charDec));
}
return strInput;
}
}
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.execution.http.cookie.IHTTPVirtualUserInfo;
import com.ibm.rational.test.lt.execution.http.cookie.ICookie;
import com.ibm.rational.test.lt.kernel.IDataArea;
import java.text.ParseException;
/**
* @author unknown
*/
public class ModifyCookie implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public ModifyCookie() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
String cookieName = args[0];
String cookieValue = args[1];
String newCookie;
IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER);
IHTTPVirtualUserInfo httpInfo =
(IHTTPVirtualUserInfo)dataArea.get(IHTTPVirtualUserInfo.KEY);
ICookie serverSuppliedCookie[] = httpInfo.getCookieCache().getCookieByName(cookieName);
if (serverSuppliedCookie.length != 1)
{
if (serverSuppliedCookie.length == 0)
tes.getTestLogManager().reportMessage("Cannot find existing Cookie named " + cookieName);
else
tes.getTestLogManager().reportMessage("Found more than 1 cookie named " + cookieName);
return "Problem";
}
newCookie = cookieName + "=" + cookieValue + ";Path=/;Domain=" +
serverSuppliedCookie[0].getDomain();
try {
httpInfo.getCookieCache().setCookie(newCookie);
} catch (ParseException e) {
tes.getTestLogManager().reportMessage("ERROR: Can't parse Cookie string: " + newCookie);
}
return "Success";
}
}
package customcode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* @author unknown
*/
public class GetCurrentDate implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public GetCurrentDate() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String strDate = df.format(new Date());
return strDate;
}
}
package customcode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
/**
* @author unknown
*/
public class GetCampaignEndDate implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public GetCampaignEndDate() {
}
/**
* For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
* Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
*/
public String exec(ITestExecutionServices tes, String[] args) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 1);
String strDate = df.format(cal.getTime());
return strDate;
}
}



沒有留言:
張貼留言