* 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:
nguyennamthai 2018-08-18 21:56:15 +07:00 committed by Predrag Maric
parent 955e78a306
commit c467a4e7d6
9 changed files with 437 additions and 145 deletions

View File

@ -1,151 +1,303 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>maven</artifactId> <artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent> <dependencies>
<artifactId>parent-modules</artifactId> <dependency>
<groupId>com.baeldung</groupId> <groupId>org.glassfish.jersey.containers</groupId>
<version>1.0.0-SNAPSHOT</version> <artifactId>jersey-container-servlet-core</artifactId>
</parent> <version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <groupId>org.eclipse.jetty</groupId>
<version>${maven.resources.version}</version> <artifactId>jetty-maven-plugin</artifactId>
<configuration> <version>${jetty.version}</version>
<outputDirectory>output-resources</outputDirectory> <configuration>
<resources> <httpConnector>
<resource> <port>8999</port>
<directory>input-resources</directory> </httpConnector>
<excludes> <stopKey>quit</stopKey>
<exclude>*.png</exclude> <stopPort>9000</stopPort>
</excludes> </configuration>
<filtering>true</filtering> <executions>
</resource> <execution>
</resources> <id>start-jetty</id>
</configuration> <phase>pre-integration-test</phase>
</plugin> <goals>
<plugin> <goal>start</goal>
<artifactId>maven-compiler-plugin</artifactId> </goals>
<version>${maven-compiler-plugin.version}</version> </execution>
<configuration> <execution>
<source>${java.version}</source> <id>stop-jetty</id>
<target>${java.version}</target> <phase>post-integration-test</phase>
<compilerArgs> <goals>
<arg>-Xlint:unchecked</arg> <goal>stop</goal>
</compilerArgs> </goals>
</configuration> </execution>
</plugin> </executions>
<plugin> </plugin>
<artifactId>maven-surefire-plugin</artifactId> <plugin>
<version>${maven-surefire-plugin.version}</version> <artifactId>maven-resources-plugin</artifactId>
<configuration> <version>${maven.resources.version}</version>
<excludes> <configuration>
<exclude>DataTest.java</exclude> <outputDirectory>output-resources</outputDirectory>
</excludes> <resources>
<includes> <resource>
<include>TestFail.java</include> <directory>input-resources</directory>
<include>DataCheck.java</include> <excludes>
</includes> <exclude>*.png</exclude>
<testFailureIgnore>true</testFailureIgnore> </excludes>
</configuration> <filtering>true</filtering>
</plugin> </resource>
<plugin> </resources>
<artifactId>maven-failsafe-plugin</artifactId> </configuration>
<version>${maven.failsafe.version}</version> </plugin>
<executions> <plugin>
<execution> <artifactId>maven-compiler-plugin</artifactId>
<goals> <version>${maven.compiler.version}</version>
<goal>integration-test</goal> <configuration>
<goal>verify</goal> <source>${java.version}</source>
</goals> <target>${java.version}</target>
<configuration> <compilerArgs>
<!-- configuration similar to surefire --> <arg>-Xlint:unchecked</arg>
</configuration> </compilerArgs>
</execution> </configuration>
</executions> </plugin>
</plugin> <plugin>
<plugin> <artifactId>maven-surefire-plugin</artifactId>
<artifactId>maven-verifier-plugin</artifactId> <version>${maven.surefire.version}</version>
<version>${maven.verifier.version}</version> <configuration>
<configuration> <excludes>
<verificationFile>input-resources/verifications.xml</verificationFile> <exclude>DataTest.java</exclude>
</configuration> <exclude>**/*IntegrationTest</exclude>
<executions> </excludes>
<execution> <excludedGroups>com.baeldung.maven.it.Integration</excludedGroups>
<goals> <includes>
<goal>verify</goal> <include>TestFail.java</include>
</goals> <include>DataCheck.java</include>
</execution> </includes>
</executions> <testFailureIgnore>true</testFailureIgnore>
</plugin> </configuration>
<plugin> </plugin>
<artifactId>maven-clean-plugin</artifactId> <plugin>
<version>${maven.clean.version}</version> <artifactId>maven-failsafe-plugin</artifactId>
<configuration> <version>${maven.failsafe.version}</version>
<filesets> <executions>
<fileset> <execution>
<directory>output-resources</directory> <goals>
</fileset> <goal>integration-test</goal>
</filesets> <goal>verify</goal>
</configuration> </goals>
</plugin> <configuration>
<plugin> <!-- configuration similar to surefire -->
<groupId>org.codehaus.mojo</groupId> </configuration>
<artifactId>build-helper-maven-plugin</artifactId> </execution>
<version>${maven.build.helper.version}</version> </executions>
<executions> </plugin>
<execution> <plugin>
<phase>generate-sources</phase> <artifactId>maven-verifier-plugin</artifactId>
<goals> <version>${maven.verifier.version}</version>
<goal>add-source</goal> <configuration>
</goals> <verificationFile>input-resources/verifications.xml</verificationFile>
<configuration> </configuration>
<sources> <executions>
<source>src/main/another-src</source> <execution>
</sources> <goals>
</configuration> <goal>verify</goal>
</execution> </goals>
</executions> </execution>
</plugin> </executions>
</plugins> </plugin>
</build> <plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.version}</version>
<configuration>
<filesets>
<fileset>
<directory>output-resources</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/another-src</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles> <profiles>
<profile> <profile>
<id>default</id> <id>default</id>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven.surefire.version}</version>
<configuration> <configuration>
<excludes> <excludes>
<exclude>DataTest.java</exclude> <exclude>DataTest.java</exclude>
</excludes> </excludes>
<includes> <includes>
<include>TestFail.java</include> <include>TestFail.java</include>
<include>DataCheck.java</include> <include>DataCheck.java</include>
</includes> </includes>
<testFailureIgnore>true</testFailureIgnore> <testFailureIgnore>true</testFailureIgnore>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>
</profiles> <profile>
<id>failsafe</id>
<properties> <build>
<maven.resources.version>3.0.2</maven.resources.version> <plugins>
<maven.failsafe.version>2.21.0</maven.failsafe.version> <plugin>
<maven.verifier.version>1.1</maven.verifier.version> <artifactId>maven-failsafe-plugin</artifactId>
<maven.clean.version>3.0.0</maven.clean.version> <version>${maven.failsafe.version}</version>
<maven.build.helper.version>3.0.0</maven.build.helper.version> <configuration>
<resources.name>Baeldung</resources.name> <includes>
</properties> <include>**/*RestIT</include>
<include>**/RestITCase</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>surefire</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>category</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven.failsafe.version}</version>
<configuration>
<includes>
<include>**/*</include>
</includes>
<groups>com.baeldung.maven.it.Integration</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<java.version>1.8</java.version>
<maven.resources.version>3.0.2</maven.resources.version>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.surefire.version>2.22.0</maven.surefire.version>
<maven.failsafe.version>2.22.0</maven.failsafe.version>
<maven.verifier.version>1.1</maven.verifier.version>
<maven.clean.version>3.0.0</maven.clean.version>
<maven.build.helper.version>3.0.0</maven.build.helper.version>
<resources.name>Baeldung</resources.name>
<jetty.version>9.4.11.v20180605</jetty.version>
<jersey.version>2.27</jersey.version>
<junit.version>4.12</junit.version>
</properties>
</project> </project>

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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!";
}
}

View File

@ -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>

View File

@ -0,0 +1,4 @@
package com.baeldung.maven.it;
public interface Integration {
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}