Commit 5a6f4b46 authored by Riegel's avatar Riegel
Browse files

Updated project to use SnakeYAML version 2.0. Ref #70

parent fb7430a0
Pipeline #10048 passed with stage
in 1 minute and 33 seconds
...@@ -64,7 +64,11 @@ ...@@ -64,7 +64,11 @@
<groupId>net.sf.saxon</groupId> <groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId> <artifactId>Saxon-HE</artifactId>
</dependency> </dependency>
</dependencies> <dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
</dependencies>
<build> <build>
<resources> <resources>
<resource> <resource>
......
...@@ -33,6 +33,7 @@ import java.util.Map.Entry; ...@@ -33,6 +33,7 @@ import java.util.Map.Entry;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.nodes.Tag;
...@@ -72,7 +73,7 @@ public class ValidationConfiguration implements Serializable { ...@@ -72,7 +73,7 @@ public class ValidationConfiguration implements Serializable {
} }
public static ValidationConfiguration loadValidationConfig(InputStream stream) { public static ValidationConfiguration loadValidationConfig(InputStream stream) {
Yaml yaml = new Yaml(new Constructor(ValidationConfiguration.class)); Yaml yaml = new Yaml(new Constructor(ValidationConfiguration.class, new LoaderOptions()));
ValidationConfiguration config = yaml.load(stream); ValidationConfiguration config = yaml.load(stream);
config.validateConfiguration(); config.validateConfiguration();
return config; return config;
...@@ -104,9 +105,9 @@ public class ValidationConfiguration implements Serializable { ...@@ -104,9 +105,9 @@ public class ValidationConfiguration implements Serializable {
DumperOptions options = new DumperOptions(); DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true); options.setPrettyFlow(true);
Representer rep = new ValidationConfigurationRepresenter(); Representer rep = new ValidationConfigurationRepresenter(options);
rep.addClassTag(ValidationConfiguration.class, Tag.MAP); rep.addClassTag(ValidationConfiguration.class, Tag.MAP);
Yaml yaml = new Yaml(rep, options); Yaml yaml = new Yaml(rep);
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
yaml.dump(this, bw); yaml.dump(this, bw);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
package de.hft.stuttgart.citydoctor2.check; package de.hft.stuttgart.citydoctor2.check;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.introspector.Property; import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.CollectionNode; import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.MappingNode;
...@@ -35,7 +36,11 @@ import org.yaml.snakeyaml.representer.Representer; ...@@ -35,7 +36,11 @@ import org.yaml.snakeyaml.representer.Representer;
* *
*/ */
public class ValidationConfigurationRepresenter extends Representer { public class ValidationConfigurationRepresenter extends Representer {
public ValidationConfigurationRepresenter(DumperOptions options) {
super(options);
}
@Override @Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag) { Tag customTag) {
......
...@@ -18,12 +18,6 @@ ...@@ -18,12 +18,6 @@
*/ */
package de.hft.stuttgart.citydoctor2.check; package de.hft.stuttgart.citydoctor2.check;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import org.junit.Test; import org.junit.Test;
...@@ -31,6 +25,13 @@ import org.junit.Test; ...@@ -31,6 +25,13 @@ import org.junit.Test;
import de.hft.stuttgart.citydoctor2.datastructure.FeatureType; import de.hft.stuttgart.citydoctor2.datastructure.FeatureType;
import de.hft.stuttgart.quality.model.enums.RequirementId; import de.hft.stuttgart.quality.model.enums.RequirementId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
public class ValidationConfigurationTest { public class ValidationConfigurationTest {
@Test @Test
...@@ -70,4 +71,21 @@ public class ValidationConfigurationTest { ...@@ -70,4 +71,21 @@ public class ValidationConfigurationTest {
assertTrue(includeFilter.getTypes().contains(FeatureType.VEGETATION)); assertTrue(includeFilter.getTypes().contains(FeatureType.VEGETATION));
} }
@Test
public void testVulnerableConfig() throws FileNotFoundException{
String file = "src/test/resources/testConfigVulnerability.yml";
ValidationConfiguration config = null;
try {
config = ValidationConfiguration.loadValidationConfig(file);
assertNotNull(config);
fail("Config with Vulnerability should not be successfully loaded");
} catch (FileNotFoundException e){
// Rethrow FNFE
throw e;
} catch (Exception e) {
// Bad config was not loaded
assertNull(config);
}
}
} }
...@@ -200,7 +200,7 @@ ...@@ -200,7 +200,7 @@
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>1.30</version> <version>2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment