Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
5a6f4b46
Commit
5a6f4b46
authored
Aug 06, 2024
by
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
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorValidation/pom.xml
View file @
5a6f4b46
...
...
@@ -64,7 +64,11 @@
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>
org.yaml
</groupId>
<artifactId>
snakeyaml
</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
...
...
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/ValidationConfiguration.java
View file @
5a6f4b46
...
...
@@ -33,6 +33,7 @@ import java.util.Map.Entry;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.LoaderOptions
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.constructor.Constructor
;
import
org.yaml.snakeyaml.nodes.Tag
;
...
...
@@ -72,7 +73,7 @@ public class ValidationConfiguration implements Serializable {
}
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
);
config
.
validateConfiguration
();
return
config
;
...
...
@@ -104,9 +105,9 @@ public class ValidationConfiguration implements Serializable {
DumperOptions
options
=
new
DumperOptions
();
options
.
setDefaultFlowStyle
(
DumperOptions
.
FlowStyle
.
BLOCK
);
options
.
setPrettyFlow
(
true
);
Representer
rep
=
new
ValidationConfigurationRepresenter
();
Representer
rep
=
new
ValidationConfigurationRepresenter
(
options
);
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
)))
{
yaml
.
dump
(
this
,
bw
);
}
...
...
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/ValidationConfigurationRepresenter.java
View file @
5a6f4b46
...
...
@@ -18,6 +18,7 @@
*/
package
de.hft.stuttgart.citydoctor2.check
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.introspector.Property
;
import
org.yaml.snakeyaml.nodes.CollectionNode
;
import
org.yaml.snakeyaml.nodes.MappingNode
;
...
...
@@ -35,7 +36,11 @@ import org.yaml.snakeyaml.representer.Representer;
*
*/
public
class
ValidationConfigurationRepresenter
extends
Representer
{
public
ValidationConfigurationRepresenter
(
DumperOptions
options
)
{
super
(
options
);
}
@Override
protected
NodeTuple
representJavaBeanProperty
(
Object
javaBean
,
Property
property
,
Object
propertyValue
,
Tag
customTag
)
{
...
...
CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/ValidationConfigurationTest.java
View file @
5a6f4b46
...
...
@@ -18,12 +18,6 @@
*/
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
org.junit.Test
;
...
...
@@ -31,6 +25,13 @@ import org.junit.Test;
import
de.hft.stuttgart.citydoctor2.datastructure.FeatureType
;
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
{
@Test
...
...
@@ -70,4 +71,21 @@ public class ValidationConfigurationTest {
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
);
}
}
}
CityDoctorParent/CityDoctorValidation/src/test/resources/testConfigVulnerability.yml
0 → 100644
View file @
5a6f4b46
globalParameters
:
!!globalTag
CityDoctorParent/pom.xml
View file @
5a6f4b46
...
...
@@ -200,7 +200,7 @@
<dependency>
<groupId>
org.yaml
</groupId>
<artifactId>
snakeyaml
</artifactId>
<version>
1.3
0
</version>
<version>
2.
0
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment