X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fsdc%2Fcontroller%2Finstaller%2FBlueprintParserTest.java;h=a768526a0664f7c1703c6a93e4cf8a2dec296d71;hb=536db7b811eba341aef48a745b495da068d170eb;hp=2a2ab94e617da13007164f49ca4698277f69f094;hpb=60e5cc9c7768ddda104069f7773fb636f77587e8;p=clamp.git 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 2a2ab94e..a768526a 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 @@ -5,6 +5,8 @@ * Copyright (C) 2019 Nokia Intellectual Property. All rights * reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,8 +22,11 @@ * =================================================================== * */ + 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; @@ -37,7 +42,8 @@ import org.json.JSONObject; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.clds.exception.sdc.controller.BlueprintParserException; +import org.onap.clamp.clds.util.ResourceFileUtils; import org.yaml.snakeyaml.Yaml; public class BlueprintParserTest { @@ -45,50 +51,56 @@ public class BlueprintParserTest { private static final String FIRST_APPP = "first_app"; private static final String SECOND_APPP = "second_app"; private static final String THIRD_APPP = "third_app"; + private static final String MODEL_TYPE1 = "type1"; + private static final String MODEL_TYPE_TCA = "onap.policies.monitoring.cdap.tca.hi.lo.app"; + private static final String VERSION = "1.0.0"; private static String microServiceTheWholeBlueprintValid; - private static String microServiceBlueprintOldStyleTCA; - private static String microServiceBlueprintOldStyleHolmes; - - private static JsonObject jsonObjectBlueprintValid; + private static String newMicroServiceBlueprint; + private static JsonObject jsonObjectBlueprintInvalid; private static JsonObject jsonObjectBlueprintWithoutName; private static JsonObject jsonObjectBlueprintWithoutProperties; private static JsonObject jsonObjectBlueprintWithoutRelationships; + private static JsonObject jsonObjectBlueprintValidWithVersion; + /** + * Method to load Blueprints before all test. + * + * @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"); - microServiceBlueprintOldStyleTCA = ResourceFileUtil - .getResourceAsString("clds/tca-old-style-ms.yaml"); - microServiceBlueprintOldStyleHolmes = ResourceFileUtil - .getResourceAsString("clds/holmes-old-style-ms.yaml"); - - String microServiceBlueprintValid = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-valid.yaml"); - String microServiceBlueprintWithoutName = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-without-name.yaml"); - String microServiceBlueprintWithoutProperties = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-without-properties.yaml"); - String microServiceBlueprintWithoutRelationships = ResourceFileUtil - .getResourceAsString("clds/single-microservice-fragment-without-relationships.yaml"); - - jsonObjectBlueprintValid = yamlToJson(microServiceBlueprintValid); + microServiceTheWholeBlueprintValid = ResourceFileUtils + .getResourceAsString("clds/blueprint-with-microservice-chain.yaml"); + + newMicroServiceBlueprint = ResourceFileUtils.getResourceAsString("clds/new-microservice.yaml"); + + String microServiceBlueprintInvalid = ResourceFileUtils + .getResourceAsString("clds/single-microservice-fragment-invalid.yaml"); + jsonObjectBlueprintInvalid = yamlToJson(microServiceBlueprintInvalid); + String microServiceBlueprintWithoutName = ResourceFileUtils + .getResourceAsString("clds/single-microservice-fragment-without-name.yaml"); jsonObjectBlueprintWithoutName = yamlToJson(microServiceBlueprintWithoutName); + String microServiceBlueprintWithoutProperties = ResourceFileUtils + .getResourceAsString("clds/single-microservice-fragment-without-properties.yaml"); jsonObjectBlueprintWithoutProperties = yamlToJson(microServiceBlueprintWithoutProperties); + String microServiceBlueprintValidWithVersion = ResourceFileUtils + .getResourceAsString("clds/single-microservice-fragment-valid-with-version.yaml"); + jsonObjectBlueprintValidWithVersion = yamlToJson(microServiceBlueprintValidWithVersion); + + String microServiceBlueprintWithoutRelationships = ResourceFileUtils + .getResourceAsString("clds/single-microservice-fragment-without-relationships.yaml"); jsonObjectBlueprintWithoutRelationships = yamlToJson(microServiceBlueprintWithoutRelationships); } @Test public void getNameShouldReturnDefinedName() { - final JsonObject jsonObject = jsonObjectBlueprintValid; - String expectedName = jsonObject.get(jsonObject.keySet().iterator().next()) - .getAsJsonObject().get("properties") - .getAsJsonObject().get("name") - .getAsString(); + final JsonObject jsonObject = jsonObjectBlueprintInvalid; + String expectedName = jsonObject.get(jsonObject.keySet().iterator().next()).getAsJsonObject().get("properties") + .getAsJsonObject().get("name").getAsString(); Entry entry = jsonObject.entrySet().iterator().next(); - String actualName = new BlueprintParser().getName(entry); + String actualName = BlueprintParser.getName(entry); Assert.assertEquals(expectedName, actualName); } @@ -99,7 +111,7 @@ public class BlueprintParserTest { String expectedName = jsonObject.keySet().iterator().next(); Entry entry = jsonObject.entrySet().iterator().next(); - String actualName = new BlueprintParser().getName(entry); + String actualName = BlueprintParser.getName(entry); Assert.assertEquals(expectedName, actualName); } @@ -110,18 +122,18 @@ public class BlueprintParserTest { String expectedName = jsonObject.keySet().iterator().next(); Entry entry = jsonObject.entrySet().iterator().next(); - String actualName = new BlueprintParser().getName(entry); + String actualName = BlueprintParser.getName(entry); Assert.assertEquals(expectedName, actualName); } @Test public void getInputShouldReturnInputWhenPresent() { - final JsonObject jsonObject = jsonObjectBlueprintValid; + final JsonObject jsonObject = jsonObjectBlueprintInvalid; String expected = FIRST_APPP; Entry entry = jsonObject.entrySet().iterator().next(); - String actual = new BlueprintParser().getInput(entry); + String actual = BlueprintParser.getInput(entry); Assert.assertEquals(expected, actual); } @@ -132,53 +144,59 @@ public class BlueprintParserTest { String expected = ""; Entry entry = jsonObject.entrySet().iterator().next(); - String actual = new BlueprintParser().getInput(entry); + String actual = BlueprintParser.getInput(entry); Assert.assertEquals(expected, actual); } + @Test(expected = BlueprintParserException.class) + public void getNodeRepresentationFromIncompleteYaml() throws BlueprintParserException { + BlueprintParser.getNodeRepresentation(jsonObjectBlueprintInvalid.entrySet().iterator().next(), + jsonObjectBlueprintInvalid, null); + } + @Test - public void getNodeRepresentationFromCompleteYaml() { - final JsonObject jsonObject = jsonObjectBlueprintValid; + public void getNodeRepresentationFromCompleteYamlWithModelVersion() throws BlueprintParserException { + final JsonObject jsonObject = jsonObjectBlueprintValidWithVersion; - MicroService expected = new MicroService(SECOND_APPP, FIRST_APPP); + BlueprintMicroService expected = new BlueprintMicroService(SECOND_APPP, MODEL_TYPE1, "", "10.0.0"); Entry entry = jsonObject.entrySet().iterator().next(); - MicroService actual = new BlueprintParser().getNodeRepresentation(entry); + BlueprintMicroService actual = BlueprintParser.getNodeRepresentation(entry, jsonObject, null); Assert.assertEquals(expected, actual); } @Test - public void getMicroServicesFromBlueprintTest() { - MicroService thirdApp = new MicroService(THIRD_APPP, ""); - MicroService firstApp = new MicroService(FIRST_APPP, THIRD_APPP); - MicroService secondApp = new MicroService(SECOND_APPP, FIRST_APPP); + public void getMicroServicesFromBlueprintTest() throws BlueprintParserException { + BlueprintMicroService thirdApp = new BlueprintMicroService(THIRD_APPP, MODEL_TYPE_TCA, SECOND_APPP, VERSION); + BlueprintMicroService firstApp = new BlueprintMicroService(FIRST_APPP, MODEL_TYPE_TCA, "", VERSION); + BlueprintMicroService secondApp = new BlueprintMicroService(SECOND_APPP, MODEL_TYPE_TCA, FIRST_APPP, VERSION); - Set expected = new HashSet<>(Arrays.asList(firstApp, secondApp, thirdApp)); - Set actual = new BlueprintParser().getMicroServices(microServiceTheWholeBlueprintValid); + Set expected = new HashSet<>(Arrays.asList(firstApp, secondApp, thirdApp)); + Set actual = BlueprintParser.getMicroServices(microServiceTheWholeBlueprintValid); Assert.assertEquals(expected, actual); } @Test - public void fallBackToOneMicroServiceTCATest() { - MicroService tcaMS = new MicroService(BlueprintParser.TCA, ""); - - List expected = Collections.singletonList(tcaMS); - List actual = new BlueprintParser().fallbackToOneMicroService(microServiceBlueprintOldStyleTCA); + public void fallBackToOneMicroServiceTcaTest() { + BlueprintMicroService tcaMs = new BlueprintMicroService(BlueprintParser.TCA, + "onap.policies.monitoring.cdap.tca.hi.lo.app", "", VERSION); + List expected = Collections.singletonList(tcaMs); + List actual = BlueprintParser.fallbackToOneMicroService(); Assert.assertEquals(expected, actual); } @Test - public void fallBackToOneMicroServiceHolmesTest() { - MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, ""); - - List expected = Collections.singletonList(holmesMS); - List actual = - new BlueprintParser().fallbackToOneMicroService(microServiceBlueprintOldStyleHolmes); - - Assert.assertEquals(expected, actual); + public void newMicroServiceTest() throws BlueprintParserException { + List microServicesChain = new ChainGenerator() + .getChainOfMicroServices(BlueprintParser.getMicroServices(newMicroServiceBlueprint)); + if (microServicesChain.isEmpty()) { + microServicesChain = BlueprintParser.fallbackToOneMicroService(); + } + assertThat(microServicesChain.size()).isEqualTo(1); + assertThat(microServicesChain.get(0).getName()).isEqualTo("pmsh"); } private static JsonObject yamlToJson(String yamlString) {