diff --git a/TMBuilder/README.md b/TMBuilder/README.md index e50e128..32103fb 100644 --- a/TMBuilder/README.md +++ b/TMBuilder/README.md @@ -24,6 +24,7 @@ Executable requires Java 8 or later. Download is available under [releases](http | Version | Notes | |---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 3.2.1 | Allow core validation set to be exported as developer mock. | | 3.2.0 | Adding null check option to each of the node types so it is possible to check for null response values. | | 3.1.2 | Fix check review bug and formatting. | | 3.1.1 | Fix export developer mock dialog selection messaging. Eliminating confusion around the file filter referencing Java and Kotlin classes which are not necessary when exporting developer mocks. | diff --git a/TMBuilder/pom.xml b/TMBuilder/pom.xml index 6f1b3c7..e7ef48a 100644 --- a/TMBuilder/pom.xml +++ b/TMBuilder/pom.xml @@ -8,7 +8,7 @@ 4.0.0 tmbuilder - 3.2.0 + 3.2.1 TMBuilder Thin Model Builder (TMBuilder) for NST thin models. diff --git a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/TMGuiConstants.java b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/TMGuiConstants.java index 1220f68..eb38939 100644 --- a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/TMGuiConstants.java +++ b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/TMGuiConstants.java @@ -2,7 +2,7 @@ public class TMGuiConstants { - public static final String APP_NAME = "TMBuilder v3.2.0"; + public static final String APP_NAME = "TMBuilder v3.2.1"; public static final int DEFAULT_WINDOW_WIDTH = 1000; public static final int DEFAULT_WINDOW_HEIGHT = 800; public static final String DICTIONARY_KEY = ""; diff --git a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/DeveloperMockExport.java b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/DeveloperMockExport.java index 2040181..23c63ba 100644 --- a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/DeveloperMockExport.java +++ b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/DeveloperMockExport.java @@ -32,23 +32,29 @@ public class DeveloperMockExport { public void export(File exportPath, List validationSetModels) throws IOException, ClassNotFoundException { ValidationSetModel coreValidationSet = getCoreValidationSet(validationSetModels); - + String validationSetName = coreValidationSet.getValidationSetName(); + validationSetName = camelCaseValidationSetName(validationSetName); + writeDeveloperMock(exportPath, validationSetName, getJsonFromValidationSet(coreValidationSet, coreValidationSet)); for (ValidationSetModel validationSetModel : validationSetModels) { String json = getJsonFromValidationSet(coreValidationSet, validationSetModel); - String validationSetName = validationSetModel.getValidationSetName(); + validationSetName = validationSetModel.getValidationSetName(); validationSetName = camelCaseValidationSetName(validationSetName); - String fileName = String.format(DEVELOPER_MOCK_FILE_NAME_FORMAT, validationSetName); - File exportFile = new File(exportPath, fileName); - FileWriter fileWriter = new FileWriter(exportFile); - fileWriter.write(json); - fileWriter.close(); + writeDeveloperMock(exportPath, validationSetName, json); } } + protected void writeDeveloperMock(File exportPath, String validationSetName, String json) throws IOException { + String fileName = String.format(DEVELOPER_MOCK_FILE_NAME_FORMAT, validationSetName); + File exportFile = new File(exportPath, fileName); + FileWriter fileWriter = new FileWriter(exportFile); + fileWriter.write(json); + fileWriter.close(); + } + public String getJsonFromValidationSet(ValidationSetModel coreValidationSet, ValidationSetModel customValidationSet) throws IOException, ClassNotFoundException { TreeMap coreValidationArrayPathToArraySizeMap = ArrayPathToArraySizeMapProcessor.getArrayPathToArraySizeMap(coreValidationSet); @@ -58,8 +64,10 @@ public String getJsonFromValidationSet(ValidationSetModel coreValidationSet, Val TreeMap arrayPathToArraySizeMap = new TreeMap<>(new SmallestToLargestArrayPathComparator()); arrayPathToArraySizeMap.putAll(coreValidationArrayPathToArraySizeMap); - TreeMap customValidationArrayPathToArraySizeMap = ArrayPathToArraySizeMapProcessor.getArrayPathToArraySizeMap(customValidationSet); - arrayPathToArraySizeMap.putAll(customValidationArrayPathToArraySizeMap); + if (customValidationSet != null) { + TreeMap customValidationArrayPathToArraySizeMap = ArrayPathToArraySizeMapProcessor.getArrayPathToArraySizeMap(customValidationSet); + arrayPathToArraySizeMap.putAll(customValidationArrayPathToArraySizeMap); + } // Build up the jsonMap structure. Map jsonMap = new HashMap<>(); @@ -67,7 +75,10 @@ public String getJsonFromValidationSet(ValidationSetModel coreValidationSet, Val // Populate the jsonMap with mock values. JsonMapPopulateProcessor.populateJsonMapWithMockValues(coreValidationSet, jsonMap); - JsonMapPopulateProcessor.populateJsonMapWithMockValues(customValidationSet, jsonMap); + + if (customValidationSet != null) { + JsonMapPopulateProcessor.populateJsonMapWithMockValues(customValidationSet, jsonMap); + } // Write the JSON to file. String json = gson.toJson(jsonMap); diff --git a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessor.java b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessor.java index 73e837a..6a0daa5 100644 --- a/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessor.java +++ b/TMBuilder/src/main/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessor.java @@ -25,10 +25,12 @@ public static Map getJsonMapForValidations(TreeMap validations = new ArrayList<>(); + validations.add(coreValidationSetModel); + validations.add(customValidationSetModel); + + exportMock.export(new File(System.getProperty("user.dir")), validations); + verify(exportMock, times(2)).writeDeveloperMock(Mockito.any(File.class), Mockito.anyString(), Mockito.anyString()); + } + + @Test + public void getCoreValidationSetByItself() throws Exception { + + DeveloperMockExport exportMock = Mockito.spy(DeveloperMockExport.class); + doNothing().when(exportMock).writeDeveloperMock(Mockito.any(File.class), Mockito.anyString(), Mockito.anyString()); + + ValidationSetModel coreValidationSetModel = Mockito.mock(ValidationSetModel.class); + when(coreValidationSetModel.getValidationSetName()).thenReturn(ExportConstants.CORE_VALIDATION_SET); + when(coreValidationSetModel.getData()).thenReturn(new NodeModel[0]); + + List validations = new ArrayList<>(); + validations.add(coreValidationSetModel); + + exportMock.export(new File(System.getProperty("user.dir")), validations); + verify(exportMock, times(1)).writeDeveloperMock(Mockito.any(File.class), Mockito.anyString(), Mockito.anyString()); + } + @Test public void getCoreValidationSet() throws IOException { diff --git a/TMBuilder/src/test/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessorTest.java b/TMBuilder/src/test/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessorTest.java index 2cdf479..7a83f6f 100644 --- a/TMBuilder/src/test/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessorTest.java +++ b/TMBuilder/src/test/java/com/ebay/tool/thinmodelgen/gui/menu/export/developer/mock/processor/JsonMapStructureProcessorTest.java @@ -32,6 +32,38 @@ public class JsonMapStructureProcessorTest { private JsonMapStructureProcessor processor = new JsonMapStructureProcessor(); private Gson gson = new GsonBuilder().serializeNulls().create();; + @Test + public void testGetJsonMapForValidationsCoreAndNullCustomValues() throws Exception { + + JsonBooleanType jsonBooleanType = new JsonBooleanType("Foo"); + jsonBooleanType.updateCheckForPath("$.foo.bar", new TMJPStringCheck()); + String booleanSerializedType = JsonBaseTypePersistence.serialize(jsonBooleanType); + + PathNode[] booleanPathNodes = new PathNode[4]; + booleanPathNodes[0] = new PathNode("$", "class com.ebay.tool.thinmodelgen.jsonschema.type.JsonObjectType", 0); + booleanPathNodes[1] = new PathNode("foo", "class com.ebay.tool.thinmodelgen.jsonschema.type.JsonObjectType", 0); + booleanPathNodes[3] = new PathNode("bar", "class com.ebay.tool.thinmodelgen.jsonschema.type.JsonBooleanType", 0); + + NodeModel booleanNodeModel = new NodeModel(booleanPathNodes, booleanSerializedType); + NodeModel[] coreNodeModel = new NodeModel[] {booleanNodeModel}; + ValidationSetModel coreValidationSet = new ValidationSetModel("core", coreNodeModel); + + TreeMap treeMap = new TreeMap<>(new SmallestToLargestArrayPathComparator()); + + Map actualJsonMap = processor.getJsonMapForValidations(treeMap, coreValidationSet, null); + + // Define expected + HashMap foo = new HashMap<>(); + foo.put("bar", null); + HashMap expectedJsonMap = new HashMap<>(); + expectedJsonMap.put("foo", foo); + + String actual = gson.toJson(actualJsonMap); + String expected = gson.toJson(expectedJsonMap); + + assertThat(actual, is(equalTo(expected))); + } + @Test public void testGetJsonMapForValidationsCoreAndCustom() throws Exception {