mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-6353 Fix Yaml Unit Test
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
package org.alfresco.module.org_alfresco_module_rm.test.util;
|
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.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -38,6 +39,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
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.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
import com.github.fge.jackson.JsonLoader;
|
import com.github.fge.jackson.JsonLoader;
|
||||||
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
|
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.core.report.ProcessingReport;
|
||||||
import com.github.fge.jsonschema.main.JsonSchema;
|
import com.github.fge.jsonschema.main.JsonSchema;
|
||||||
import com.github.fge.jsonschema.main.JsonSchemaFactory;
|
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.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
||||||
import org.yaml.snakeyaml.parser.ParserException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for unit tests for Yaml files.
|
* 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,
|
assertTrue("Yaml file is not valid Swagger " + OPEN_API_SPECIFICATION + ": " + yamlFilePath,
|
||||||
validateYamlFile(yamlFilePath, swaggerSchema));
|
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);
|
Swagger swagger = new SwaggerParser().read(yamlFilePath);
|
||||||
assertEquals("Failed to obtain Swagger version from yaml file " + 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
|
// ensure the yaml filename is included in the message
|
||||||
String context = String.format(yamlFilePath + ": %n" + ex.getContext());
|
String context = String.format(yamlFilePath + ": %n" + ex.getMessage());
|
||||||
throw new ParserException(context, ex.getContextMark(), ex.getProblem(), ex.getProblemMark()) ;
|
throw new ProcessingException(context) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,6 +156,15 @@ public class BaseYamlUnitTest
|
|||||||
{
|
{
|
||||||
final JsonNode dataNode = JsonLoader.fromString(jsonData);
|
final JsonNode dataNode = JsonLoader.fromString(jsonData);
|
||||||
final ProcessingReport report = schema.validate(dataNode);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user