diff options
author | Xue Gao <xg353y@intl.att.com> | 2020-01-30 12:50:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-01-30 12:50:39 +0000 |
commit | 32d2e29dc6d751c2053a130238526144ab46912c (patch) | |
tree | 35b93ca7fb4a382ab7f1bad917977fd845923bd6 /src/test | |
parent | a84ea55e9291f5c3af9ac3a3ae6ca31d860f1566 (diff) | |
parent | 504df70f2b210488f77274915ce8652d56978e18 (diff) |
Merge "Add a unit test"
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java | 39 | ||||
-rw-r--r-- | src/test/resources/clds/new-microservice.yaml | 46 |
2 files changed, 72 insertions, 13 deletions
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 dcaf2b952..e48bfc44a 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<String, JsonElement> 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<MicroService> expected = Collections.singletonList(tcaMs); List<MicroService> 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<MicroService> expected = Collections.singletonList(holmesMs); List<MicroService> actual = new BlueprintParser() - .fallbackToOneMicroService(microServiceBlueprintOldStyleHolmes); + .fallbackToOneMicroService(microServiceBlueprintOldStyleHolmes); Assert.assertEquals(expected, actual); } + @Test + public void newMicroServiceTest() { + List<MicroService> 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<String, Object> map = yaml.load(yamlString); diff --git a/src/test/resources/clds/new-microservice.yaml b/src/test/resources/clds/new-microservice.yaml new file mode 100644 index 000000000..70c1eda46 --- /dev/null +++ b/src/test/resources/clds/new-microservice.yaml @@ -0,0 +1,46 @@ +tosca_definitions_version: cloudify_dsl_1_3 + +imports: + - "http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml" + - "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R5/k8splugin/1.4.13/k8splugin_types.yaml" + - "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R5/clamppolicyplugin/1.0.0/clamppolicyplugin_types.yaml" + +inputs: + tag_version: + type: string + description: docker image + policy_model_id: + type: 'string' + default: 'onap.policies.monitoring.dcae-pm-initiation-handler' + policy_id: + type: 'string' + default: 'onap.policies.monitoring.dcae-pm-initiation-handler' + +node_templates: + pmsh: + relationships: + - type: cloudify.relationships.depends_on + target: pmsh-policy + + interfaces: + cloudify.interfaces.lifecycle: + start: + inputs: + ports: + - '8443:0' + - '8081:0' + properties: + image: + get_input: tag_version + replicas: 1 + service_component_type: "pmsh" + service_component_name_override: "pmsh" + type: dcae.nodes.ContainerizedServiceComponent + + pmsh-policy: + type: clamp.nodes.policy + properties: + policy_model_id: + get_input: policy_model_id + policy_id: + get_input: policy_id |