From 504df70f2b210488f77274915ce8652d56978e18 Mon Sep 17 00:00:00 2001 From: sebdet Date: Thu, 30 Jan 2020 10:15:03 +0100 Subject: Add a unit test Add a test on Blueprint parser to validate a specific case Issue-ID: CLAMP-567 Change-Id: I2f0ed17bd8fd203b055fcb26614e747afcf85d9a Signed-off-by: sebdet --- .../controller/installer/BlueprintParserTest.java | 39 ++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/test/java/org/onap') diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java index dcaf2b95..e48bfc44 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java @@ -25,6 +25,8 @@ package org.onap.clamp.clds.sdc.controller.installer; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -57,7 +59,7 @@ public class BlueprintParserTest { private static String microServiceTheWholeBlueprintValid; private static String microServiceBlueprintOldStyleTCA; private static String microServiceBlueprintOldStyleHolmes; - + private static String newMicroServiceBlueprint; private static JsonObject jsonObjectBlueprintValid; private static JsonObject jsonObjectBlueprintWithoutName; private static JsonObject jsonObjectBlueprintWithoutProperties; @@ -66,22 +68,22 @@ public class BlueprintParserTest { /** * Method to load Blueprints before all test. * - * @throws IOException - * In case of issues when opening the files + * @throws IOException In case of issues when opening the files */ @BeforeClass public static void loadBlueprints() throws IOException { microServiceTheWholeBlueprintValid = ResourceFileUtil - .getResourceAsString("clds/blueprint-with-microservice-chain.yaml"); + .getResourceAsString("clds/blueprint-with-microservice-chain.yaml"); microServiceBlueprintOldStyleTCA = ResourceFileUtil.getResourceAsString("clds/tca-old-style-ms.yaml"); + newMicroServiceBlueprint = ResourceFileUtil.getResourceAsString("clds/new-microservice.yaml"); microServiceBlueprintOldStyleHolmes = ResourceFileUtil.getResourceAsString("clds/holmes-old-style-ms.yaml"); String microServiceBlueprintValid = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-valid.yaml"); + .getResourceAsString("clds/single-microservice-fragment-valid.yaml"); String microServiceBlueprintWithoutName = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-without-name.yaml"); + .getResourceAsString("clds/single-microservice-fragment-without-name.yaml"); String microServiceBlueprintWithoutProperties = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-without-properties.yaml"); + .getResourceAsString("clds/single-microservice-fragment-without-properties.yaml"); jsonObjectBlueprintValid = yamlToJson(microServiceBlueprintValid); jsonObjectBlueprintWithoutName = yamlToJson(microServiceBlueprintWithoutName); @@ -97,7 +99,7 @@ public class BlueprintParserTest { public void getNameShouldReturnDefinedName() { final JsonObject jsonObject = jsonObjectBlueprintValid; String expectedName = jsonObject.get(jsonObject.keySet().iterator().next()).getAsJsonObject().get("properties") - .getAsJsonObject().get("name").getAsString(); + .getAsJsonObject().get("name").getAsString(); Entry entry = jsonObject.entrySet().iterator().next(); String actualName = new BlueprintParser().getName(entry); @@ -174,8 +176,8 @@ public class BlueprintParserTest { @Test public void fallBackToOneMicroServiceTcaTest() { - MicroService tcaMs = new MicroService(BlueprintParser.TCA, - "onap.policies.monitoring.cdap.tca.hi.lo.app", "", ""); + MicroService tcaMs = new MicroService(BlueprintParser.TCA, "onap.policies.monitoring.cdap.tca.hi.lo.app", "", + ""); List expected = Collections.singletonList(tcaMs); List actual = new BlueprintParser().fallbackToOneMicroService(microServiceBlueprintOldStyleTCA); @@ -184,16 +186,27 @@ public class BlueprintParserTest { @Test public void fallBackToOneMicroServiceHolmesTest() { - MicroService holmesMs = new MicroService(BlueprintParser.HOLMES, - "onap.policies.monitoring.cdap.tca.hi.lo.app", "", ""); + MicroService holmesMs = new MicroService(BlueprintParser.HOLMES, "onap.policies.monitoring.cdap.tca.hi.lo.app", + "", ""); List expected = Collections.singletonList(holmesMs); List actual = new BlueprintParser() - .fallbackToOneMicroService(microServiceBlueprintOldStyleHolmes); + .fallbackToOneMicroService(microServiceBlueprintOldStyleHolmes); Assert.assertEquals(expected, actual); } + @Test + public void newMicroServiceTest() { + List microServicesChain = new ChainGenerator() + .getChainOfMicroServices(new BlueprintParser().getMicroServices(newMicroServiceBlueprint)); + if (microServicesChain.isEmpty()) { + microServicesChain = new BlueprintParser().fallbackToOneMicroService(newMicroServiceBlueprint); + } + assertThat(microServicesChain.size()).isEqualTo(1); + assertThat(microServicesChain.get(0).getName()).isEqualTo("pmsh"); + } + private static JsonObject yamlToJson(String yamlString) { Yaml yaml = new Yaml(); Map map = yaml.load(yamlString); -- cgit 1.2.3-korg