use random ports;

tests for the Daemon
This commit is contained in:
Andreas Penski (init) 2020-04-30 10:32:22 +02:00
parent aca3d2bd04
commit fcf3ff2bf1
7 changed files with 102 additions and 26 deletions

32
pom.xml
View file

@ -145,6 +145,26 @@
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>validator.server.port</portName>
<portName>jacoco.tcp.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
@ -319,6 +339,7 @@
</execution>
<execution>
<id>prepareJacocoFailsafeArgLine</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
@ -326,7 +347,7 @@
<propertyName>jacocoFailsafe</propertyName>
<output>tcpserver</output>
<address>localhost</address>
<port>8081</port>
<port>${jacoco.tcp.port}</port>
</configuration>
</execution>
<execution>
@ -338,7 +359,7 @@
</goals>
<configuration>
<address>localhost</address>
<port>8081</port>
<port>${jacoco.tcp.port}</port>
<append>true</append>
</configuration>
</execution>
@ -411,6 +432,8 @@
<argument>${project.build.testOutputDirectory}/examples/simple/scenarios.xml</argument>
<argument>-r</argument>
<argument>${project.build.testOutputDirectory}/examples/simple/repository</argument>
<argument>--port</argument>
<argument>${validator.server.port}</argument>
<argument>-D</argument>
</arguments>
@ -425,6 +448,7 @@
<target>
<!-- schlafen um den Start des Daemon abzuwarten -->
<sleep seconds="5" />
<echo>${jacoco.tcp.port}</echo>
</target>
</configuration>
<executions>
@ -448,6 +472,10 @@
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!--suppress MavenModelInspection -->
<argLine>-Dfile.encoding=UTF-8 -Ddaemon.port=${validator.server.port}</argLine>
</configuration>
</execution>
</executions>

View file

@ -6,7 +6,6 @@ import java.util.concurrent.Executors;
import com.sun.net.httpserver.HttpServer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@ -23,7 +22,6 @@ import de.kosit.validationtool.model.daemon.HealthType;
*/
@RequiredArgsConstructor
@Setter
@Getter
@Slf4j
public class Daemon {

View file

@ -1,7 +1,6 @@
package de.kosit.validationtool.impl.xml;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@ -15,6 +14,7 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import net.sf.saxon.Configuration;
import net.sf.saxon.expr.XPathContext;
@ -98,12 +98,9 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
return processor;
}
@SneakyThrows
private static String encode(final String input) {
try {
return URLEncoder.encode(input, StandardCharsets.UTF_8.name());
} catch (final UnsupportedEncodingException e) {
throw new IllegalStateException("Error encoding property while initializing saxon", e);
}
}
@Override

View file

@ -0,0 +1,26 @@
package de.kosit.validationtool.daemon;
import org.junit.Before;
import io.restassured.RestAssured;
/**
* Base for integration tests.
*
* @author Andreas Penski
*/
public abstract class BaseIT {
@Before
public void setup() {
final String port = System.getProperty("daemon.port");
if (port != null) {
RestAssured.port = Integer.valueOf(port);
}
final String baseHost = System.getProperty("daemon.host");
if (baseHost != null) {
RestAssured.baseURI = baseHost;
}
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
}

View file

@ -1,4 +1,4 @@
package de.kosit.validationtool.cmd;
package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given;
@ -6,13 +6,11 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import de.kosit.validationtool.impl.Helper.Simple;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
/**
@ -20,24 +18,13 @@ import io.restassured.http.ContentType;
*
* @author Roula Antoun
*/
public class DaemonIT {
public class CheckHandlerIT extends BaseIT {
private static final String APPLICATION_XML = "application/xml";
@Before
public void setup() {
final String port = System.getProperty("daemon.port");
if (port != null) {
RestAssured.port = Integer.valueOf(port);
}
final String baseHost = System.getProperty("daemon.host");
if (baseHost != null) {
RestAssured.baseURI = baseHost;
}
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
@Test
public void makeSureThatSuccessTest() throws IOException {

View file

@ -0,0 +1,20 @@
package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.http.ContentType;
/**
* Integration test for the {@link ConfigHandler}.
*
* @author Andreas Penski
*/
public class ConfigHandlerIT extends BaseIT {
@Test
public void checkHealth() {
given().when().get("/server/config").then().statusCode(200).and().contentType(ContentType.XML);
}
}

View file

@ -0,0 +1,20 @@
package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.http.ContentType;
/**
* Checks the health endpoint.
*
* @author Andreas Penski
*/
public class HealthHandlerIT extends BaseIT {
@Test
public void checkHealth() {
given().when().get("/server/health").then().statusCode(200).and().contentType(ContentType.XML);
}
}