X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2FDcaeComponentTest.java;h=7f3b5709518367052860da5d2348964de0823a0a;hb=a2dbf1f653cba8c2d2835b36e8c89c9e41c5d1bb;hp=557fdcecf4a5df3d67b8a26443b238e1724e5233;hpb=5e4ad12350fb01cc690999b8096f0be7b7f1bdae;p=clamp.git diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java index 557fdcec..7f3b5709 100644 --- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java @@ -27,45 +27,55 @@ import static org.assertj.core.api.Assertions.assertThat; import com.google.gson.Gson; import com.google.gson.JsonObject; - import java.io.IOException; -import java.util.HashSet; - +import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.Message; +import org.json.simple.parser.ParseException; import org.junit.Test; import org.mockito.Mockito; +import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse; import org.onap.clamp.clds.model.dcae.DcaeOperationStatusResponse; import org.onap.clamp.loop.components.external.DcaeComponent; import org.onap.clamp.loop.components.external.ExternalComponentState; +import org.onap.clamp.loop.template.LoopTemplate; +import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.policy.microservice.MicroServicePolicy; public class DcaeComponentTest { private Loop createTestLoop() { - String yaml = "imports:\n" + " - \"http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\"\n" - + "node_templates:\n" + " docker_service_host:\n" + " type: dcae.nodes.SelectedDockerHost"; - - Loop loopTest = new Loop("ControlLoopTest", yaml, ""); + Loop loopTest = new Loop("ControlLoopTest", ""); loopTest.setGlobalPropertiesJson( - new Gson().fromJson("{\"dcaeDeployParameters\":" + "{\"policy_id\": \"name\"}}", JsonObject.class)); + new Gson().fromJson( + "{\"dcaeDeployParameters\":{\"uniqueBlueprintParameters\": {\"policy_id\": \"name\"}}}", + JsonObject.class)); loopTest.setLastComputedState(LoopState.DESIGN); loopTest.setDcaeDeploymentId("123456789"); loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085"); - loopTest.setDcaeBlueprintId("UUID-blueprint"); - MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", "", - "tosca_definitions_version: tosca_simple_yaml_1_0_0", true, - new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>()); - microServicePolicy.setProperties(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); + MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", new PolicyModel("policy1", + "tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0"), true, + new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, null, null); + microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); loopTest.addMicroServicePolicy(microServicePolicy); + LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null); + loopTemplate.setDcaeBlueprintId("UUID-blueprint"); + loopTest.setLoopTemplate(loopTemplate); + return loopTest; } + /** + * Test the DcaeReponse roughly. + * + * @throws IOException In case of issues + */ @Test public void convertDcaeResponseTest() throws IOException { - String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state','error':'errorMessage', 'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}"; + String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state'," + + "'error':'errorMessage', 'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}"; DcaeOperationStatusResponse responseObject = DcaeComponent.convertDcaeResponse(dcaeFakeResponse); assertThat(responseObject.getRequestId()).isEqualTo("testId"); assertThat(responseObject.getOperationType()).isEqualTo("install"); @@ -94,6 +104,11 @@ public class DcaeComponentTest { assertThat(unDeploymentPayload).isEqualTo(expectedPayload); } + /** + * Test the computeState method of the DcaeComponent roughly. + * + * @throws IOException In case of issues + */ @Test public void computeStateTest() throws IOException { Exchange exchange = Mockito.mock(Exchange.class); @@ -110,7 +125,7 @@ public class DcaeComponentTest { assertThat(state.getStateName()).isEqualTo("BLUEPRINT_DEPLOYED"); // OperationalType = install - DcaeOperationStatusResponse dcaeResponse = Mockito.mock(DcaeOperationStatusResponse.class); + DcaeOperationStatusResponse dcaeResponse = Mockito.mock(DcaeOperationStatusResponse.class); Mockito.when(dcaeResponse.getOperationType()).thenReturn("install"); Mockito.when(dcaeResponse.getStatus()).thenReturn("succeeded"); @@ -151,4 +166,49 @@ public class DcaeComponentTest { ExternalComponentState state9 = dcae.computeState(exchange); assertThat(state9.getStateName()).isEqualTo("IN_ERROR"); } + + /** + * Test the Converter to DcaeInventoryResponse method. + * + * @throws IOException In case of failure + * @throws ParseException In case of failure + */ + @Test + public void convertToDcaeInventoryResponseTest() throws IOException, ParseException { + String dcaeFakeResponse = "{\n" + " \"links\": {\n" + " \"previousLink\": {\n" + + " \"title\": \"string\",\n" + " \"rel\": \"string\",\n" + " \"uri\": \"string\",\n" + + " \"uriBuilder\": {},\n" + " \"rels\": [\n" + " \"string\"\n" + " ],\n" + + " \"params\": {\n" + " \"additionalProp1\": \"string\",\n" + + " \"additionalProp2\": \"string\",\n" + " \"additionalProp3\": \"string\"\n" + + " },\n" + " \"type\": \"string\"\n" + " },\n" + " \"nextLink\": {\n" + + " \"title\": \"string\",\n" + " \"rel\": \"string\",\n" + " \"uri\": \"string\",\n" + + " \"uriBuilder\": {},\n" + " \"rels\": [\n" + " \"string\"\n" + " ],\n" + + " \"params\": {\n" + " \"additionalProp1\": \"string\",\n" + + " \"additionalProp2\": \"string\",\n" + " \"additionalProp3\": \"string\"\n" + + " },\n" + " \"type\": \"string\"\n" + " }\n" + " },\n" + " \"totalCount\": 0,\n" + + " \"items\": [\n" + " {\n" + " \"owner\": \"testOwner\",\n" + + " \"application\": \"testApplication\",\n" + " \"component\": \"testComponent\",\n" + + " \"typeName\": \"testTypeName\",\n" + " \"typeVersion\": 0,\n" + + " \"blueprintTemplate\": \"testBlueprintTemplate\",\n" + " \"serviceIds\": [\n" + + " \"serviceId1\", \"serviceId2\"\n" + " ],\n" + " \"vnfTypes\": [\n" + + " \"vnfType1\", \"vnfType2\"\n" + " ],\n" + " \"serviceLocations\": [\n" + + " \"serviceLocation1\", \"serviceLocation2\"\n" + " ],\n" + + " \"asdcServiceId\": \"testAsdcServiceId\",\n" + + " \"asdcResourceId\": \"testAsdcResourceId\",\n" + + " \"asdcServiceURL\": \"testAsdcServiceURL\",\n" + " \"typeId\": \"testTypeId\",\n" + + " \"selfLink\": {\n" + " \"title\": \"selfLinkTitle\",\n" + + " \"rel\": \"selfLinkRel\",\n" + " \"uri\": \"selfLinkUri\",\n" + + " \"uriBuilder\": {},\n" + " \"rels\": [\n" + " \"string\"\n" + " ],\n" + + " \"params\": {\n" + " \"additionalProp1\": \"string\",\n" + + " \"additionalProp2\": \"string\",\n" + " \"additionalProp3\": \"string\"\n" + + " },\n" + " \"type\": \"string\"\n" + " },\n" + + " \"created\": \"2020-01-22T09:38:15.436Z\",\n" + + " \"deactivated\": \"2020-01-22T09:38:15.437Z\"\n" + " }\n" + " ]\n" + "}"; + List responseObject = DcaeComponent.convertToDcaeInventoryResponse(dcaeFakeResponse); + assertThat(responseObject.get(0).getAsdcResourceId()).isEqualTo("testAsdcResourceId"); + assertThat(responseObject.get(0).getAsdcServiceId()).isEqualTo("testAsdcServiceId"); + assertThat(responseObject.get(0).getTypeName()).isEqualTo("testTypeName"); + assertThat(responseObject.get(0).getTypeId()).isEqualTo("testTypeId"); + assertThat(responseObject.get(0).getBlueprintTemplate()).isEqualTo("testBlueprintTemplate"); + } }