Junit注記方式Webサービスのテスト

1634 ワード

import static org.junit.Assert.*;  
  
import java.net.MalformedURLException;  
import java.net.URL;  
import java.util.HashMap;  
import java.util.Map;  
  
  
  
import org.codehaus.xfire.client.Client;  
  
import org.junit.BeforeClass;  
import org.junit.Test;  
  
public class  Sumtest {  
    //Web   
    private final static String WS_URL="http://localhost:8080/WS/services/SumService?wsdl";  
    // Client  
    private static Client client=null;  
    // Map  
    private static Map mothods= null;  
      
    @BeforeClass// @Before   
    /** 
     *   
     */  
    public static void setUp() throws Exception{  
        createWSClient();  
        createTestMethods();  
    }  
    //Web   
    private final static String WS_MOTHODS_SUM = null;  
    /** 
     *  Map 
     */  
    private static void createTestMethods() {  
        mothods = new HashMap();  
        mothods.put(WS_MOTHODS_SUM, "sum");  
    }  
    /** 
     *  client 
     * @throws Exception 
     * @throws MalformedURLException 
     */  
    private static void createWSClient() throws Exception,  
            MalformedURLException {  
        client = new Client(new URL(WS_URL));  
    }  
      
    @Test  
    /** 
     *   
     */  
   public void testSum() throws Exception{  
  
        Object[] obj = client.invoke(mothods.get(WS_MOTHODS_SUM),new Object[]{5});  
        Integer result = (Integer) obj[0];  
        assertEquals(" ", new Integer(10),result);  
        System.out.println(" :result="+result);  
    }