-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
372 additions
and
29 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.askimed.nf.test.util; | ||
|
||
public interface MapOperation { | ||
public Object map(String path, Object value); | ||
} |
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,41 @@ | ||
package com.askimed.nf.test.util; | ||
|
||
import java.util.*; | ||
|
||
public class MapTraverser { | ||
|
||
public static void traverse(String prefix, Object root, MapOperation operation) { | ||
traverseRecursive(root, prefix, operation); | ||
} | ||
|
||
private static void traverseRecursive(Object node, String path, MapOperation operation) { | ||
if (node instanceof Map) { | ||
Map<String, Object> map = (Map<String, Object>) node; | ||
for (Map.Entry<String, Object> entry : new HashSet<>(map.entrySet())) { | ||
String key = entry.getKey(); | ||
Object value = entry.getValue(); | ||
String currentPath = path.isEmpty() ? key : path + "." + key; | ||
traverseRecursive(value, currentPath, operation); | ||
if (!(value instanceof Map) && !(value instanceof List)) { | ||
Object newValue = operation.map(currentPath, value); | ||
if (newValue != null) { | ||
map.put(key, newValue); | ||
} | ||
} | ||
} | ||
} else if (node instanceof List) { | ||
List<Object> list = (List<Object>) node; | ||
for (int i = 0; i < list.size(); i++) { | ||
Object value = list.get(i); | ||
String currentPath = path + "[" + i + "]"; | ||
traverseRecursive(value, currentPath, operation); | ||
if (!(value instanceof Map) && !(value instanceof List)) { | ||
Object newValue = operation.map(currentPath, value); | ||
if (newValue != null) { | ||
list.set(i, newValue); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.askimed.nf.test.lang; | ||
|
||
import com.askimed.nf.test.App; | ||
import com.askimed.nf.test.util.FileUtil; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class SnapshotTest { | ||
|
||
static { | ||
|
||
//AnsiColors.disable(); | ||
//AnsiText.disable(); | ||
|
||
} | ||
|
||
@BeforeAll | ||
public static void setUp() throws IOException { | ||
FileUtil.deleteDirectory(new File(".nf-test")); | ||
new File("nf-test.config").delete(); | ||
} | ||
|
||
@Test | ||
public void testSnapshotTransformer() throws Exception { | ||
|
||
App app = new App(); | ||
int exitCode = app.run(new String[] { "test", "test-data/snapshots/snapshot_transformer.nf.test" }); | ||
assertEquals(0, exitCode); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.