Merge branch 'xperimental/RM6353_FixYamlUnitTest_no' into 'xperimental/RM-6313UpgradeRMSchedulers'

RM-6353 Fix Yaml Unit Test

See merge request records-management/records-management!1015
This commit is contained in:
Sara Aspery
2018-05-29 11:38:58 +01:00

View File

@@ -27,6 +27,7 @@
package org.alfresco.module.org_alfresco_module_rm.test.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -38,6 +39,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.fasterxml.jackson.databind.JsonNode;
@@ -45,14 +47,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.report.ProcessingMessage;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.yaml.snakeyaml.parser.ParserException;
/**
* Base class for unit tests for Yaml files.
@@ -97,16 +101,16 @@ public class BaseYamlUnitTest
assertTrue("Yaml file is not valid Swagger " + OPEN_API_SPECIFICATION + ": " + yamlFilePath,
validateYamlFile(yamlFilePath, swaggerSchema));
/* // check can read the swagger object to obtain the swagger version
// check can read the swagger object to obtain the swagger version
Swagger swagger = new SwaggerParser().read(yamlFilePath);
assertEquals("Failed to obtain Swagger version from yaml file " + yamlFilePath,
swagger.getSwagger(), OPEN_API_SPECIFICATION);*/
swagger.getSwagger(), OPEN_API_SPECIFICATION);
}
catch (ParserException ex)
catch (ProcessingException ex)
{
// ensure the yaml filename is included in the message
String context = String.format(yamlFilePath + ": %n" + ex.getContext());
throw new ParserException(context, ex.getContextMark(), ex.getProblem(), ex.getProblemMark()) ;
String context = String.format(yamlFilePath + ": %n" + ex.getMessage());
throw new ProcessingException(context) ;
}
}
}
@@ -152,6 +156,15 @@ public class BaseYamlUnitTest
{
final JsonNode dataNode = JsonLoader.fromString(jsonData);
final ProcessingReport report = schema.validate(dataNode);
return report.isSuccess();
boolean isOk = report.isSuccess();
if (!isOk)
{
Iterator<ProcessingMessage> messages = report.iterator();
if (messages.hasNext())
{
throw new ProcessingException(messages.next().toString());
}
}
return isOk;
}
}