|
13 | 13 | */ |
14 | 14 | package com.ibm.watson.developer_cloud.service; |
15 | 15 |
|
16 | | -import static org.mockserver.integration.ClientAndServer.startClientAndServer; |
17 | 16 | import static org.mockserver.model.HttpRequest.request; |
18 | 17 | import static org.mockserver.model.HttpResponse.response; |
19 | 18 |
|
20 | 19 | import java.util.HashMap; |
21 | 20 | import java.util.Map; |
22 | | -import java.util.logging.Level; |
23 | | -import java.util.logging.Logger; |
24 | 21 |
|
25 | | -import org.junit.After; |
26 | 22 | import org.junit.Before; |
27 | 23 | import org.junit.Test; |
28 | | -import org.mockserver.integration.ClientAndServer; |
29 | 24 | import org.mockserver.model.Header; |
30 | 25 | import org.mockserver.model.HttpRequest; |
31 | 26 |
|
32 | | -import com.ibm.watson.developer_cloud.WatsonServiceTest; |
| 27 | +import com.ibm.watson.developer_cloud.WatsonServiceUnitTest; |
33 | 28 | import com.ibm.watson.developer_cloud.http.HttpHeaders; |
34 | 29 | import com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsights; |
35 | | -import com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsightsTest; |
36 | 30 |
|
37 | 31 | /** |
38 | | - * The Class GenericServiceTest. |
| 32 | + * Generic Service Test. |
39 | 33 | */ |
40 | | -public class GenericServiceTest extends WatsonServiceTest { |
41 | | - |
42 | | - /** The Constant GET_PROFILE_PATH. */ |
| 34 | +public class GenericServiceTest extends WatsonServiceUnitTest { |
43 | 35 | private final static String GET_PROFILE_PATH = "/v2/profile"; |
44 | | - |
45 | | - /** The Constant log. */ |
46 | | - private static final Logger log = Logger.getLogger(PersonalityInsightsTest.class.getName()); |
47 | | - |
48 | | - /** The Constant POST. */ |
49 | | - private static final String POST = "POST"; |
50 | | - |
51 | | - /** Mock Server *. */ |
52 | | - private ClientAndServer mockServer; |
53 | | - |
54 | | - /** The sample text. */ |
55 | 36 | private final String sampleText = "this is a test"; |
56 | | - |
57 | | - /** The service. */ |
58 | 37 | private PersonalityInsights service; |
59 | 38 |
|
60 | 39 | /** |
@@ -86,28 +65,13 @@ public void ServiceUnavailableException() { |
86 | 65 | service.getProfile(sampleText); |
87 | 66 | } |
88 | 67 |
|
89 | | - /** |
90 | | - * Start mock server. |
91 | | - */ |
| 68 | + @Override |
92 | 69 | @Before |
93 | | - public void startMockServer() { |
94 | | - try { |
95 | | - mockServer = startClientAndServer(Integer.parseInt(getValidProperty("mock.server.port"))); |
96 | | - service = new PersonalityInsights(); |
97 | | - service.setApiKey(""); |
98 | | - service.setEndPoint("http://" + getValidProperty("mock.server.host") + ":" |
99 | | - + getValidProperty("mock.server.port")); |
100 | | - } catch (final NumberFormatException e) { |
101 | | - log.log(Level.SEVERE, "Error mocking the service", e); |
102 | | - } |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Stop mock server. |
107 | | - */ |
108 | | - @After |
109 | | - public void stopMockServer() { |
110 | | - mockServer.stop(); |
| 70 | + public void setUp() throws Exception { |
| 71 | + super.setUp(); |
| 72 | + service = new PersonalityInsights(); |
| 73 | + service.setApiKey(""); |
| 74 | + service.setEndPoint(MOCK_SERVER_URL); |
111 | 75 | } |
112 | 76 |
|
113 | 77 | /** |
@@ -221,7 +185,7 @@ public void testDefaultHeadersAreSet() { |
221 | 185 | service.setDefaultHeaders(headers); |
222 | 186 | mockAPICall(); |
223 | 187 | service.getProfile(sampleText); |
224 | | - mockServer.verify(new HttpRequest().withMethod("POST").withHeader(expectedHeader1) |
| 188 | + mockServer.verify(new HttpRequest().withMethod(POST).withHeader(expectedHeader1) |
225 | 189 | .withHeader(expectedHeader2)); |
226 | 190 | } |
227 | 191 | } |
0 commit comments