File tree Expand file tree Collapse file tree
integration-test/java/com/baeldung/maven/it
java/com/baeldung/maven/it
test/java/com/baeldung/maven/it Expand file tree Collapse file tree Load diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import org .junit .Test ;
4+
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
7+ import java .net .URL ;
8+ import java .net .URLConnection ;
9+ import java .util .Scanner ;
10+
11+ import static org .junit .Assert .assertEquals ;
12+
13+ public class RestITCase {
14+ @ Test
15+ public void whenSendingGet_thenMessageIsReturned () throws IOException {
16+ String url = "http://localhost:8999" ;
17+ URLConnection connection = new URL (url ).openConnection ();
18+ try (InputStream response = connection .getInputStream ();
19+ Scanner scanner = new Scanner (response )) {
20+ String responseBody = scanner .nextLine ();
21+ assertEquals ("Welcome to Baeldung!" , responseBody );
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import org .glassfish .jersey .server .ResourceConfig ;
4+
5+ public class EndpointConfig extends ResourceConfig {
6+ public EndpointConfig () {
7+ register (RestEndpoint .class );
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import javax .ws .rs .GET ;
4+ import javax .ws .rs .Path ;
5+
6+ @ Path ("/" )
7+ public class RestEndpoint {
8+ @ GET
9+ public String hello () {
10+ return "Welcome to Baeldung!" ;
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ <web-app xmlns =" http://xmlns.jcp.org/xml/ns/javaee"
2+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : schemaLocation =" http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
4+ version =" 3.1" >
5+ <servlet >
6+ <servlet-name >rest-servlet</servlet-name >
7+ <servlet-class >org.glassfish.jersey.servlet.ServletContainer</servlet-class >
8+ <init-param >
9+ <param-name >javax.ws.rs.Application</param-name >
10+ <param-value >com.baeldung.maven.it.EndpointConfig</param-value >
11+ </init-param >
12+ </servlet >
13+ <servlet-mapping >
14+ <servlet-name >rest-servlet</servlet-name >
15+ <url-pattern >/*</url-pattern >
16+ </servlet-mapping >
17+ </web-app >
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ public interface Integration {
4+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import org .junit .Test ;
4+
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
7+ import java .net .URL ;
8+ import java .net .URLConnection ;
9+ import java .util .Scanner ;
10+
11+ import static org .junit .Assert .assertEquals ;
12+
13+ public class RestIT {
14+ @ Test
15+ public void whenSendingGet_thenMessageIsReturned () throws IOException {
16+ String url = "http://localhost:8999" ;
17+ URLConnection connection = new URL (url ).openConnection ();
18+ try (InputStream response = connection .getInputStream ();
19+ Scanner scanner = new Scanner (response )) {
20+ String responseBody = scanner .nextLine ();
21+ assertEquals ("Welcome to Baeldung!" , responseBody );
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import org .junit .Test ;
4+
5+ import java .io .IOException ;
6+ import java .io .InputStream ;
7+ import java .net .URL ;
8+ import java .net .URLConnection ;
9+ import java .util .Scanner ;
10+
11+ import static org .junit .Assert .assertEquals ;
12+
13+ public class RestIntegrationTest {
14+ @ Test
15+ public void whenSendingGet_thenMessageIsReturned () throws IOException {
16+ String url = "http://localhost:8999" ;
17+ URLConnection connection = new URL (url ).openConnection ();
18+ try (InputStream response = connection .getInputStream ();
19+ Scanner scanner = new Scanner (response )) {
20+ String responseBody = scanner .nextLine ();
21+ assertEquals ("Welcome to Baeldung!" , responseBody );
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maven .it ;
2+
3+ import org .junit .Test ;
4+ import org .junit .experimental .categories .Category ;
5+
6+ import java .io .IOException ;
7+ import java .io .InputStream ;
8+ import java .net .URL ;
9+ import java .net .URLConnection ;
10+ import java .util .Scanner ;
11+
12+ import static org .junit .Assert .assertEquals ;
13+
14+ @ Category (Integration .class )
15+ public class RestJUnitTest {
16+ @ Test
17+ public void whenSendingGet_thenMessageIsReturned () throws IOException {
18+ String url = "http://localhost:8999" ;
19+ URLConnection connection = new URL (url ).openConnection ();
20+ try (InputStream response = connection .getInputStream ();
21+ Scanner scanner = new Scanner (response )) {
22+ String responseBody = scanner .nextLine ();
23+ assertEquals ("Welcome to Baeldung!" , responseBody );
24+ }
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments