Bael 1854 (#4954)
* Fix a division method mistake * Maven integration testing * Move Maven integration tests to the maven module * Remove Maven integration tests in the old module
This commit is contained in:
committed by
Predrag Maric
parent
955e78a306
commit
c467a4e7d6
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RestITCase {
|
||||
@Test
|
||||
public void whenSendingGet_thenMessageIsReturned() throws IOException {
|
||||
String url = "http://localhost:8999";
|
||||
URLConnection connection = new URL(url).openConnection();
|
||||
try (InputStream response = connection.getInputStream();
|
||||
Scanner scanner = new Scanner(response)) {
|
||||
String responseBody = scanner.nextLine();
|
||||
assertEquals("Welcome to Baeldung!", responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
public class EndpointConfig extends ResourceConfig {
|
||||
public EndpointConfig() {
|
||||
register(RestEndpoint.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/")
|
||||
public class RestEndpoint {
|
||||
@GET
|
||||
public String hello() {
|
||||
return "Welcome to Baeldung!";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
<servlet>
|
||||
<servlet-name>rest-servlet</servlet-name>
|
||||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>javax.ws.rs.Application</param-name>
|
||||
<param-value>com.baeldung.maven.it.EndpointConfig</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>rest-servlet</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
public interface Integration {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RestIT {
|
||||
@Test
|
||||
public void whenSendingGet_thenMessageIsReturned() throws IOException {
|
||||
String url = "http://localhost:8999";
|
||||
URLConnection connection = new URL(url).openConnection();
|
||||
try (InputStream response = connection.getInputStream();
|
||||
Scanner scanner = new Scanner(response)) {
|
||||
String responseBody = scanner.nextLine();
|
||||
assertEquals("Welcome to Baeldung!", responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RestIntegrationTest {
|
||||
@Test
|
||||
public void whenSendingGet_thenMessageIsReturned() throws IOException {
|
||||
String url = "http://localhost:8999";
|
||||
URLConnection connection = new URL(url).openConnection();
|
||||
try (InputStream response = connection.getInputStream();
|
||||
Scanner scanner = new Scanner(response)) {
|
||||
String responseBody = scanner.nextLine();
|
||||
assertEquals("Welcome to Baeldung!", responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.maven.it;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Category(Integration.class)
|
||||
public class RestJUnitTest {
|
||||
@Test
|
||||
public void whenSendingGet_thenMessageIsReturned() throws IOException {
|
||||
String url = "http://localhost:8999";
|
||||
URLConnection connection = new URL(url).openConnection();
|
||||
try (InputStream response = connection.getInputStream();
|
||||
Scanner scanner = new Scanner(response)) {
|
||||
String responseBody = scanner.nextLine();
|
||||
assertEquals("Welcome to Baeldung!", responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user