View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.wshelloworld;
18  
19  import static org.junit.Assert.*;
20  
21  import java.net.MalformedURLException;
22  import java.net.URL;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.jboss.arquillian.container.test.api.Deployment;
27  import org.jboss.arquillian.junit.Arquillian;
28  import org.jboss.arquillian.test.api.ArquillianResource;
29  import org.jboss.as.quickstarts.wshelloworld.HelloWorldService;
30  import org.jboss.shrinkwrap.api.ShrinkWrap;
31  import org.jboss.shrinkwrap.api.spec.WebArchive;
32  import org.junit.Before;
33  import org.junit.Test;
34  import org.junit.runner.RunWith;
35  
36  /**
37   * Simple set of tests for the HelloWorld Web Service to demonstrate accessing the web service using a client
38   * 
39   * @author lnewson@redhat.com
40   */
41  @RunWith(Arquillian.class)
42  public class ClientArqTest {
43      /**
44       * The name of the WAR Archive that will be used by Arquillian to deploy the application.
45       */
46      private static final String APP_NAME = "jboss-helloworld-ws";
47      /**
48       * The path of the WSDL endpoint in relation to the deployed web application.
49       */
50      private static final String WSDL_PATH = "HelloWorldService?wsdl";
51  
52      @ArquillianResource
53      private URL deploymentUrl;
54  
55      private HelloWorldService client;
56  
57      @Deployment(testable = false)
58      public static WebArchive createDeployment() {
59          return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war").addPackage(HelloWorldService.class.getPackage());
60      }
61  
62      @Before
63      public void setup() {
64          try {
65              client = new Client(new URL(deploymentUrl, WSDL_PATH));
66          } catch (MalformedURLException e) {
67              e.printStackTrace();
68          }
69      }
70  
71      @Test
72      public void testHello() {
73          System.out.println("[Client] Requesting the WebService to say Hello.");
74  
75          // Get a response from the WebService
76          final String response = client.sayHello();
77          assertEquals(response, "Hello World!");
78  
79          System.out.println("[WebService] " + response);
80  
81      }
82  
83      @Test
84      public void testHelloName() {
85          System.out.println("[Client] Requesting the WebService to say Hello to John.");
86  
87          // Get a response from the WebService
88          final String response = client.sayHelloToName("John");
89          assertEquals(response, "Hello John!");
90  
91          System.out.println("[WebService] " + response);
92      }
93  
94      @Test
95      public void testHelloNames() {
96          System.out.println("[Client] Requesting the WebService to say Hello to John, Mary and Mark.");
97  
98          // Create the array of names for the WebService to say hello to.
99          final List<String> names = new ArrayList<String>();
100         names.add("John");
101         names.add("Mary");
102         names.add("Mark");
103 
104         // Get a response from the WebService
105         final String response = client.sayHelloToNames(names);
106         assertEquals(response, "Hello John, Mary & Mark!");
107 
108         System.out.println("[WebService] " + response);
109     }
110 }