-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Piszmog/develop
Release 2.2
- Loading branch information
Showing
5 changed files
with
157 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...groovy/io/github/piszmog/cloudconfigclient/autoconfig/env/support/MapFlattenerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.github.piszmog.cloudconfigclient.autoconfig.env.support | ||
|
||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* Created by Piszmog on 7/29/2018 | ||
*/ | ||
class MapFlattenerSpec extends Specification | ||
{ | ||
// ============================================================ | ||
// Tests: | ||
// ============================================================ | ||
|
||
def "flatten a simple map"() | ||
{ | ||
given: "a map" | ||
Map topLevelMap = new HashMap() | ||
topLevelMap.put( "key1", "value1" ) | ||
topLevelMap.put( "key2", "value2" ) | ||
|
||
when: "the map is flattened" | ||
def flattenedMap = MapFlattener.flatten( topLevelMap ) | ||
|
||
then: "the map is flattened" | ||
flattenedMap.get( "key1" ) == "value1" | ||
flattenedMap.get( "key2" ) == "value2" | ||
} | ||
|
||
def "flatten a nested map"() | ||
{ | ||
given: "a map" | ||
Map level2Map = new HashMap() | ||
level2Map.put( "level2Key1", "value1" ) | ||
level2Map.put( "level2Key2", "value2" ) | ||
Map level1Map = new HashMap() | ||
level1Map.put( "level2", level2Map ) | ||
Map topLevelMap = new HashMap() | ||
topLevelMap.put( "level1", level1Map ) | ||
|
||
when: "the map is flattened" | ||
def flattenMap = MapFlattener.flatten( topLevelMap ) | ||
|
||
then: "the map is flattened" | ||
flattenMap.get( "level1.level2.level2Key1" ) == "value1" | ||
flattenMap.get( "level1.level2.level2Key2" ) == "value2" | ||
} | ||
|
||
def "flatten a nested map with a list"() | ||
{ | ||
given: "a map" | ||
List list = new LinkedList() | ||
list.add( "value1" ) | ||
list.add( "value2" ) | ||
Map level1Map = new HashMap() | ||
level1Map.put( "list", list ) | ||
Map topLevelMap = new HashMap() | ||
topLevelMap.put( "level1", level1Map ) | ||
|
||
when: "the map is flattened" | ||
def flattenMap = MapFlattener.flatten( topLevelMap ) | ||
|
||
then: "the map is flattened" | ||
flattenMap.get( "level1.list[0]" ) == "value1" | ||
flattenMap.get( "level1.list[1]" ) == "value2" | ||
} | ||
|
||
def "flatten a nested map with special characters"() | ||
{ | ||
given: "a map" | ||
Map level2Map = new HashMap() | ||
level2Map.put( "level2.Key1", "value1" ) | ||
level2Map.put( "level2:Key2", "value2" ) | ||
level2Map.put( "level2*Key3", "value3" ) | ||
level2Map.put( "\$level2Key4", "value4" ) | ||
level2Map.put( "#level2Key5", "value5" ) | ||
level2Map.put( "%level2Key6", "value6" ) | ||
level2Map.put( "!level2Key7", "value7" ) | ||
level2Map.put( "^level2Key8", "value8" ) | ||
level2Map.put( "@level2Key9", "value9" ) | ||
level2Map.put( "&level2Key10", "value10" ) | ||
Map level1Map = new HashMap() | ||
level1Map.put( "level2", level2Map ) | ||
Map topLevelMap = new HashMap() | ||
topLevelMap.put( "level1", level1Map ) | ||
|
||
when: "the map is flattened" | ||
def flattenMap = MapFlattener.flatten( topLevelMap ) | ||
|
||
then: "the map is flattened" | ||
flattenMap.get( "level1.level2.[level2.Key1]" ) == "value1" | ||
flattenMap.get( "level1.level2.[level2:Key2]" ) == "value2" | ||
flattenMap.get( "level1.level2.[level2*Key3]" ) == "value3" | ||
flattenMap.get( "level1.level2.[\$level2Key4]" ) == "value4" | ||
flattenMap.get( "level1.level2.[#level2Key5]" ) == "value5" | ||
flattenMap.get( "level1.level2.%level2Key6" ) == "value6" | ||
flattenMap.get( "level1.level2.!level2Key7" ) == "value7" | ||
flattenMap.get( "level1.level2.^level2Key8" ) == "value8" | ||
flattenMap.get( "level1.level2.@level2Key9" ) == "value9" | ||
flattenMap.get( "level1.level2.&level2Key10" ) == "value10" | ||
} | ||
} |