11package com .baeldung .server ;
22
3- import java . io . IOException ;
4-
3+ import com . baeldung . server . model . Employee ;
4+ import com . fasterxml . jackson . databind . ObjectMapper ;
55import org .apache .http .HttpResponse ;
66import org .apache .http .HttpStatus ;
7- import org .apache .http .client .ClientProtocolException ;
87import org .apache .http .client .methods .HttpGet ;
98import org .apache .http .client .methods .HttpPost ;
109import org .apache .http .client .methods .HttpUriRequest ;
1110import org .apache .http .entity .StringEntity ;
1211import org .apache .http .impl .client .HttpClientBuilder ;
1312import org .junit .Test ;
1413
15- import com .baeldung .server .model .Employee ;
16- import com .fasterxml .jackson .databind .ObjectMapper ;
14+ import java .io .IOException ;
1715
1816public class JerseyApiLiveTest {
1917
2018 private static final String SERVICE_URL = "http://localhost:8082/jersey-api/resources/employees" ;
2119
2220 @ Test
23- public void givenGetAllEmployees_whenCorrectRequest_thenResponseCodeSuccess () throws ClientProtocolException , IOException {
21+ public void givenGetAllEmployees_whenCorrectRequest_thenResponseCodeSuccess () throws IOException {
2422 final HttpUriRequest request = new HttpGet (SERVICE_URL );
2523
2624 final HttpResponse httpResponse = HttpClientBuilder .create ().build ().execute (request );
@@ -29,7 +27,7 @@ public void givenGetAllEmployees_whenCorrectRequest_thenResponseCodeSuccess() th
2927 }
3028
3129 @ Test
32- public void givenGetEmployee_whenEmployeeExists_thenResponseCodeSuccess () throws ClientProtocolException , IOException {
30+ public void givenGetEmployee_whenEmployeeExists_thenResponseCodeSuccess () throws IOException {
3331 final HttpUriRequest request = new HttpGet (SERVICE_URL + "/1" );
3432
3533 final HttpResponse httpResponse = HttpClientBuilder .create ().build ().execute (request );
@@ -38,7 +36,7 @@ public void givenGetEmployee_whenEmployeeExists_thenResponseCodeSuccess() throws
3836 }
3937
4038 @ Test
41- public void givenGetEmployee_whenEmployeeDoesNotExist_thenResponseCodeNotFound () throws ClientProtocolException , IOException {
39+ public void givenGetEmployee_whenEmployeeDoesNotExist_thenResponseCodeNotFound () throws IOException {
4240 final HttpUriRequest request = new HttpGet (SERVICE_URL + "/1000" );
4341
4442 final HttpResponse httpResponse = HttpClientBuilder .create ().build ().execute (request );
@@ -47,7 +45,7 @@ public void givenGetEmployee_whenEmployeeDoesNotExist_thenResponseCodeNotFound()
4745 }
4846
4947 @ Test
50- public void givenGetEmployee_whenJsonRequested_thenCorrectDataRetrieved () throws ClientProtocolException , IOException {
48+ public void givenGetEmployee_whenJsonRequested_thenCorrectDataRetrieved () throws IOException {
5149 final HttpUriRequest request = new HttpGet (SERVICE_URL + "/1" );
5250
5351 request .setHeader ("Accept" , "application/json" );
@@ -59,7 +57,7 @@ public void givenGetEmployee_whenJsonRequested_thenCorrectDataRetrieved() throws
5957 }
6058
6159 @ Test
62- public void givenAddEmployee_whenJsonRequestSent_thenResponseCodeCreated () throws ClientProtocolException , IOException {
60+ public void givenAddEmployee_whenJsonRequestSent_thenResponseCodeCreated () throws IOException {
6361 final HttpPost request = new HttpPost (SERVICE_URL );
6462
6563 Employee emp = new Employee (5 , "Johny" );
@@ -74,7 +72,7 @@ public void givenAddEmployee_whenJsonRequestSent_thenResponseCodeCreated() throw
7472 }
7573
7674 @ Test
77- public void givenAddEmployee_whenRequestForExistingObjectSent_thenResponseCodeConflict () throws ClientProtocolException , IOException {
75+ public void givenAddEmployee_whenRequestForExistingObjectSent_thenResponseCodeConflict () throws IOException {
7876 final HttpPost request = new HttpPost (SERVICE_URL );
7977
8078 Employee emp = new Employee (1 , "Johny" );
0 commit comments