1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.as.quickstarts.wshelloworld.HelloWorldService;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30
31
32
33
34
35
36 public class ClientTest {
37
38
39
40 private static final String APP_NAME = "jboss-helloworld-ws";
41
42
43
44 private static final String WSDL_PATH = "HelloWorldService?wsdl";
45
46
47
48
49 private static final String SERVER_URL_PROPERTY = "serverUrl";
50
51
52
53 private static final String DEFAULT_SERVER_URL = "http://localhost:8080/";
54
55 private static URL deploymentUrl;
56
57 private HelloWorldService client;
58
59 @BeforeClass
60 public static void beforeClass() throws MalformedURLException
61 {
62 String deploymentUrl = System.getProperty(SERVER_URL_PROPERTY);
63
64
65 if (deploymentUrl == null || deploymentUrl.isEmpty()) {
66 deploymentUrl = DEFAULT_SERVER_URL;
67 }
68
69
70 if (!deploymentUrl.endsWith("/")) {
71 deploymentUrl += "/";
72 }
73
74
75 if (!deploymentUrl.matches(".*" + APP_NAME + ".*"))
76 {
77 deploymentUrl += APP_NAME + "/";
78 }
79
80
81 deploymentUrl += WSDL_PATH;
82
83 System.out.println("WSDL Deployment URL: " + deploymentUrl);
84
85
86 ClientTest.deploymentUrl = new URL(deploymentUrl);
87 }
88
89 @Before
90 public void setup() {
91 try {
92 client = new Client(new URL(deploymentUrl, WSDL_PATH));
93 } catch (MalformedURLException e) {
94 e.printStackTrace();
95 }
96 }
97
98 @Test
99 public void testHello() {
100 System.out.println("[Client] Requesting the WebService to say Hello.");
101
102
103 final String response = client.sayHello();
104 assertEquals(response, "Hello World!");
105
106 System.out.println("[WebService] " + response);
107
108 }
109
110 @Test
111 public void testHelloName() {
112 System.out.println("[Client] Requesting the WebService to say Hello to John.");
113
114
115 final String response = client.sayHelloToName("John");
116 assertEquals(response, "Hello John!");
117
118 System.out.println("[WebService] " + response);
119 }
120
121 @Test
122 public void testHelloNames() {
123 System.out.println("[Client] Requesting the WebService to say Hello to John, Mary and Mark.");
124
125
126 final List<String> names = new ArrayList<String>();
127 names.add("John");
128 names.add("Mary");
129 names.add("Mark");
130
131
132 final String response = client.sayHelloToNames(names);
133 assertEquals(response, "Hello John, Mary & Mark!");
134
135 System.out.println("[WebService] " + response);
136 }
137 }