17 years ago
Adding External Java CLASS to soapUI
Hey,
Iam fairly new to soapUI. Previously I was working with SOATest and Ive this JAVA CLASS integrated with SOATest which we use for testing. I know need to integrate that class with soapUI and I am confused how would I go about that, because Iam not sure if the same api's and Util's exist in soapUI or not. Here's the code which I need to manipulate to integrate it with soapUI
import com.parasoft.api.MethodToolContext;
import java.io.*;
import soaptest.api.SOAPUtil;
public class Profile_parameters
{
public Profile_parameters()
{
userName = "soatest";
userPassword = "Userpwd@";
phoneNumber = "613";
phonePassword = "phonepassword";
emailDomain = "@ngun.com";
groupName = "soa group";
nickname = "soa nickname";
buddyGroupName = "soa buddy group";
parentUserGroup = "soa parent group";
}
public Object Profile_parameters_launchscript(String bla, MethodToolContext context)
{
try
{
File f = context.getAbsolutePathFile("counter.txt");
System.out.println(f.getAbsolutePath());
BufferedReader in = new BufferedReader(new FileReader(f));
String str;
while((str = in.readLine()) != null)
{
if(str.compareTo("9") == 0)
{
System.out.println(str);
updateCounter(str, f);
in.close();
}
if(str.compareTo("99") == 0)
{
System.out.println(str);
updateCounter(str, f);
in.close();
}
System.out.println(str);
updateCounter(str, f);
}
in.close();
}
catch(IOException e)
{
System.out.println("Unable to read from counter.txt");
e.printStackTrace();
}
String s1 = getUser();
System.out.println("user: " + s1);
String s2 = getEmail();
System.out.println("email: " + s2);
String s3 = getGroupName();
System.out.println("group: " + s3);
String s4 = getNickname();
System.out.println("nick: " + s4);
String s5 = getUserPassword();
System.out.println("userPassword: " + s5);
String s6 = getPhoneNumber();
System.out.println("phoneNumber: " + s6);
String s7 = getPhonePassword();
System.out.println("PhonePassword: " + s7);
String s8 = getBuddyGroupName();
System.out.println("BuddyGroup: " + s8);
String s9 = getParentUserGroup();
System.out.println("ParentGroup: " + s9);
String values[] = {
s1, s2, s3, s4, s5, s6, s7, s8, s9
};
Object temp = SOAPUtil.getXMLFromString(values);
return temp;
}
Now, the areas in RED are the one I need help with. I have an idea about the last one though. I think we can use XMLHolder.getXMLObject() but Iam not sure but the big issue is I cant find anything in parallel with MethodToolContext in soapUI.
and the second class which actually take this MethodToolContext as an input is :
private void updateCounter(String c, File f)
{
counter = (new Integer(c)).intValue();
int tmp = counter + 1;
String tmps = (new Integer(tmp)).toString();
System.out.println("new counter value is: " + tmps);
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(f));
out.write(tmps);
out.close();
}
catch(IOException e)
{
System.out.println("Unable to write to counter.txt");
e.printStackTrace();
}
}
Iam fairly new to soapUI. Previously I was working with SOATest and Ive this JAVA CLASS integrated with SOATest which we use for testing. I know need to integrate that class with soapUI and I am confused how would I go about that, because Iam not sure if the same api's and Util's exist in soapUI or not. Here's the code which I need to manipulate to integrate it with soapUI
import com.parasoft.api.MethodToolContext;
import java.io.*;
import soaptest.api.SOAPUtil;
public class Profile_parameters
{
public Profile_parameters()
{
userName = "soatest";
userPassword = "Userpwd@";
phoneNumber = "613";
phonePassword = "phonepassword";
emailDomain = "@ngun.com";
groupName = "soa group";
nickname = "soa nickname";
buddyGroupName = "soa buddy group";
parentUserGroup = "soa parent group";
}
public Object Profile_parameters_launchscript(String bla, MethodToolContext context)
{
try
{
File f = context.getAbsolutePathFile("counter.txt");
System.out.println(f.getAbsolutePath());
BufferedReader in = new BufferedReader(new FileReader(f));
String str;
while((str = in.readLine()) != null)
{
if(str.compareTo("9") == 0)
{
System.out.println(str);
updateCounter(str, f);
in.close();
}
if(str.compareTo("99") == 0)
{
System.out.println(str);
updateCounter(str, f);
in.close();
}
System.out.println(str);
updateCounter(str, f);
}
in.close();
}
catch(IOException e)
{
System.out.println("Unable to read from counter.txt");
e.printStackTrace();
}
String s1 = getUser();
System.out.println("user: " + s1);
String s2 = getEmail();
System.out.println("email: " + s2);
String s3 = getGroupName();
System.out.println("group: " + s3);
String s4 = getNickname();
System.out.println("nick: " + s4);
String s5 = getUserPassword();
System.out.println("userPassword: " + s5);
String s6 = getPhoneNumber();
System.out.println("phoneNumber: " + s6);
String s7 = getPhonePassword();
System.out.println("PhonePassword: " + s7);
String s8 = getBuddyGroupName();
System.out.println("BuddyGroup: " + s8);
String s9 = getParentUserGroup();
System.out.println("ParentGroup: " + s9);
String values[] = {
s1, s2, s3, s4, s5, s6, s7, s8, s9
};
Object temp = SOAPUtil.getXMLFromString(values);
return temp;
}
Now, the areas in RED are the one I need help with. I have an idea about the last one though. I think we can use XMLHolder.getXMLObject() but Iam not sure but the big issue is I cant find anything in parallel with MethodToolContext in soapUI.
and the second class which actually take this MethodToolContext as an input is :
private void updateCounter(String c, File f)
{
counter = (new Integer(c)).intValue();
int tmp = counter + 1;
String tmps = (new Integer(tmp)).toString();
System.out.println("new counter value is: " + tmps);
try
{
BufferedWriter out = new BufferedWriter(new FileWriter(f));
out.write(tmps);
out.close();
}
catch(IOException e)
{
System.out.println("Unable to write to counter.txt");
e.printStackTrace();
}
}