0811-3 对webservice执行自动化测试

0811-3 对webservice执行自动化测试

 

import org.codehaus.xfire.*;
import org.codehaus.xfire.service.*;
import org.codehaus.xfire.service.binding.*;
import org.codehaus.xfire.client.*;

import java.io.*;
import java.lang.reflect.Method;

public class TestHelloWorld1 {
	public static void main() {
		Service service=new ObjectServiceFactory().create(IHelloWorldService.class);
		XFireProxyFactory factory=new XFireProxyFactory(XFireFactory.newInstance().getXFire());
		String helloWorldURL ="http://localhost:8080/HelloWorld/services/HelloWorldService";
		
		try {
			BufferedReader br = new BufferedReader(new FileReader("c:/jtest/8/0812"));
			String line;
			String[] lArray,paraArray;
			String funcName,paras,ret,m,p,t,tusr;
			while((line=br.readLine())!=null){
				lArray=line.split("\\t");
				
				funcName=lArray[0];//获得函数名称
				paras=lArray[1];   //获得参数
				ret=lArray[2];     //获得返回值
				
				
				paraArray=paras.split("\\|");
				m=paraArray[0];
				int start,end;
				//求m
				start=m.indexOf("m=")+2;
				end=m.indexOf("|");
				m=m.substring(start,end);
				//求p
				start=m.indexOf("p=")+2;
				end=m.indexOf("|",end+1);
				p=m.substring(start,end);
				//求t
				start=m.indexOf("t=")+2;
				end=m.indexOf("|",end+1);
				t=p=m.substring(start,end);
				//求tusr
				start=m.indexOf("tusr=")+2;
				tusr=m.substring(start);
				
				//函数调用
				IHelloWorldService srvc = (IHelloWorldService)factory.create(service, helloWorldURL);
				Class c=srvc.getClass();
				Method method=c.getMethod(funcName, new Class[]{String.class,String.class,String.class,String.class});
				String rett=(String)method.invoke(m,p,t,tusr);
				if(ret==rett){
					System.out.println("pass");
					
				}else{
					System.out.println("fail");
				}
			}

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

}

 

 

参考:http://hi.baidu.com/dobodo/blog/item/47e0da82cc9b5eaa0df4d26e.html

 

你可能感兴趣的:(C++,c,webservice,C#,Blog)