package jboss.ws;
import static org.junit.Assert.assertEquals;
import javax.xml.ws.Holder;
import jboss.ws.hello.client.AuthHeader;
import jboss.ws.hello.client.Hello;
import jboss.ws.hello.client.HelloService;
import jboss.ws.hello.client.Person;
import jboss.ws.hello.client.SayHello;
import jboss.ws.hello.client.SayHelloResponse;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.junit.Before;
import org.junit.Test;
public class HelloWorldTest {
private Client client = null;;
private Hello port = null;
private HelloService service = null;
@Before
public void setUp() {
service = new HelloService();
port = service.getHelloPort();
client = ClientProxy.getClient(port);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
}
@Test
public void testSayHello() throws Exception {
Person person = new Person();
person.setFirstName("David");
person.setLastName("F");
AuthHeader authHeader = new AuthHeader();
authHeader.setStatus("explicit");
SayHello sayHello = new SayHello();
sayHello.setPerson(person);
Holder<AuthHeader> holder = new Holder<AuthHeader>(authHeader);
Object[] returnedObjects = client.invoke("sayHello", new Object[] {
sayHello, holder });
String expected = "Hello David . F by JBoss 6 WS with CXF implementation.";
String result = ((SayHelloResponse) returnedObjects[0]).getReturn();
assertEquals(expected, result);
System.out.println("status of header returned from hello service : "
+ ((AuthHeader) ((Holder) returnedObjects[2]).value).getStatus());
}
}