Commit 3f3ddee3 authored by Adrien's avatar Adrien
Browse files

Update IT module for gherkin syntax

parent e773899d
Pipeline #293567 failed with stages
in 6 minutes and 14 seconds
......@@ -102,7 +102,7 @@ public class ValidationOverview {
*
* @param disclaimer {@link String} can not be null
* @param validationServiceName {@link String} can not be null
* @param validationServiceVersion {@link String} can not be null
* @param validationServiceVersion {@link String}
* @param validatorID {@link String} can not be null
* @param additionalMetadata {@link Metadata}
* @param validatorVersion {@link String}
......@@ -222,9 +222,6 @@ public class ValidationOverview {
* @throws IllegalArgumentException if validationServiceVersion is null
*/
public void setValidationServiceVersion(String validationServiceVersion) {
if (validationServiceVersion == null) {
throw new IllegalArgumentException("validationServiceVersion can not be null");
}
this.validationServiceVersion = validationServiceVersion;
}
......@@ -346,7 +343,7 @@ public class ValidationOverview {
if (!validationServiceName.equals(overview.validationServiceName)) {
return false;
}
if (!validationServiceVersion.equals(overview.validationServiceVersion)) {
if (validationServiceVersion != null ? !validationServiceVersion.equals(overview.validationServiceVersion) : overview.validationServiceVersion != null) {
return false;
}
if (!validatorID.equals(overview.validatorID)) {
......@@ -369,7 +366,7 @@ public class ValidationOverview {
int result = disclaimer.hashCode();
result = 31 * result + validationDateTime.hashCode();
result = 31 * result + validationServiceName.hashCode();
result = 31 * result + validationServiceVersion.hashCode();
result = 31 * result + (validationServiceVersion != null ? validationServiceVersion.hashCode() : 0);
result = 31 * result + validatorID.hashCode();
result = 31 * result + (validatorVersion != null ? validatorVersion.hashCode() : 0);
result = 31 * result + additionalMetadata.hashCode();
......
......@@ -47,8 +47,17 @@ public class DefaultValidatorReportParser implements ValidatorReportParser {
public ValidationReport buildValidationReport(Validation validation, ValidationReportDao dao) throws IOException {
ValidationReport vr = new ValidationReport(validation.getOid()+".1");
DetailedResult detailedResult = parse();
report.getValidationServiceRef().setVersion(toVersion(detailedResult.getValidationResultsOverview().getValidationServiceVersion()));
report.getValidationServiceRef().setValidatorVersion(toVersion(detailedResult.getValidationResultsOverview().getValidationEngineVersion()));
String validationServiceVersion = detailedResult.getValidationResultsOverview().getValidationServiceVersion();
if(validationServiceVersion != null){
report.getValidationServiceRef().setVersion(toVersion(validationServiceVersion));
}
String validationEngineVersion = detailedResult.getValidationResultsOverview().getValidationEngineVersion();
if(validationServiceVersion != null){
report.getValidationServiceRef().setValidatorVersion(toVersion(validationEngineVersion));
}
vr.setValidatorReportRef(new ValidatorReportRef(report));
vr.setValidationOverview(parseOverview(detailedResult.getValidationResultsOverview()));
......
package net.ihe.gazelle.evs.api;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.MustacheException;
import com.samskivert.mustache.Template;
import io.restassured.RestAssured;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import java.io.*;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import static org.hamcrest.Matchers.equalTo;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ValidationsIT extends AbstractValidationsIT {
public class ValidationsIT {
class Tpl {
Mustache.Compiler compiler = Mustache.compiler()
.withLoader(new Mustache.TemplateLoader() {
public Reader getTemplate(String name) {
try {
return reader(name);
} catch (Exception e) {
logger.error("Mustache.TemplateLoader", e);
return null;
}
}
});
Template template;
Tpl(String tplname) {
template = compiler.compile(reader(tplname));
}
public String execute(Object context) throws MustacheException {
return template.execute(context);
}
private Reader reader(String name) {
return new BufferedReader(new InputStreamReader(getRootClass().getResourceAsStream(name + ".mustache"), StandardCharsets.UTF_8));
}
private Class<?> getRootClass() {
return ValidationsIT.this.getClass();
}
}
private static Logger logger = Logger.getLogger(ValidationsIT.class);
private static String oid;
private static String ref;
class LoggingOutputStream extends OutputStream {
@Test
public void _0001_postValidationCDA2HL7Ok() throws IOException {
// build request
String body = new Tpl("validation-for-creation")
.execute(new Object() {
String service = conf.at("/it/evs/ws/services/model-based/cda-hl7/service").asText();
String validator = conf.at("/it/evs/ws/services/model-based/cda-hl7/validator").asText();
String filename = conf.at("/it/evs/ws/services/model-based/cda-hl7/filename").asText();
String content = getContent(filename);
});
RequestSpecification request = request(RestAssured.given()
.contentType(ContentType.XML)
.body(body));
/**
* Default number of bytes in the buffer.
*/
private static final int DEFAULT_BUFFER_LENGTH = 2048;
// send request
Response response = response(request
.when()
.post(validations.toURL()));
/**
* Indicates stream state.
*/
private boolean hasBeenClosed = false;
// asserts
response.then().statusCode(201);
/**
* Internal buffer where data is stored.
*/
private byte[] buf;
// keep oid
oid = response.getHeader("Location").replaceAll(".*./validations/(.*?)", "$1");
}
@Test
public void _0001_postValidationCDA2HL7WrongService() throws IOException {
// build request
String body = new Tpl("validation-for-creation")
.execute(new Object() {
String service = conf.at("/it/evs/ws/services/model-based/wrong/service").asText();
String validator = conf.at("/it/evs/ws/services/model-based/cda-hl7/validator").asText();
String filename = conf.at("/it/evs/ws/services/model-based/cda-hl7/filename").asText();
String content = getContent(filename);
});
RequestSpecification request = request(RestAssured.given()
.contentType(ContentType.XML)
.body(body));
/**
* The number of valid bytes in the buffer.
*/
private int count;
// send request
Response response = response(request
.when()
.post(validations.toURL()));
/**
* Remembers the size of the buffer.
*/
private int curBufLength;
// asserts
response.then().statusCode(400);
/**
* The logger to write to.
*/
private Logger log;
/**
* The log level.
*/
private Level level;
/**
* Creates the Logging instance to flush to the given logger.
*
* @param log the Logger to write to
* @param level the log level
* @throws IllegalArgumentException in case if one of arguments is null.
*/
public LoggingOutputStream(final Logger log,
final Level level)
throws IllegalArgumentException {
if (log == null || level == null) {
throw new IllegalArgumentException(
"Logger or log level must be not null");
}
this.log = log;
this.level = level;
curBufLength = DEFAULT_BUFFER_LENGTH;
buf = new byte[curBufLength];
count = 0;
}
/**
* Writes the specified byte to this output stream.
*
* @param b the byte to write
* @throws IOException if an I/O error occurs.
*/
public void write(final int b) throws IOException {
if (hasBeenClosed) {
throw new IOException("The stream has been closed.");
}
// don't log nulls
if (b == 0) {
return;
}
// would this be writing past the buffer?
if (count == curBufLength) {
// grow the buffer
final int newBufLength = curBufLength +
DEFAULT_BUFFER_LENGTH;
final byte[] newBuf = new byte[newBufLength];
System.arraycopy(buf, 0, newBuf, 0, curBufLength);
buf = newBuf;
curBufLength = newBufLength;
}
buf[count] = (byte) b;
count++;
}
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
*/
public void flush() {
if (count == 0) {
return;
}
final byte[] bytes = new byte[count];
System.arraycopy(buf, 0, bytes, 0, count);
String str = new String(bytes);
log.log(level, str);
count = 0;
}
/**
* Closes this output stream and releases any system resources
* associated with this stream.
*/
public void close() {
flush();
hasBeenClosed = true;
}
}
@Test
public void _0001_postValidationCDA2HL7WrongValidator() throws IOException {
// build request
String body = new Tpl("validation-for-creation")
.execute(new Object() {
String service = conf.at("/it/evs/ws/services/model-based/cda-hl7/service").asText();
String validator = conf.at("/it/evs/ws/services/model-based/wrong/validator").asText();
String filename = conf.at("/it/evs/ws/services/model-based/cda-hl7/filename").asText();
String content = getContent(filename);
});
RequestSpecification request = request(RestAssured.given()
.contentType(ContentType.XML)
.body(body));
// send request
Response response = response(request
.when()
.post(validations.toURL()));
private static Logger logger = Logger.getLogger(ValidationsIT.class);
private static String oid;
private static String ref;
private static JsonNode conf;
static {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
conf = mapper.readTree(ValidationsIT.class.getResourceAsStream(System.getProperty("validations-it.configuration","validations-it.yml")));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// asserts
response.then().statusCode(400);
private LoggingOutputStream los;
private RestAssuredConfig config;
private URI host = URI.create(System.getProperty("it.evs-ws-host",conf.at("/it/evs/ws/host").asText()));
private URI root = host.resolve(System.getProperty("it.evs-ws-path",conf.at("/it/evs/ws/path").asText()));
private URI validations = root.resolve("validations/");
@Before
public void setUpBeforeTest() {
RestAssured.reset();
los = new LoggingOutputStream(logger,Level.INFO);
config = RestAssuredConfig.newConfig().logConfig(new LogConfig(new PrintStream(los),true));
RestAssured.config = config;
}
@Test
public void _0001_postValidationCDA2HL7WrongFile() throws IOException {
// build request
......@@ -122,6 +229,7 @@ public class ValidationsIT extends AbstractValidationsIT {
.then()
.body("validation.status",equalTo("DONE_FAILED"));
}
@Test
public void _0001_postValidationCDA2HL7EmptyFile() throws IOException {
// build request
......@@ -166,6 +274,7 @@ public class ValidationsIT extends AbstractValidationsIT {
.getNode("object")
.getAttribute("ref");
}
@Test
public void _0002_getValidationCDA2HL7NotExists() throws IOException {
// build request
......@@ -552,4 +661,39 @@ public class ValidationsIT extends AbstractValidationsIT {
}
private String getContent(String filename) throws IOException {
Scanner s = new Scanner(this.getClass().getResourceAsStream(filename))
.useDelimiter("\\A");
return Base64.encodeBase64String((s.hasNext() ? s.next() : "").getBytes(StandardCharsets.UTF_8));
}
private RequestSpecification request(RequestSpecification request) {
logger.info(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ");
logger.info(" <<<<<<<<<< "+Thread.currentThread().getStackTrace()[2].getMethodName()); request.config(config).log().all();
logger.info(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ");
los.flush();
return request;
}
private Response response(Response response) {
response.then().log().all();
los.flush();
logger.info(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ");
logger.info("");
logger.info("");
return response;
}
}
package net.ihe.gazelle.evs.api.config;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.MustacheException;
import com.samskivert.mustache.Template;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
public class MustacheTemplate {
private static Logger logger = Logger.getLogger(MustacheTemplate.class);
Mustache.Compiler compiler = Mustache.compiler()
.withLoader(new Mustache.TemplateLoader() {
public Reader getTemplate(String name) {
try {
return reader(name);
} catch (Exception e) {
logger.error("Mustache.TemplateLoader", e);
return null;
}
}
});
Template template;
public MustacheTemplate(String tplname) {
template = compiler.compile(reader(tplname));
}
public String execute(Object context) throws MustacheException {
return template.execute(context);
}
private Reader reader(String name) {
return new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(name + ".mustache"), StandardCharsets.UTF_8));
}
private Class<?> getRootClass() {
return MustacheTemplate.this.getClass();
}
}
package net.ihe.gazelle.evs.api;
package net.ihe.gazelle.evs.api.config;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.MustacheException;
import com.samskivert.mustache.Template;
import io.restassured.RestAssured;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import static org.hamcrest.Matchers.equalTo;
public class AbstractValidationsIT {
class Tpl {
Mustache.Compiler compiler = Mustache.compiler()
.withLoader(new Mustache.TemplateLoader() {
public Reader getTemplate(String name) {
try {
return reader(name);
} catch (Exception e) {
logger.error("Mustache.TemplateLoader", e);
return null;
}
}
});
Template template;
Tpl(String tplname) {
template = compiler.compile(reader(tplname));
}
public String execute(Object context) throws MustacheException {
return template.execute(context);
}
private Reader reader(String name) {
return new BufferedReader(new InputStreamReader(getRootClass().getResourceAsStream(name + ".mustache"), StandardCharsets.UTF_8));
}
private Class<?> getRootClass() {
return AbstractValidationsIT.this.getClass();
public class RestApiConnector {
private static Logger logger = Logger.getLogger(RestApiConnector.class);
protected RestAssuredConfig config;
private LoggingOutputStream los;
private URI validationUri;
public RestApiConnector() {
initApiConfig();
RestAssured.reset();
los = new LoggingOutputStream(logger,Level.INFO);
config = RestAssuredConfig.newConfig().logConfig(new LogConfig(new PrintStream(los),true));
}
private void initApiConfig() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
JsonNode apiConfig = mapper.readTree(this.getClass().getResourceAsStream(System.getProperty("api-config-it.configuration","api-config-it.yml")));
String host = apiConfig.at("/it/evs/ws/host").asText();
String path = apiConfig.at("/it/evs/ws/path").asText();
validationUri = URI.create(System.getProperty("it.evs-ws-host", host)).resolve(System.getProperty("it.evs-ws-path", path)).resolve("validations/");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public Response validate(String body) {
RequestSpecification request = request(RestAssured.given()
.contentType(ContentType.XML)
.body(body));
// send request
return response(request
.when()
.post(validationUri));
}
public Response getReport(String uri) {
return RestAssured.given()
.accept(ContentType.XML.getAcceptHeader())
.when()
.get(URI.create(uri));
}
private RequestSpecification request(RequestSpecification request) {
logger.info(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ");
logger.info(" <<<<<<<<<< "+Thread.currentThread().getStackTrace()[2].getMethodName());
request.config(config).log().all();
logger.info(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ");
los.flush();
return request;
}
private Response response(Response response) {
response.then().log().all();
los.flush();
logger.info(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ");
logger.info("");
logger.info("");
return response;
}
class LoggingOutputStream extends OutputStream {
/**
......@@ -168,63 +196,4 @@ public class AbstractValidationsIT {
hasBeenClosed = true;
}
}