Glen Mazza wrote:
Hello,

I'm trying to create a JUnit test case for my infamous "DoubleIt" web
service (http://www.jroller.com/gmazza/date/20080417), and would like to:

(1) create the endpoint, (2) make several test SOAP requests against it, and (3) close the endpoint.
My test case is below--I want to make sure I'm doing this correctly (it
seems to work--and correctly returns errors when I intentionally place wrong
values in for the expected results), in particular the setUp() and
tearDown()--is it really as simple as I have it below?

Your tests are just making normal Java method calls to the impl object, they're not going through the web service stack at all. If you really want to test it properly you'd need to create a client proxy talking to the same address as the Endpoint.publish, and make your test calls through that proxy rather than straight to the impl.

Ian

Thanks,
Glen


package com.mycompany.webservice.service;

import static org.junit.Assert.assertEquals;
import java.math.BigInteger;
import javax.xml.ws.Endpoint;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mycompany.webservice.service.DoubleItPortTypeImpl;
import org.example.doubleit.DoubleItPortType;

public class DoubleItPortTypeImplTest {

    protected static Endpoint ep;
    protected static DoubleItPortTypeImpl port;
@BeforeClass
    public static void setUp() throws Exception {
        port = new DoubleItPortTypeImpl();
        String address =
"http://localhost:8080/cxf/services/DoubleItPortType";;
        Endpoint ep = Endpoint.publish(address, port);
    }

    @AfterClass
    public static void tearDown() {
        try {
            ep.stop();
        } catch (Throwable t) {
            System.out.println("Error thrown: " + t.getMessage());
        }
    }

    @Test
public void doubleItWorksForPositiveNumbers() { BigInteger resp = port.doubleIt(new BigInteger("10")); assertEquals("Double-It not doubling positive numbers", resp.toString(), "20");
    }

    @Test
    public void doubleItWorksForNegativeNumbers() {
        BigInteger resp = port.doubleIt(new BigInteger("-10"));
assertEquals("Double-It not doubling negative numbers", resp.toString(), "-20"); } }




--
Ian Roberts               | Department of Computer Science
[EMAIL PROTECTED]  | University of Sheffield, UK

Reply via email to