Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package jboss.ws;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4.  
  5. import javax.xml.ws.Holder;
  6.  
  7. import jboss.ws.hello.client.AuthHeader;
  8. import jboss.ws.hello.client.Hello;
  9. import jboss.ws.hello.client.HelloService;
  10. import jboss.ws.hello.client.Person;
  11. import jboss.ws.hello.client.SayHello;
  12. import jboss.ws.hello.client.SayHelloResponse;
  13.  
  14. import org.apache.cxf.endpoint.Client;
  15. import org.apache.cxf.frontend.ClientProxy;
  16. import org.apache.cxf.interceptor.LoggingInInterceptor;
  17. import org.apache.cxf.interceptor.LoggingOutInterceptor;
  18. import org.junit.Before;
  19. import org.junit.Test;
  20.  
  21. public class HelloWorldTest {
  22.     private Client client = null;;
  23.     private Hello port = null;
  24.     private HelloService service = null;
  25.  
  26.     @Before
  27.     public void setUp() {
  28.         service = new HelloService();
  29.         port = service.getHelloPort();
  30.         client = ClientProxy.getClient(port);
  31.         client.getInInterceptors().add(new LoggingInInterceptor());
  32.         client.getOutInterceptors().add(new LoggingOutInterceptor());
  33.     }
  34.  
  35.     @Test
  36.     public void testSayHello() throws Exception {
  37.  
  38.         Person person = new Person();
  39.         person.setFirstName("David");
  40.         person.setLastName("F");
  41.         AuthHeader authHeader = new AuthHeader();
  42.         authHeader.setStatus("explicit");
  43.    
  44.         SayHello sayHello = new SayHello();
  45.         sayHello.setPerson(person);
  46.         Holder<AuthHeader> holder = new Holder<AuthHeader>(authHeader);
  47.  
  48.         Object[] returnedObjects = client.invoke("sayHello", new Object[] {
  49.                 sayHello, holder });
  50.  
  51.         String expected = "Hello David . F by JBoss 6 WS with CXF implementation.";
  52.         String result = ((SayHelloResponse) returnedObjects[0]).getReturn();
  53.         assertEquals(expected, result);
  54.  
  55.         System.out.println("status of header returned from hello service : "
  56.                 + ((AuthHeader) ((Holder) returnedObjects[2]).value).getStatus());
  57.     }
  58. }