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

View file

@ -0,0 +1,70 @@
package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
import de.kosit.validationtool.impl.Helper.Simple;
import io.restassured.http.ContentType;
/**
* Testet the Daemon-Mode input , Methoden , Output Content-Type and the success case
*
* @author Roula Antoun
*/
public class CheckHandlerIT extends BaseIT {
private static final String APPLICATION_XML = "application/xml";
@Test
public void makeSureThatSuccessTest() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
given().contentType(ContentType.XML).body(toContent(io)).when().post("/").then().statusCode(200);
}
}
@Test
public void NoInputTest() {
given().body("").contentType(APPLICATION_XML).when().post("/").then().statusCode(400);
}
@Test
@Ignore // no default error report yet
public void internalServerErrorTest() throws IOException {
try ( final InputStream io = Simple.INVALID.toURL().openStream() ) {
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(200);
}
}
private static byte[] toContent(final InputStream io) throws IOException {
return IOUtils.toByteArray(io);
}
@Test
public void methodNotAllowedTest() {
given().when().get("/").then().statusCode(405);
given().when().put("/").then().statusCode(405);
given().when().patch("/").then().statusCode(405);
given().when().delete("/").then().statusCode(405);
given().when().head("/").then().statusCode(405);
given().when().options("/").then().statusCode(405);
}
@Test
public void xmlResultTest() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
given().body(toContent(io)).when().post("/").then().contentType(APPLICATION_XML).and().statusCode(200);
}
}
}