-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#442] account for lists in YamlUtils#loadYaml
#443
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,8 @@ | |
"implementation": "com.boozallen.aissemble.upgrade.migration.v1_10_0.DeltaSparkYamlMigration", | ||
"fileSets": [ | ||
{ | ||
"includes": ["**/*.yaml"] | ||
"includes": ["**/*.yaml"], | ||
"excludes": ["**/target/**", "**/templates/**"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I: Not strictly necessary but this cuts down significantly on the number of output lines talking about un-parseable helm templates. |
||
} | ||
] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.boozallen.aissemble.upgrade.migration.utils; | ||
|
||
/*- | ||
* #%L | ||
* aiSSEMBLE::Foundation::Upgrade | ||
* %% | ||
* Copyright (C) 2021 Booz Allen | ||
* %% | ||
* This software package is licensed under the Booz Allen Public License. All Rights Reserved. | ||
* #L% | ||
*/ | ||
|
||
import com.boozallen.aissemble.upgrade.util.YamlUtils; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.When; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class YamlUtilsSteps { | ||
|
||
private Path testFile; | ||
private YamlUtils.YamlObject yaml; | ||
|
||
@Given("a YAML file:") | ||
public void aYamlFile(String contents) throws IOException { | ||
testFile = Files.createTempFile(Path.of("target"), "yaml-util-test", ""); | ||
Files.writeString(testFile, contents); | ||
} | ||
|
||
@When("the file is loaded") | ||
public void theFileIsLoaded() throws IOException { | ||
yaml = YamlUtils.loadYaml(testFile.toFile()); | ||
} | ||
|
||
@Then("the string value of the property {string} is {string}") | ||
public void theStringValueOfThePropertyIs(String name, String value) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as string: " + name + " (was " + type + ")", yaml.hasString(name)); | ||
assertEquals("Property value does not match for: " + name, value, yaml.getString(name)); | ||
} | ||
|
||
@Then("the decimal value of the property {string} is {double}") | ||
public void theDecimalValueOfThePropertyIs(String name, double value) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as double: " + name + " (was " + type + ")", yaml.hasDouble(name)); | ||
assertEquals("Property value does not match for: " + name, value, yaml.getDouble(name), 0.01); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a |
||
} | ||
|
||
@Then("the integer value of the property {string} is {int}") | ||
public void theIntegerValueOfThePropertyIs(String name, int value) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as int: " + name + " (was " + type + ")", yaml.hasInt(name)); | ||
assertEquals("Property value does not match for: " + name, value, yaml.getInt(name)); | ||
} | ||
|
||
@Then("the boolean value of the property {string} is {string}") | ||
public void theBooleanValueOfThePropertyIs(String name, String value) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as boolean: " + name + " (was " + type + ")", yaml.hasBoolean(name)); | ||
assertEquals("Property value does not match for: " + name, Boolean.valueOf(value), yaml.getBoolean(name)); | ||
} | ||
|
||
@Then("the property {string} is an object") | ||
public void thePropertyIsAnObject(String name) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as object: " + name + " (was " + type + ")", yaml.hasObject(name)); | ||
} | ||
|
||
@Then("the decimal value of the property {string} of the Object {string} is {double}") | ||
public void theDecimalValueOfThePropertyOfTheObjectIs(String prop, String obj, double value) { | ||
assertTrue("Property was not loaded as double: " + obj + "." + prop, yaml.hasDouble(obj, prop)); | ||
assertEquals("Property value does not match for: " + obj + "." + prop, value, yaml.getDouble(obj, prop), 0.01); | ||
} | ||
|
||
@Then("the size of the list {string} is {int}") | ||
public void theSizeOfTheListIs(String name, int size) { | ||
String type = yaml.get(name).getClass().getSimpleName(); | ||
assertTrue("Property was not loaded as list: " + name + " (was " + type + ")", yaml.hasList(name)); | ||
assertEquals("Property value does not match for: " + name, size, yaml.getList(name).size()); | ||
} | ||
|
||
@Then("the {string} of item {int} of the list {string} is {int}") | ||
public void theIntegerValueOfItemOfTheListIs(String prop, int index, String list, int value) { | ||
List<YamlUtils.YamlObject> objects = yaml.getListOfObjects(list); | ||
YamlUtils.YamlObject object = objects.get(index); | ||
String key = list + "[" + index + "]." + prop; | ||
assertEquals("Property value does not match for: " + key, value, object.getInt(prop)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Utilities -> YAML | ||
|
||
Scenario: I can load a YAML file with an object | ||
Given a YAML file: | ||
"""yaml | ||
name: test | ||
size: 7.5 | ||
count: 12 | ||
complete: True | ||
nested: { | ||
size: 2.0 | ||
} | ||
multiple: | ||
- intvalue: 5 | ||
- intvalue: 7 | ||
""" | ||
When the file is loaded | ||
Then the string value of the property "name" is "test" | ||
And the decimal value of the property "size" is 7.5 | ||
And the integer value of the property "count" is 12 | ||
And the boolean value of the property "complete" is "true" | ||
And the property "nested" is an object | ||
And the decimal value of the property "size" of the Object "nested" is 2.0 | ||
And the size of the list "multiple" is 2 | ||
And the "intvalue" of item 1 of the list "multiple" is 7 | ||
|
||
Scenario: I can load a YAML file with a list | ||
Given a YAML file: | ||
"""yaml | ||
- red | ||
- blue | ||
- yellow | ||
""" | ||
When the file is loaded | ||
Then the size of the list "items" is 3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- | ||
#%L | ||
aiSSEMBLE::Foundation::Upgrade | ||
%% | ||
Copyright (C) 2021 Booz Allen | ||
%% | ||
This software package is licensed under the Booz Allen Public License. All Rights Reserved. | ||
#L% | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.test</groupId> | ||
<artifactId>test-pom</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.delta</groupId> | ||
<artifactId>delta-core_2.13</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- | ||
#%L | ||
aiSSEMBLE::Foundation::Upgrade | ||
%% | ||
Copyright (C) 2021 Booz Allen | ||
%% | ||
This software package is licensed under the Booz Allen Public License. All Rights Reserved. | ||
#L% | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.test</groupId> | ||
<artifactId>test-pom</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.delta</groupId> | ||
<artifactId>delta-spark_2.13</artifactId> | ||
<version>${version.delta}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I: these were returning false when they shouldn't have as the map has the boxed version of the value so
isInstance
was failing.