From daab14bd058de198c80b71d63e108fd788b7f5ee Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Mon, 26 Jul 2021 12:00:59 -0400 Subject: Revert "Renaming Files having BluePrint to have Blueprint" The renaming in CCSDK-3098 caused breaking changes to the grpc api and compile issues for kotlin scripts. Issue-ID: CCSDK-3385 Change-Id: I0d745cb858371678eabcb2284671c1fd76a1ab6d Signed-off-by: Jozsef Csongvai --- .../core/BluePrintErrorTest.kt | 33 ++ .../core/BlueprintErrorTest.kt | 33 -- .../core/CustomFunctionsTest.kt | 16 +- .../controllerblueprints/core/MDCContextTest.kt | 6 +- .../core/annotations/BluePrintsAnnotationsTest.kt | 119 +++++ .../core/annotations/BlueprintsAnnotationsTest.kt | 119 ----- .../core/dsl/BluePrintDSLTest.kt | 318 +++++++++++ .../core/dsl/BlueprintDSLTest.kt | 318 ----------- .../scripts/BluePrintScriptsServiceImplTest.kt | 88 +++ .../scripts/BlueprintScriptsServiceImplTest.kt | 88 --- .../core/service/BluePrintContextTest.kt | 588 +++++++++++++++++++++ .../core/service/BluePrintExpressionServiceTest.kt | 140 +++++ .../core/service/BluePrintRepoFileServiceTest.kt | 58 ++ .../core/service/BluePrintRuntimeServiceTest.kt | 299 +++++++++++ .../core/service/BluePrintTemplateServiceTest.kt | 82 +++ .../core/service/BluePrintWorkflowServiceTest.kt | 272 ++++++++++ .../core/service/BlueprintContextTest.kt | 588 --------------------- .../core/service/BlueprintExpressionServiceTest.kt | 140 ----- .../core/service/BlueprintRepoFileServiceTest.kt | 58 -- .../core/service/BlueprintRuntimeServiceTest.kt | 299 ----------- .../core/service/BlueprintTemplateServiceTest.kt | 82 --- .../core/service/BlueprintWorkflowServiceTest.kt | 272 ---------- .../core/utils/BluePrintFileUtilsTest.kt | 57 ++ .../core/utils/BluePrintIOUtilsTest.kt | 41 ++ .../core/utils/BluePrintMetadataUtilsTest.kt | 82 +++ .../core/utils/BlueprintFileUtilsTest.kt | 57 -- .../core/utils/BlueprintIOUtilsTest.kt | 41 -- .../core/utils/BlueprintMetadataUtilsTest.kt | 82 --- .../core/utils/JacksonUtilsTest.kt | 16 +- .../core/utils/PropertyDefinitionUtilsTest.kt | 2 +- .../Scripts/kotlin/ActivateBlueprintDefinitions.kt | 12 +- 31 files changed, 2203 insertions(+), 2203 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintErrorTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BluePrintsAnnotationsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BlueprintsAnnotationsTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BlueprintDSLTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptsServiceImplTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContextTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContextTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintExpressionServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRepoFileServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRuntimeServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintWorkflowServiceTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt create mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintFileUtilsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintIOUtilsTest.kt delete mode 100644 ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintMetadataUtilsTest.kt (limited to 'ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test') diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintErrorTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintErrorTest.kt new file mode 100644 index 000000000..167c0381a --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintErrorTest.kt @@ -0,0 +1,33 @@ +package org.onap.ccsdk.cds.controllerblueprints.core + +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class BluePrintErrorTest { + + @Test + fun testBluePrintErrorIsCreatedWithemptyList() { + val bluePrintError = BluePrintError() + + assertTrue(bluePrintError.allErrors().isEmpty()) + } + + @Test + fun testAddErrorWith3Params() { + val bluePrintError = BluePrintError() + + bluePrintError.addError("type", "name", "error", "step") + + assertEquals("type : name : error", bluePrintError.stepErrors("step")!![0]) + } + + @Test + fun testAddErrorWith2Params() { + val bluePrintError = BluePrintError() + + bluePrintError.addError("error", "step") + + assertEquals("error", bluePrintError.stepErrors("step")!![0]) + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt deleted file mode 100644 index 94ba98603..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BlueprintErrorTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.onap.ccsdk.cds.controllerblueprints.core - -import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class BlueprintErrorTest { - - @Test - fun testBlueprintErrorIsCreatedWithemptyList() { - val bluePrintError = BlueprintError() - - assertTrue(bluePrintError.allErrors().isEmpty()) - } - - @Test - fun testAddErrorWith3Params() { - val bluePrintError = BlueprintError() - - bluePrintError.addError("type", "name", "error", "step") - - assertEquals("type : name : error", bluePrintError.stepErrors("step")!![0]) - } - - @Test - fun testAddErrorWith2Params() { - val bluePrintError = BlueprintError() - - bluePrintError.addError("error", "step") - - assertEquals("error", bluePrintError.stepErrors("step")!![0]) - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt index 8c1e9f65f..7ac9b8649 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt @@ -95,13 +95,13 @@ class CustomFunctionsTest { val returnValueBool: JsonNode = false.asJsonType() assertFalse(returnValueBool.asBoolean()) - val returnValue: JsonNode = BlueprintError().asJsonType() + val returnValue: JsonNode = BluePrintError().asJsonType() assertEquals(JsonNodeType.OBJECT, returnValue.getNodeType()) } @Test fun testMapAsObjectNode() { - val returnValue: ObjectNode = hashMapOf("test" to BlueprintError()).asObjectNode() + val returnValue: ObjectNode = hashMapOf("test" to BluePrintError()).asObjectNode() assertNotNull(returnValue.get("test")) } @@ -121,7 +121,7 @@ class CustomFunctionsTest { assertNull(returnValueString) } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testCastValue() { val initMap: Map = hashMapOf("test" to 1.1) val returnValue = initMap.castValue("test", Number::class) @@ -178,7 +178,7 @@ class CustomFunctionsTest { assertTrue("[{\"key\": \"value\"},{\"key\": \"value\"}]".asJsonType().isComplexType()) } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testRootFieldsToMap() { 1.asJsonType().rootFieldsToMap() } @@ -192,7 +192,7 @@ class CustomFunctionsTest { assertEquals(3, mutMap["hello"]?.asInt()) } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testMapGetAsString() { val initMap = hashMapOf("test" to "hello".asJsonType()) @@ -201,7 +201,7 @@ class CustomFunctionsTest { initMap.getAsString("test2") } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testMapGetAsBoolean() { val initMap = hashMapOf("test" to true.asJsonType()) @@ -210,7 +210,7 @@ class CustomFunctionsTest { initMap.getAsBoolean("test2") } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testMapGetAsInt() { val initMap = hashMapOf("test" to 1.asJsonType()) @@ -219,7 +219,7 @@ class CustomFunctionsTest { initMap.getAsInt("test2") } - @Test(expected = BlueprintException::class) + @Test(expected = BluePrintException::class) fun testCheckEquals() { assertTrue(checkEquals("hello", "hello", { -> "error" })) diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt index 0fe2fbf7f..643549be0 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/MDCContextTest.kt @@ -41,14 +41,14 @@ class MDCContextTest { @Test fun testContextCanBePassedBetweenCoroutines() { - MDC.put(BlueprintConstants.ONAP_REQUEST_ID, "12345") + MDC.put(BluePrintConstants.ONAP_REQUEST_ID, "12345") runBlocking { GlobalScope.launch { - assertEquals(null, MDC.get(BlueprintConstants.ONAP_REQUEST_ID)) + assertEquals(null, MDC.get(BluePrintConstants.ONAP_REQUEST_ID)) } launch(MDCContext()) { assertEquals( - "12345", MDC.get(BlueprintConstants.ONAP_REQUEST_ID), + "12345", MDC.get(BluePrintConstants.ONAP_REQUEST_ID), "couldn't get request id" ) diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BluePrintsAnnotationsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BluePrintsAnnotationsTest.kt new file mode 100644 index 000000000..a75262f96 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BluePrintsAnnotationsTest.kt @@ -0,0 +1,119 @@ +/* + * Copyright © 2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.annotations + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.asBluePrintsDataTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asPropertyDefinitionMap +import kotlin.test.Test +import kotlin.test.assertNotNull + +class BluePrintsAnnotationsTest { + + @Test + fun testBluePrintWorkflowData() { + val wfInput = TestBluePrintsWorkflowInput::class.asPropertyDefinitionMap() + // println(wfInput.asJsonString(true)) + assertNotNull(wfInput, "failed to generate wfInput property map") + + val wfOutput = TestBluePrintsWorkflowOutput::class.asPropertyDefinitionMap() + // println(wfOutput.asJsonString(true)) + assertNotNull(wfInput, "failed to generate wfOutput property map") + } + + @Test + fun testBluePrintDataType() { + val dataTypes = TestBluePrintsDataType::class.asBluePrintsDataTypes() + // println(dataTypes.asJsonString(true)) + assertNotNull(dataTypes, "failed to generate dataTypes definition") + } +} + +@BluePrintsDataType( + name = "dt-test-datatype", description = "I am test", + version = "1.0.0", derivedFrom = "tosca.datatypes.root" +) +data class TestBluePrintsDataType( + @BluePrintsProperty(description = "this stringData") + var stringData: String, + @BluePrintsProperty(description = "this stringDataWithValue") + @PropertyDefaultValue(value = "USA") + val stringDataWithValue: String, + @BluePrintsProperty(description = "this intDataWithValue") + @PropertyDefaultValue(value = "30") + val intDataWithValue: Int, + @BluePrintsProperty(description = "this booleanDataWithValue") + @PropertyDefaultValue(value = "true") + val booleanDataWithValue: Boolean, + @BluePrintsProperty(description = "this anyData") + val anyData: Any, + @BluePrintsProperty(description = "this jsonDataWithValue") + @PropertyDefaultValue(value = """{"data" : "1234"}""") + val jsonDataWithValue: JsonNode?, + @BluePrintsProperty(description = "listData") + val listData: MutableList, + @BluePrintsProperty(description = "this mapData") + val mapData: MutableMap = hashMapOf(), + @BluePrintsProperty(description = "this complexData") + val complexData: TestBluePrintsChildDataType?, + @BluePrintsProperty(description = "this complexDataList") + val complexDataList: MutableList +) + +data class TestBluePrintsChildDataType(val name: String) + +@BluePrintsWorkflowInput +data class TestBluePrintsWorkflowInput( + @BluePrintsProperty(description = "this sample name") + @PropertyDefaultValue(value = "Brinda") + var name: String, + @BluePrintsProperty(description = "this sample name") + val place: String +) + +@BluePrintsWorkflowOutput +data class TestBluePrintsWorkflowOutput( + @BluePrintsProperty(description = "this is dslExpression") + @DSLExpression("field1") + var dslExpression: String, + + @BluePrintsProperty(description = "this is withNodeAttributeExpression") + @AttributeExpression(modelableEntityName = "sample-node", attributeName = "response-data") + var withNodeAttributeExpression: String, + + @BluePrintsProperty(description = "this is withNodeAttributeExpressionSubAttribute") + @AttributeExpression( + modelableEntityName = "sample-node", attributeName = "response-data", + subAttributeName = ".\$field1" + ) + var withNodeAttributeExpressionSubAttribute: String, + + @BluePrintsProperty(description = "this is withAttributeExpressionSubAttribute") + @AttributeExpression(attributeName = "response-data", subAttributeName = ".\$field1") + var withAttributeExpressionSubAttribute: String, + + @BluePrintsProperty(description = "this is withAttributeExpression") + @AttributeExpression(attributeName = "response-data") + var withAttributeExpression: String, + + @BluePrintsProperty(description = "this is withAArtifactExpression") + @ArtifactExpression(modelableEntityName = "test-node", artifactName = "content-template") + var withAArtifactExpression: String, + + @BluePrintsProperty(description = "this status") + val status: String = "success" +) diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BlueprintsAnnotationsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BlueprintsAnnotationsTest.kt deleted file mode 100644 index b19c3502a..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/annotations/BlueprintsAnnotationsTest.kt +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.annotations - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.cds.controllerblueprints.core.asBlueprintsDataTypes -import org.onap.ccsdk.cds.controllerblueprints.core.asPropertyDefinitionMap -import kotlin.test.Test -import kotlin.test.assertNotNull - -class BlueprintsAnnotationsTest { - - @Test - fun testBlueprintWorkflowData() { - val wfInput = TestBlueprintsWorkflowInput::class.asPropertyDefinitionMap() - // println(wfInput.asJsonString(true)) - assertNotNull(wfInput, "failed to generate wfInput property map") - - val wfOutput = TestBlueprintsWorkflowOutput::class.asPropertyDefinitionMap() - // println(wfOutput.asJsonString(true)) - assertNotNull(wfInput, "failed to generate wfOutput property map") - } - - @Test - fun testBlueprintDataType() { - val dataTypes = TestBlueprintsDataType::class.asBlueprintsDataTypes() - // println(dataTypes.asJsonString(true)) - assertNotNull(dataTypes, "failed to generate dataTypes definition") - } -} - -@BlueprintsDataType( - name = "dt-test-datatype", description = "I am test", - version = "1.0.0", derivedFrom = "tosca.datatypes.root" -) -data class TestBlueprintsDataType( - @BlueprintsProperty(description = "this stringData") - var stringData: String, - @BlueprintsProperty(description = "this stringDataWithValue") - @PropertyDefaultValue(value = "USA") - val stringDataWithValue: String, - @BlueprintsProperty(description = "this intDataWithValue") - @PropertyDefaultValue(value = "30") - val intDataWithValue: Int, - @BlueprintsProperty(description = "this booleanDataWithValue") - @PropertyDefaultValue(value = "true") - val booleanDataWithValue: Boolean, - @BlueprintsProperty(description = "this anyData") - val anyData: Any, - @BlueprintsProperty(description = "this jsonDataWithValue") - @PropertyDefaultValue(value = """{"data" : "1234"}""") - val jsonDataWithValue: JsonNode?, - @BlueprintsProperty(description = "listData") - val listData: MutableList, - @BlueprintsProperty(description = "this mapData") - val mapData: MutableMap = hashMapOf(), - @BlueprintsProperty(description = "this complexData") - val complexData: TestBlueprintsChildDataType?, - @BlueprintsProperty(description = "this complexDataList") - val complexDataList: MutableList -) - -data class TestBlueprintsChildDataType(val name: String) - -@BlueprintsWorkflowInput -data class TestBlueprintsWorkflowInput( - @BlueprintsProperty(description = "this sample name") - @PropertyDefaultValue(value = "Brinda") - var name: String, - @BlueprintsProperty(description = "this sample name") - val place: String -) - -@BlueprintsWorkflowOutput -data class TestBlueprintsWorkflowOutput( - @BlueprintsProperty(description = "this is dslExpression") - @DSLExpression("field1") - var dslExpression: String, - - @BlueprintsProperty(description = "this is withNodeAttributeExpression") - @AttributeExpression(modelableEntityName = "sample-node", attributeName = "response-data") - var withNodeAttributeExpression: String, - - @BlueprintsProperty(description = "this is withNodeAttributeExpressionSubAttribute") - @AttributeExpression( - modelableEntityName = "sample-node", attributeName = "response-data", - subAttributeName = ".\$field1" - ) - var withNodeAttributeExpressionSubAttribute: String, - - @BlueprintsProperty(description = "this is withAttributeExpressionSubAttribute") - @AttributeExpression(attributeName = "response-data", subAttributeName = ".\$field1") - var withAttributeExpressionSubAttribute: String, - - @BlueprintsProperty(description = "this is withAttributeExpression") - @AttributeExpression(attributeName = "response-data") - var withAttributeExpression: String, - - @BlueprintsProperty(description = "this is withAArtifactExpression") - @ArtifactExpression(modelableEntityName = "test-node", artifactName = "content-template") - var withAArtifactExpression: String, - - @BlueprintsProperty(description = "this status") - val status: String = "success" -) diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt new file mode 100644 index 000000000..f2d95cdc6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BluePrintDSLTest.kt @@ -0,0 +1,318 @@ +/* + * Copyright © 2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.dsl + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType +import kotlin.test.assertNotNull + +class BluePrintDSLTest { + + @Test + fun testOperationDSLWorkflow() { + + val blueprint = blueprint( + "sample-bp", "1.0.0", + "brindasanth@onap.com", "sample, blueprints" + ) { + + artifactType(BluePrintTypes.artifactTypeTemplateVelocity()) + + // For New Component Definition + component( + "resource-resolution", "component-script-executor", "1.0.0", + "Resource Resolution component." + ) { + implementation(180) + // Attributes ( Properties which will be set during execution) + attribute("template1-data", "string", true, "") + + // Properties + property("string-value1", "string", true, "sample") + property("string-value2", "string", true, getInput("key-1")) + // Inputs + input("json-content", "json", true, """{ "name" : "cds"}""") + input("template-content", "string", true, getArtifact("template1")) + // Outputs + output("self-attribute-expression", "json", true, getAttribute("template1-data")) + // Artifacts + artifact("template1", "artifact-template-velocity", "Templates/template1.vtl") + } + + // Already definitions Registered Components + registryComponent( + "activate-restconf", "component-resource-resolution", "1.0.0", + "RestconfExecutor", "Resource Resolution component." + ) { + implementation(180) + // Properties + property("string-value1", "data") + // Inputs + input("json-content", """{ "name" : "cds"}""") + // Outputs + output("self-attribute-expression", getAttribute("template1-data")) + // Artifacts + artifact("template2", "artifact-template-velocity", "Templates/template1.vtl") + } + + workflow("resource-resolution-process", "Resource Resolution wf") { + input("json-content", "json", true, "") + input("key-1", "string", true, "") + output("status", "string", true, "success") + step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke") + } + } + assertNotNull(blueprint.components, "failed to get components") + assertNotNull(blueprint.workflows, "failed to get workflows") + // println(blueprint.asJsonString(true)) + + val serviceTemplateGenerator = BluePrintServiceTemplateGenerator(blueprint) + val serviceTemplate = serviceTemplateGenerator.serviceTemplate() + assertNotNull(serviceTemplate.topologyTemplate, "failed to get service topology template") + // println(serviceTemplate.asJsonString(true)) + } + + @Test + fun testServiceTemplate() { + val serviceTemplate = serviceTemplate( + "sample-bp", "1.0.0", + "brindasanth@onap.com", "sample, blueprints" + ) { + metadata("release", "1806") + import("Definition/data_types.json") + dsl("rest-endpoint", """{ "selector" : "odl-selector"}""") + dsl("db-endpoint", """{ "selector" : "db-selector"}""") + + nodeTypeComponent() + nodeTypeResourceSource() + nodeTypeVnf() + + artifactTypeTemplateVelocity() + artifactTypeTempleJinja() + artifactTypeScriptKotlin() + artifactTypeMappingResource() + artifactTypeComponentJar() + artifactTypeK8sProfileFolder() + artifactTypeK8sConfigFolder() + + relationshipTypeConnectsTo() + relationshipTypeDependsOn() + relationshipTypeHostedOn() + + topologyTemplate { + nodeTemplateOperation( + nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor", + description = "sample activation" + ) { + implementation(360, "SELF") { + primary("Scripts/sample.py") + dependencies("one", "two") + } + inputs { + property("json-content", """{ "name" : "cds"}""") + property("array-content", """["controller", "blueprints"]""") + property("int-value", 234) + property("boolean-value", true) + property("string-value", "sample") + property("input-expression", getInput("key-1")) + property("self-property-expression", getProperty("key-1")) + property("self-artifact-expression", getArtifact("key-1")) + property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1")) + } + outputs { + property("self-attribute-expression", getAttribute("key-1")) + } + } + // Other way of defining Node Template with artifacts, implementation + nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") { + operation("ResourceResolutionExecutor", "") { + implementation(180) + inputs { + property("boolean-value", true) + property("string-value", "sample") + } + outputs { + property("resolve-expression", getAttribute("key-1")) + } + } + artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl") + } + + workflow("resource-resolution", "to resolve resources") { + step("resource-resolution-call", "resolve", "Resource Resolution component invoke") + } + // Alternate way to define workflow + workflow("activate", "to resolve resources") { + // Alternate step definition + step("netconf-activate-call", "activate", "call activation component") { + success("END") + failure("END") + } + inputs { + property("request-content", "json", true) + } + outputs { + property("response-content", "json", true) { + value(getAttribute("key-1")) + defaultValue("""{ "status" : "success"}""".jsonAsJsonType()) + } + } + } + } + } + + // println(serviceTemplate.asJsonString(true)) + assertNotNull(serviceTemplate.artifactTypes, "failed to get artifactTypes") + assertNotNull(serviceTemplate.nodeTypes, "failed to get nodeTypes") + assertNotNull(serviceTemplate.relationshipTypes, "failed to get relationshipTypes") + assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") + assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes") + assertNotNull( + serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], + "failed to get nodeTypes(activate)" + ) + } + + @Test + fun testNodeTypePropertyConstrains() { + val nodeType = nodeType("data-node", "1.0.0", "tosca.Nodes.root", "") { + property("ip-address", "string", true, "") { + defaultValue("127.0.0.1") + constrain { + validValues(arrayListOf("""127.0.0.1""".asJsonPrimitive())) + length(10) + maxLength(20) + minLength(10) + } + } + property("disk-space", "string", true, "") { + defaultValue(10) + constrain { + validValues("""["200KB", "400KB"]""") + equal("200KB") + inRange("""["100KB", "500KB" ]""") + maxLength("10MB") + minLength("10KB") + } + constrain { + validValues("""[ 200, 400]""") + greaterOrEqual("10KB") + greaterThan("20KB") + lessOrEqual("200KB") + lessThan("190KB") + } + } + } + assertNotNull(nodeType, "failed to get nodeType") + // println(nodeType.asJsonString(true)) + } + + @Test + fun testServiceTemplateWorkflow() { + val serviceTemplate = serviceTemplate( + "sample-bp", "1.0.0", + "brindasanth@onap.com", "sample, blueprints" + ) { + topologyTemplate { + workflowNodeTemplate("activate", "component-resource-resolution", "") { + operation("ResourceResolutionExecutor", "") { + inputs { + property("string-value", "sample") + } + } + } + } + } + assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") + assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)") + // println(serviceTemplate.asJsonString(true)) + } + + @Test + fun testNodeTemplateOperationTypes() { + + val testNodeTemplateInstance = BluePrintTypes.nodeTemplateComponentTestExecutor( + id = "test-node-template", + description = "" + ) { + definedProperties { + prop1("i am property1") + prop2("i am property2") + } + definedOperation("") { + implementation(360) + inputs { + request("i am request") + } + outputs { + response(getAttribute("attribute1")) + } + } + } + assertNotNull(testNodeTemplateInstance, "failed to get test node template") + // println(testNodeTemplateInstance.asJsonString(true)) + } +} + +fun BluePrintTypes.nodeTemplateComponentTestExecutor( + id: String, + description: String, + block: TestNodeTemplateOperationImplBuilder.() -> Unit +): + NodeTemplate { + return TestNodeTemplateOperationImplBuilder(id, description).apply(block).build() + } + +class TestNodeTemplateOperationImplBuilder(id: String, description: String) : + AbstractNodeTemplateOperationImplBuilder( + id, "component-test-executor", + "ComponentTestExecutor", + description + ) + +class TestProperty : PropertiesAssignmentBuilder() { + + fun prop1(prop1: String) { + property("prop1", prop1.asJsonPrimitive()) + } + + fun prop2(prop2: String) { + property("prop2", prop2.asJsonPrimitive()) + } +} + +class TestInput : PropertiesAssignmentBuilder() { + + fun request(request: String) { + property("request", request.asJsonPrimitive()) + } +} + +class TestOutput : PropertiesAssignmentBuilder() { + + fun response(response: String) { + response(response.asJsonPrimitive()) + } + + fun response(response: JsonNode) { + property("response", response) + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BlueprintDSLTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BlueprintDSLTest.kt deleted file mode 100644 index 57f671dc4..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/dsl/BlueprintDSLTest.kt +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.dsl - -import com.fasterxml.jackson.databind.JsonNode -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType -import kotlin.test.assertNotNull - -class BlueprintDSLTest { - - @Test - fun testOperationDSLWorkflow() { - - val blueprint = blueprint( - "sample-bp", "1.0.0", - "brindasanth@onap.com", "sample, blueprints" - ) { - - artifactType(BlueprintTypes.artifactTypeTemplateVelocity()) - - // For New Component Definition - component( - "resource-resolution", "component-script-executor", "1.0.0", - "Resource Resolution component." - ) { - implementation(180) - // Attributes ( Properties which will be set during execution) - attribute("template1-data", "string", true, "") - - // Properties - property("string-value1", "string", true, "sample") - property("string-value2", "string", true, getInput("key-1")) - // Inputs - input("json-content", "json", true, """{ "name" : "cds"}""") - input("template-content", "string", true, getArtifact("template1")) - // Outputs - output("self-attribute-expression", "json", true, getAttribute("template1-data")) - // Artifacts - artifact("template1", "artifact-template-velocity", "Templates/template1.vtl") - } - - // Already definitions Registered Components - registryComponent( - "activate-restconf", "component-resource-resolution", "1.0.0", - "RestconfExecutor", "Resource Resolution component." - ) { - implementation(180) - // Properties - property("string-value1", "data") - // Inputs - input("json-content", """{ "name" : "cds"}""") - // Outputs - output("self-attribute-expression", getAttribute("template1-data")) - // Artifacts - artifact("template2", "artifact-template-velocity", "Templates/template1.vtl") - } - - workflow("resource-resolution-process", "Resource Resolution wf") { - input("json-content", "json", true, "") - input("key-1", "string", true, "") - output("status", "string", true, "success") - step("resource-resolution-call", "resource-resolution", "Resource Resolution component invoke") - } - } - assertNotNull(blueprint.components, "failed to get components") - assertNotNull(blueprint.workflows, "failed to get workflows") - // println(blueprint.asJsonString(true)) - - val serviceTemplateGenerator = BlueprintServiceTemplateGenerator(blueprint) - val serviceTemplate = serviceTemplateGenerator.serviceTemplate() - assertNotNull(serviceTemplate.topologyTemplate, "failed to get service topology template") - // println(serviceTemplate.asJsonString(true)) - } - - @Test - fun testServiceTemplate() { - val serviceTemplate = serviceTemplate( - "sample-bp", "1.0.0", - "brindasanth@onap.com", "sample, blueprints" - ) { - metadata("release", "1806") - import("Definition/data_types.json") - dsl("rest-endpoint", """{ "selector" : "odl-selector"}""") - dsl("db-endpoint", """{ "selector" : "db-selector"}""") - - nodeTypeComponent() - nodeTypeResourceSource() - nodeTypeVnf() - - artifactTypeTemplateVelocity() - artifactTypeTempleJinja() - artifactTypeScriptKotlin() - artifactTypeMappingResource() - artifactTypeComponentJar() - artifactTypeK8sProfileFolder() - artifactTypeK8sConfigFolder() - - relationshipTypeConnectsTo() - relationshipTypeDependsOn() - relationshipTypeHostedOn() - - topologyTemplate { - nodeTemplateOperation( - nodeTemplateName = "activate", type = "sample-node-type", interfaceName = "RestconfExecutor", - description = "sample activation" - ) { - implementation(360, "SELF") { - primary("Scripts/sample.py") - dependencies("one", "two") - } - inputs { - property("json-content", """{ "name" : "cds"}""") - property("array-content", """["controller", "blueprints"]""") - property("int-value", 234) - property("boolean-value", true) - property("string-value", "sample") - property("input-expression", getInput("key-1")) - property("self-property-expression", getProperty("key-1")) - property("self-artifact-expression", getArtifact("key-1")) - property("other-artifact-expression", getNodeTemplateArtifact("node-1", "key-1")) - } - outputs { - property("self-attribute-expression", getAttribute("key-1")) - } - } - // Other way of defining Node Template with artifacts, implementation - nodeTemplate("resolve", "sample-resolve-type", "Resource Resolution") { - operation("ResourceResolutionExecutor", "") { - implementation(180) - inputs { - property("boolean-value", true) - property("string-value", "sample") - } - outputs { - property("resolve-expression", getAttribute("key-1")) - } - } - artifact("sample-template", "artifact-velocity", "Templates/sample-template.vtl") - } - - workflow("resource-resolution", "to resolve resources") { - step("resource-resolution-call", "resolve", "Resource Resolution component invoke") - } - // Alternate way to define workflow - workflow("activate", "to resolve resources") { - // Alternate step definition - step("netconf-activate-call", "activate", "call activation component") { - success("END") - failure("END") - } - inputs { - property("request-content", "json", true) - } - outputs { - property("response-content", "json", true) { - value(getAttribute("key-1")) - defaultValue("""{ "status" : "success"}""".jsonAsJsonType()) - } - } - } - } - } - - // println(serviceTemplate.asJsonString(true)) - assertNotNull(serviceTemplate.artifactTypes, "failed to get artifactTypes") - assertNotNull(serviceTemplate.nodeTypes, "failed to get nodeTypes") - assertNotNull(serviceTemplate.relationshipTypes, "failed to get relationshipTypes") - assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") - assertNotNull(serviceTemplate.topologyTemplate?.nodeTemplates, "failed to get nodeTypes") - assertNotNull( - serviceTemplate.topologyTemplate?.nodeTemplates!!["activate"], - "failed to get nodeTypes(activate)" - ) - } - - @Test - fun testNodeTypePropertyConstrains() { - val nodeType = nodeType("data-node", "1.0.0", "tosca.Nodes.root", "") { - property("ip-address", "string", true, "") { - defaultValue("127.0.0.1") - constrain { - validValues(arrayListOf("""127.0.0.1""".asJsonPrimitive())) - length(10) - maxLength(20) - minLength(10) - } - } - property("disk-space", "string", true, "") { - defaultValue(10) - constrain { - validValues("""["200KB", "400KB"]""") - equal("200KB") - inRange("""["100KB", "500KB" ]""") - maxLength("10MB") - minLength("10KB") - } - constrain { - validValues("""[ 200, 400]""") - greaterOrEqual("10KB") - greaterThan("20KB") - lessOrEqual("200KB") - lessThan("190KB") - } - } - } - assertNotNull(nodeType, "failed to get nodeType") - // println(nodeType.asJsonString(true)) - } - - @Test - fun testServiceTemplateWorkflow() { - val serviceTemplate = serviceTemplate( - "sample-bp", "1.0.0", - "brindasanth@onap.com", "sample, blueprints" - ) { - topologyTemplate { - workflowNodeTemplate("activate", "component-resource-resolution", "") { - operation("ResourceResolutionExecutor", "") { - inputs { - property("string-value", "sample") - } - } - } - } - } - assertNotNull(serviceTemplate.topologyTemplate, "failed to get topology template") - assertNotNull(serviceTemplate.topologyTemplate?.workflows?.get("activate"), "failed to get workflow(activate)") - // println(serviceTemplate.asJsonString(true)) - } - - @Test - fun testNodeTemplateOperationTypes() { - - val testNodeTemplateInstance = BlueprintTypes.nodeTemplateComponentTestExecutor( - id = "test-node-template", - description = "" - ) { - definedProperties { - prop1("i am property1") - prop2("i am property2") - } - definedOperation("") { - implementation(360) - inputs { - request("i am request") - } - outputs { - response(getAttribute("attribute1")) - } - } - } - assertNotNull(testNodeTemplateInstance, "failed to get test node template") - // println(testNodeTemplateInstance.asJsonString(true)) - } -} - -fun BlueprintTypes.nodeTemplateComponentTestExecutor( - id: String, - description: String, - block: TestNodeTemplateOperationImplBuilder.() -> Unit -): - NodeTemplate { - return TestNodeTemplateOperationImplBuilder(id, description).apply(block).build() - } - -class TestNodeTemplateOperationImplBuilder(id: String, description: String) : - AbstractNodeTemplateOperationImplBuilder( - id, "component-test-executor", - "ComponentTestExecutor", - description - ) - -class TestProperty : PropertiesAssignmentBuilder() { - - fun prop1(prop1: String) { - property("prop1", prop1.asJsonPrimitive()) - } - - fun prop2(prop2: String) { - property("prop2", prop2.asJsonPrimitive()) - } -} - -class TestInput : PropertiesAssignmentBuilder() { - - fun request(request: String) { - property("request", request.asJsonPrimitive()) - } -} - -class TestOutput : PropertiesAssignmentBuilder() { - - fun response(response: String) { - response(response.asJsonPrimitive()) - } - - fun response(response: JsonNode) { - property("response", response) - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt new file mode 100644 index 000000000..0803d921b --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt @@ -0,0 +1,88 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.scripts + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintDefinitions +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import kotlin.script.experimental.jvm.util.classpathFromClass +import kotlin.script.experimental.jvm.util.classpathFromClassloader +import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty +import kotlin.test.assertNotNull + +class BluePrintScriptsServiceImplTest { + + private fun viewClassPathInfo() { + + println(" *********** classpathFromClass *********** ") + classpathFromClass( + BluePrintScriptsServiceImplTest::class.java.classLoader, + BluePrintScriptsServiceImplTest::class + )!! + .forEach(::println) + + println(" *********** classpathFromClassloader *********** ") + classpathFromClassloader(BluePrintScriptsServiceImplTest::class.java.classLoader)!! + .forEach(::println) + + println(" *********** classpathFromClasspathProperty *********** ") + classpathFromClasspathProperty()!! + .forEach(::println) + } + + @Test + fun testCachedService() { + runBlocking { + + val bluePrintScriptsService = BluePrintScriptsServiceImpl() + + val basePath = normalizedPathName("src/test/resources/compile") + + /** Load the Definitions */ + val bluePrintDefinitions = bluePrintScriptsService + .scriptInstance( + basePath, + "cba.scripts.ActivateBlueprintDefinitions", true + ) + assertNotNull(bluePrintDefinitions, "failed to get blueprint definitions") + + val serviceTemplate = bluePrintDefinitions.serviceTemplate() + assertNotNull(serviceTemplate, "failed to get service template") + + val customDataType = bluePrintDefinitions.otherDefinition("datatype-custom-datatype") + assertNotNull(customDataType, "failed to get custom definitions") + + val instance = bluePrintScriptsService + .scriptInstance>( + basePath, + "cba.scripts.SampleBlueprintFunctionNode", false + ) + assertNotNull(instance, "failed to get compiled instance") + + val cachedInstance = bluePrintScriptsService + .scriptInstance>( + basePath, + "cba.scripts.SampleBlueprintFunctionNode", false + ) + assertNotNull(cachedInstance, "failed to get cached compile instance") + } + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptsServiceImplTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptsServiceImplTest.kt deleted file mode 100644 index 7dd980dc7..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptsServiceImplTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.scripts - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintDefinitions -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName -import kotlin.script.experimental.jvm.util.classpathFromClass -import kotlin.script.experimental.jvm.util.classpathFromClassloader -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty -import kotlin.test.assertNotNull - -class BlueprintScriptsServiceImplTest { - - private fun viewClassPathInfo() { - - println(" *********** classpathFromClass *********** ") - classpathFromClass( - BlueprintScriptsServiceImplTest::class.java.classLoader, - BlueprintScriptsServiceImplTest::class - )!! - .forEach(::println) - - println(" *********** classpathFromClassloader *********** ") - classpathFromClassloader(BlueprintScriptsServiceImplTest::class.java.classLoader)!! - .forEach(::println) - - println(" *********** classpathFromClasspathProperty *********** ") - classpathFromClasspathProperty()!! - .forEach(::println) - } - - @Test - fun testCachedService() { - runBlocking { - - val bluePrintScriptsService = BlueprintScriptsServiceImpl() - - val basePath = normalizedPathName("src/test/resources/compile") - - /** Load the Definitions */ - val bluePrintDefinitions = bluePrintScriptsService - .scriptInstance( - basePath, - "cba.scripts.ActivateBlueprintDefinitions", true - ) - assertNotNull(bluePrintDefinitions, "failed to get blueprint definitions") - - val serviceTemplate = bluePrintDefinitions.serviceTemplate() - assertNotNull(serviceTemplate, "failed to get service template") - - val customDataType = bluePrintDefinitions.otherDefinition("datatype-custom-datatype") - assertNotNull(customDataType, "failed to get custom definitions") - - val instance = bluePrintScriptsService - .scriptInstance>( - basePath, - "cba.scripts.SampleBlueprintFunctionNode", false - ) - assertNotNull(instance, "failed to get compiled instance") - - val cachedInstance = bluePrintScriptsService - .scriptInstance>( - basePath, - "cba.scripts.SampleBlueprintFunctionNode", false - ) - assertNotNull(cachedInstance, "failed to get cached compile instance") - } - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContextTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContextTest.kt new file mode 100644 index 000000000..38f6ea2ec --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintContextTest.kt @@ -0,0 +1,588 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.ObjectMapper +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType +import org.onap.ccsdk.cds.controllerblueprints.core.data.RequirementAssignment +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.Step +import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +/** + * + * + * @author Brinda Santh + */ +class BluePrintContextTest { + + private val log = LoggerFactory.getLogger(this::class.toString()) + + val blueprintBasePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG + + @Test + fun testBluePrintContextCreation() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) + assertNotNull(bluePrintContext, "Failed to populate Blueprint context") + } + } + + @Test + fun testChainedProperty() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(blueprintBasePath) + val nodeType = bluePrintContext.nodeTypeChained("component-resource-resolution") + assertNotNull(nodeType, "Failed to get chained node type") + log.trace("Properties {}", JacksonUtils.getJson(nodeType, true)) + } + } + + @Test + fun testImports() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.imports = mutableListOf() + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.imports()!!.isEmpty()) + + serviceTemplate.imports = null + assertNull(bluePrintContext.imports()) + } + + @Test + fun testDataTypes() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.dataTypes = mutableMapOf() + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.dataTypes()!!.isEmpty()) + + serviceTemplate.dataTypes = null + assertNull(bluePrintContext.dataTypes()) + } + + @Test + fun testInputs() { + val topologyTemplate = TopologyTemplate() + topologyTemplate.inputs = mutableMapOf() + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.inputs()!!.isEmpty()) + + topologyTemplate.inputs = null + + assertNull(bluePrintContext.inputs()) + } + + @Test + fun testBluePrintJson() { + val serviceTemplate = ServiceTemplate() + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("{\"tosca_definitions_version\":\"controller_blueprint_1_0_0\"}", bluePrintContext.blueprintJson()) + } + + @Test(expected = BluePrintException::class) + fun testName() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_NAME to "hello") + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.name()) + + serviceTemplate.metadata = mutableMapOf() + val bluePrintContext2 = BluePrintContext(serviceTemplate) + bluePrintContext2.name() + } + + @Test(expected = BluePrintException::class) + fun testVersion() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_VERSION to "hello") + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.version()) + + serviceTemplate.metadata = mutableMapOf() + val bluePrintContext2 = BluePrintContext(serviceTemplate) + bluePrintContext2.version() + } + + @Test(expected = BluePrintException::class) + fun testAuthor() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_AUTHOR to "hello") + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.author()) + + serviceTemplate.metadata = mutableMapOf() + val bluePrintContext2 = BluePrintContext(serviceTemplate) + bluePrintContext2.author() + } + + @Test + fun testWorkflows() { + val topologyTemplate = TopologyTemplate() + topologyTemplate.workflows = mutableMapOf() + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.workflows()!!.isEmpty()) + + topologyTemplate.workflows = null + assertNull(bluePrintContext.workflows()) + } + + @Test(expected = BluePrintException::class) + fun testWorkFlowsByName() { + val topologyTemplate = TopologyTemplate() + topologyTemplate.workflows = mutableMapOf("workflow" to Workflow()) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.workflowByName("workflow")) + + bluePrintContext.workflowByName("") + } + + @Test + fun testWorkflowInput() { + val topologyTemplate = TopologyTemplate() + val workflow = Workflow() + workflow.inputs = mutableMapOf() + topologyTemplate.workflows = mutableMapOf("workflow" to workflow) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.workflowInputs("workflow")!!.isEmpty()) + + workflow.inputs = null + + assertNull(bluePrintContext.workflowInputs("workflow")) + } + + @Test(expected = BluePrintException::class) + fun testWorkflowStepByName() { + val topologyTemplate = TopologyTemplate() + val workflow = Workflow() + workflow.steps = mutableMapOf("step" to Step()) + topologyTemplate.workflows = mutableMapOf("workflow" to workflow) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.workflowStepByName("workflow", "step")) + + bluePrintContext.workflowStepByName("workflow", "") + } + + @Test(expected = BluePrintException::class) + fun testWorkflowStepNodeTemplate() { + val topologyTemplate = TopologyTemplate() + val workflow = Workflow() + val step = Step() + step.target = "hello" + workflow.steps = mutableMapOf("step" to step) + topologyTemplate.workflows = mutableMapOf("workflow" to workflow) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.workflowStepNodeTemplate("workflow", "step")) + + bluePrintContext.workflowStepNodeTemplate("workflow", "") + } + + @Test(expected = BluePrintException::class) + fun testWorkflowFirstStepNodeTemplate() { + val topologyTemplate = TopologyTemplate() + val workflow = Workflow() + val step = Step() + step.target = "hello" + workflow.steps = mutableMapOf("step" to step, "step2" to Step()) + topologyTemplate.workflows = mutableMapOf("workflow" to workflow) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.workflowFirstStepNodeTemplate("workflow")) + + workflow.steps = null + bluePrintContext.workflowFirstStepNodeTemplate("workflow") + } + + @Test(expected = BluePrintException::class) + fun testWorkflowStepFirstCallOperation() { + val topologyTemplate = TopologyTemplate() + val workflow = Workflow() + val step = Step() + val activity = Activity() + activity.callOperation = "hello" + step.activities = arrayListOf(activity) + workflow.steps = mutableMapOf("step" to step) + topologyTemplate.workflows = mutableMapOf("workflow" to workflow) + val serviceTemplate = ServiceTemplate() + serviceTemplate.topologyTemplate = topologyTemplate + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.workflowStepFirstCallOperation("workflow", "step")) + + bluePrintContext.workflowStepFirstCallOperation("workflow", "") + } + + @Test + fun testDatatypeByName() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.dataTypes = mutableMapOf("data" to DataType()) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.dataTypeByName("data")) + assertNull(bluePrintContext.dataTypeByName("")) + } + + @Test + fun testArtifactTypes() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.artifactTypes = mutableMapOf() + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.artifactTypes()!!.isEmpty()) + + serviceTemplate.artifactTypes = null + assertNull(bluePrintContext.artifactTypes()) + } + + @Test + fun testPolicyTypes() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.policyTypes = mutableMapOf() + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.policyTypes()!!.isEmpty()) + + serviceTemplate.policyTypes = null + assertNull(bluePrintContext.policyTypes()) + } + + @Test(expected = BluePrintException::class) + fun testPolicyTypeByName() { + val serviceTemplate = ServiceTemplate() + serviceTemplate.policyTypes = mutableMapOf("policy" to PolicyType()) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.policyTypeByName("policy")) + + bluePrintContext.policyTypeByName("") + } + + @Test + fun testPolicyTypesDerivedFrom() { + val serviceTemplate = ServiceTemplate() + val policyType = PolicyType() + policyType.derivedFrom = "hi" + val policyType2 = PolicyType() + policyType2.derivedFrom = "hello" + serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals(1, bluePrintContext.policyTypesDerivedFrom("hi")!!.size) + + serviceTemplate.policyTypes = null + assertNull(bluePrintContext.policyTypesDerivedFrom("hi")) + } + + @Test + fun testPolicyTypesTarget() { + val serviceTemplate = ServiceTemplate() + val policyType = PolicyType() + policyType.targets = mutableListOf("hi") + val policyType2 = PolicyType() + policyType2.targets = mutableListOf() + serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals(1, bluePrintContext.policyTypesTarget("hi")!!.size) + + serviceTemplate.policyTypes = null + assertNull(bluePrintContext.policyTypesTarget("hi")) + } + + @Test + fun testPolicyTypesTargetNDerivedFrom() { + val serviceTemplate = ServiceTemplate() + val policyType = PolicyType() + policyType.targets = mutableListOf("hi") + policyType.derivedFrom = "hi" + val policyType2 = PolicyType() + policyType2.targets = mutableListOf() + policyType2.derivedFrom = "hi" + serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals(1, bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi")!!.size) + + serviceTemplate.policyTypes = null + assertNull(bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi")) + } + + @Test + fun testNodeTypeDerivedFrom() { + val serviceTemplate = ServiceTemplate() + val nodeType = NodeType() + nodeType.derivedFrom = "hi" + val nodeType2 = NodeType() + nodeType2.derivedFrom = "hiii" + serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType, "node2" to nodeType2) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals(1, bluePrintContext.nodeTypeDerivedFrom("hi")!!.size) + + serviceTemplate.nodeTypes = null + assertNull(bluePrintContext.nodeTypeDerivedFrom("hi")) + } + + @Test(expected = BluePrintException::class) + fun testInterfaceNameForNodeType() { + val serviceTemplate = ServiceTemplate() + val nodeType = NodeType() + nodeType.interfaces = mutableMapOf("hello" to InterfaceDefinition(), "hi" to InterfaceDefinition()) + serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("hello", bluePrintContext.interfaceNameForNodeType("node")) + + bluePrintContext.interfaceNameForNodeType("") + } + + @Test + fun testNodeTemplateForNodeType() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.type = "hello" + val nodeTemplate2 = NodeTemplate() + nodeTemplate2.type = "hi" + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = + mutableMapOf("node" to nodeTemplate, "node2" to nodeTemplate2) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals(1, bluePrintContext.nodeTemplateForNodeType("hello")!!.size) + + serviceTemplate.topologyTemplate!!.nodeTemplates = null + assertNull(bluePrintContext.nodeTemplateForNodeType("hello")) + } + + @Test + fun testNodeTemplateProperty() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateProperty("node", "prop")) + + assertNull(bluePrintContext.nodeTemplateProperty("node", "")) + + nodeTemplate.properties = null + assertNull(bluePrintContext.nodeTemplateProperty("node", "prop")) + } + + @Test + fun testNodeTemplateArtifacts() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.artifacts = mutableMapOf() + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertTrue(bluePrintContext.nodeTemplateArtifacts("node")!!.isEmpty()) + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateArtifact() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.artifacts = mutableMapOf("art" to ArtifactDefinition()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateArtifact("node", "art")) + + bluePrintContext.nodeTemplateArtifact("node", "") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateArtifactForArtifactType() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + val artifactDefinition = ArtifactDefinition() + artifactDefinition.type = "type" + val artifactDefinition2 = ArtifactDefinition() + artifactDefinition2.type = "No type" + nodeTemplate.artifacts = mutableMapOf("art" to artifactDefinition, "art2" to artifactDefinition2) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateArtifactForArtifactType("node", "type")) + + bluePrintContext.nodeTemplateArtifactForArtifactType("", "") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateFirstInterface() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateFirstInterface("node")) + + nodeTemplate.interfaces = null + bluePrintContext.nodeTemplateFirstInterface("node") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateFirstInterfaceName() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("interface", bluePrintContext.nodeTemplateFirstInterfaceName("node")) + + nodeTemplate.interfaces = null + bluePrintContext.nodeTemplateFirstInterfaceName("node") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateFirstInterfaceFirstOperationName() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + val interfaceAssignment = InterfaceAssignment() + interfaceAssignment.operations = mutableMapOf("op" to OperationAssignment(), "op2" to OperationAssignment()) + nodeTemplate.interfaces = mutableMapOf("intf" to interfaceAssignment) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertEquals("op", bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node")) + + interfaceAssignment.operations = null + bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateCapability() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.capabilities = mutableMapOf("cap" to CapabilityAssignment()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateCapability("node", "cap")) + + bluePrintContext.nodeTemplateCapability("node", "") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateRequirement() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + nodeTemplate.requirements = mutableMapOf("req" to RequirementAssignment()) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateRequirement("node", "req")) + + bluePrintContext.nodeTemplateRequirement("node", "") + } + + @Test(expected = BluePrintException::class) + fun testNodeTemplateRequirementNode() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + val requirementAssignment = RequirementAssignment() + requirementAssignment.node = "node" + nodeTemplate.requirements = mutableMapOf("req" to requirementAssignment) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateRequirementNode("node", "req")) + + bluePrintContext.nodeTemplateRequirementNode("node", "") + } + + @Test + fun testNodeTemplateCapabilityProperty() { + val serviceTemplate = ServiceTemplate() + val nodeTemplate = NodeTemplate() + val capabilityAssignment = CapabilityAssignment() + capabilityAssignment.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode()) + nodeTemplate.capabilities = mutableMapOf("cap" to capabilityAssignment) + serviceTemplate.topologyTemplate = TopologyTemplate() + serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) + val bluePrintContext = BluePrintContext(serviceTemplate) + + assertNotNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop")) + + capabilityAssignment.properties = null + + assertNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop")) + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt new file mode 100644 index 000000000..4f645270d --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintExpressionServiceTest.kt @@ -0,0 +1,140 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.data.ExpressionData +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintExpressionServiceTest { + + @Test + fun testInputExpression() { + val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }") + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.inputExpression, " Failed to populate input expression data") + assertEquals("input-name", expressionData.inputExpression?.propertyName, "Failed to get propertyName from expression data") + } + + @Test + fun testPropertyExpression() { + val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }") + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data") + assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName") + + val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }") + val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression") + assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data") + assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName") + assertEquals( + "resource.name", + expressionData1.propertyExpression?.subPropertyName, + " Failed to populate nested subPropertyName expression data" + ) + } + + @Test + fun testAttributeExpression() { + val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"resource\"] }") + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data") + assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("resource", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName") + + val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }") + val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData1.attributeExpression, " Failed to populate attribute expression data") + assertEquals("SELF", expressionData1.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("attribute-name", expressionData1.attributeExpression?.attributeName, " Failed to get expected attributeName") + assertEquals( + "resource.name", + expressionData1.attributeExpression?.subAttributeName, + " Failed to populate nested subAttributeName expression data" + ) + } + + @Test + fun testOutputOperationExpression() { + val node: JsonNode = + jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }") + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data") + assertEquals("SELF", expressionData.operationOutputExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("interface-name", expressionData.operationOutputExpression?.interfaceName, " Failed to get expected interfaceName") + assertEquals("operation-name", expressionData.operationOutputExpression?.operationName, " Failed to get expected operationName") + assertEquals("output-property-name", expressionData.operationOutputExpression?.propertyName, " Failed to get expected propertyName") + } + + @Test + fun testArtifactExpression() { + val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }") + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName") + + val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }") + val expressionData1: ExpressionData = BluePrintExpressionService.getExpressionData(node1) + assertNotNull(expressionData1, " Failed to populate expression data") + assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data") + assertEquals("SELF", expressionData1.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") + assertEquals("artifact-template", expressionData1.artifactExpression?.artifactName, " Failed to get expected artifactName") + assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location") + assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove") + } + + @Test + fun testDSLExpression() { + val node: JsonNode = "*dynamic-rest-source".asJsonPrimitive() + val expressionData: ExpressionData = BluePrintExpressionService.getExpressionData(node) + assertNotNull(expressionData, " Failed to populate expression data") + assertEquals(expressionData.isExpression, true, "Failed to identify as expression") + assertNotNull(expressionData.dslExpression, " Failed to populate dsl expression data") + assertEquals( + "dynamic-rest-source", expressionData.dslExpression!!.propertyName, + " Failed to populate dsl property name" + ) + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt new file mode 100644 index 000000000..265175165 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import kotlin.test.assertNotNull + +/** + * BluePrintRepoFileServiceTest + * @author Brinda Santh + * + */ +class BluePrintRepoFileServiceTest { + + private val basePath = TestConstants.PATH_TEST_DEFINITION_TYPE_STARTER + private val bluePrintRepoFileService = BluePrintRepoFileService(basePath) + + @Test + fun testGetDataType() { + val dataType = bluePrintRepoFileService.getDataType("dt-v4-aggregate") + assertNotNull(dataType, "Failed to get DataType from repo") + } + + @Test + fun testGetNodeType() { + val nodeType = bluePrintRepoFileService.getNodeType("component-resource-resolution") + assertNotNull(nodeType, "Failed to get NodeType from repo") + } + + @Test + fun testGetArtifactType() { + val nodeType = bluePrintRepoFileService.getArtifactType("artifact-template-velocity") + assertNotNull(nodeType, "Failed to get ArtifactType from repo") + } + + @Test(expected = BluePrintException::class) + fun testModelNotFound() { + val dataType = bluePrintRepoFileService.getDataType("dt-not-found") + assertNotNull(dataType, "Failed to get DataType from repo") + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt new file mode 100644 index 000000000..4fcbb2d98 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt @@ -0,0 +1,299 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018-2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.NullNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintRuntimeUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +/** + * + * + * @author Brinda Santh + */ +class BluePrintRuntimeServiceTest { + + private val log = LoggerFactory.getLogger(this::class.toString()) + + @Test + fun `test Resolve NodeTemplate Properties`() { + log.info("************************ testResolveNodeTemplateProperties **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val inputDataPath = "src/test/resources/data/default-context.json" + + val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath) + bluePrintRuntimeService.assignInputs(inputNode) + + val propContext: MutableMap = bluePrintRuntimeService + .resolveNodeTemplateProperties("activate-process") + + assertNotNull(propContext, "Failed to populate interface property values") + } + + @Test + fun `test Resolve Relationship Properties`() { + log.info("************************ testResolveRelationshipTemplateProperties **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val inputDataPath = "src/test/resources/data/default-context.json" + + val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath) + bluePrintRuntimeService.assignInputs(inputNode) + + val propContext: MutableMap = bluePrintRuntimeService + .resolveRelationshipTemplateProperties("cli-device-properties") + + assertNotNull(propContext, "Failed to populate relationship property values") + assertEquals( + "localhost".asJsonPrimitive(), + propContext["connection-config"]!!.get("host"), + "failed to resolve expression" + ) + } + + @Test + fun `test resolve NodeTemplate Capability Properties`() { + log.info("************************ testResolveNodeTemplateRequirementProperties **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val executionContext = bluePrintRuntimeService.getExecutionContext() + + BluePrintRuntimeUtils.assignInputsFromClassPathFile( + bluePrintRuntimeService.bluePrintContext(), + "data/default-context.json", executionContext + ) + + val assignmentParams = "{\n" + + " \"ipAddress\": \"127.0.0.1\",\n" + + " \"hostName\": \"vnf-host\"\n" + + " }" + + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment", "assignment-params", + JacksonUtils.jsonNode(assignmentParams) + ) + + val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties( + "sample-netconf-device", + "netconf" + ) + assertNotNull(capProperties, "Failed to populate capability property values") + assertEquals( + capProperties["target-ip-address"], + "127.0.0.1".asJsonPrimitive(), + "Failed to populate parameter target-ip-address" + ) + assertEquals( + capProperties["port-number"], + JacksonUtils.jsonNodeFromObject(830), + "Failed to populate parameter port-number" + ) + } + + @Test + fun `test Resolve NodeTemplate Interface Operation Inputs`() { + log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val executionContext = bluePrintRuntimeService.getExecutionContext() + + BluePrintRuntimeUtils.assignInputsFromClassPathFile( + bluePrintRuntimeService.bluePrintContext(), + "data/default-context.json", executionContext + ) + + val inContext: MutableMap = bluePrintRuntimeService + .resolveNodeTemplateInterfaceOperationInputs( + "resource-assignment", + "ResourceResolutionComponent", "process" + ) + + assertNotNull(inContext, "Failed to populate interface input property values") + assertEquals( + inContext["action-name"], + JacksonUtils.jsonNodeFromObject("sample-action"), + "Failed to populate parameter action-name" + ) + assertEquals( + inContext["request-id"], + JacksonUtils.jsonNodeFromObject("12345"), + "Failed to populate parameter action-name" + ) + } + + @Test + fun `test Resolve NodeTemplate Interface Operation Outputs`() { + log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment", + "assignment-params", + NullNode.getInstance() + ) + + bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs( + "resource-assignment", + "ResourceResolutionComponent", "process" + ) + + val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue( + "resource-assignment", + "ResourceResolutionComponent", "process", "status" + ) + assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status") + + val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue( + "resource-assignment", + "ResourceResolutionComponent", "process", "resource-assignment-params" + ) + assertEquals( + NullNode.getInstance(), + outputParams, + "Failed to get operation property resource-assignment-params" + ) + } + + @Test + fun `test NodeTemplate Context Property`() { + log.info("************************ testNodeTemplateContextProperty **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment-ra-component", "context1", + JacksonUtils.jsonNodeFromObject("context1-value") + ) + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment-ra-component", "context2", + JacksonUtils.jsonNodeFromObject("context2-value") + ) + + val keys = listOf("context1", "context2") + + val jsonValueNode = + bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys) + assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties") + log.info("JSON Prepared Value Context {}", jsonValueNode) + } + + @Test + fun `test Resolve DSL Properties`() { + log.info("************************ resolveDSLExpression **********************") + + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive()) + + val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source") + assertNotNull(resolvedJsonNode, "Failed to populate dsl property values") + } + + @Test + fun `test Resolve Workflow Outputs`() { + log.info("************************ resolvePropertyAssignments **********************") + val bluePrintRuntimeService = getBluePrintRuntimeService() + + val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}" + + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment", "assignment-params", + JacksonUtils.jsonNode(assignmentParams) + ) + + val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment") + assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values") + } + + @Test + fun `test resolvePropertyDefinitions using sub attributes`() { + val bluePrintRuntimeService = getBluePrintRuntimeService() + + bluePrintRuntimeService.setNodeTemplateAttributeValue( + "resource-assignment", "assignment-map", + JacksonUtils.jsonNode( + """ + { + "a-prefix":{ + "an-object":{ + "a-key":123 + } + } + } + """.trimIndent() + ) + ) + + val propertyDefinitions = mutableMapOf( + "resolution" to PropertyDefinition().apply { + this.type = "json" + this.value = JacksonUtils.jsonNode( + """ + { + "get_attribute":[ + "resource-assignment", + "", + "assignment-map", + "a-prefix", + "an-object", + "a-key" + ] + } + """.trimIndent() + ) + } + ) + + val result = bluePrintRuntimeService.resolvePropertyDefinitions("workflow", "WORKFLOW", propertyDefinitions) + + assertEquals("123", result["resolution"]!!.asText()) + } + + private fun getBluePrintRuntimeService(): BluePrintRuntimeService> { + val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG) + val blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath) + val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID) + val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH) + + assertEquals( + "1234".asJsonPrimitive(), + checkProcessId, "Failed to get process id after runtime creation" + ) + assertEquals( + blueprintBasePath.asJsonPrimitive(), + checkBasePath, "Failed to get base path after runtime creation" + ) + + return blueprintRuntime + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt new file mode 100644 index 000000000..0e93ccf6b --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import kotlin.test.BeforeTest +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +class BluePrintTemplateServiceTest { + + lateinit var blueprintRuntime: BluePrintRuntimeService<*> + + @BeforeTest + fun setup() { + val blueprintBasePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG + blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath) + } + + @Test + fun testVelocityGeneratedContent() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/base-config-velocity-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-velocity.json") + + val content = BluePrintVelocityTemplateService.generateContent(template, json) + assertNotNull(content, "failed to generate content for velocity template") + } + } + + @Test + fun testJinjaGeneratedContent() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/master.jinja") + val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json") + + val element: MutableMap = mutableMapOf() + element["additional_array"] = arrayListOf( + hashMapOf("name" to "Element1", "location" to "Region0"), + hashMapOf("name" to "Element2", "location" to "Region1") + ) + + val content = BluePrintJinjaTemplateService.generateContent(template, json, false, element) + assertNotNull(content, "failed to generate content for velocity template") + } + } + + @Test + fun `no value variable should evaluate to default value - standalone template mesh test`() { + runBlocking { + val template = + JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json") + + val content = BluePrintVelocityTemplateService.generateContent(template, json) + // first line represents a variable whose value was successfully retrieved, second line contains a variable + // whose value could not be evaluated + val expected = "sample-hostname\n\${node0_backup_router_address}" + assertEquals(expected, content, "No value variable should use default value") + } + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt new file mode 100644 index 000000000..eb6246989 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintWorkflowServiceTest.kt @@ -0,0 +1,272 @@ +/* + * Copyright © 2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.service + +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeout +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.data.EdgeLabel +import org.onap.ccsdk.cds.controllerblueprints.core.data.Graph +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.toGraph +import kotlin.test.assertNotNull + +class BluePrintWorkflowServiceTest { + + @Test + fun testSimpleFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>E/SUCCESS, E>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testMultipleFlows() { + runBlocking { + coroutineScope { + val wfs = listOf("12345", "12346").map { + async { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D"), null) + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(it), it) + assertNotNull(response, "failed to get response") + } + } + wfs.awaitAll() + } + } + } + + @Test + fun testMissingEdgeForBFailureState() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "C", "D", "E"), arrayListOf("B")) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testBExceptionFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "C", "D", "E"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testTimeoutExceptionFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>TO/SUCCESS, TO>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "TO", "C", "D", "E"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testConditionalFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testBothConditionalFlow() { + runBlocking { + // Failure Flow + val failurePatGraph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val failurePathWorkflow = TestBluePrintWorkFlowService() + failurePathWorkflow.simulatedState = prepareSimulation( + arrayListOf("B", "C", "D", "E"), + arrayListOf("A") + ) + val failurePathWorkflowInput = "123456" + val failurePathResponse = failurePathWorkflow.executeWorkflow(failurePatGraph, mockBluePrintRuntimeService(), failurePathWorkflowInput) + assertNotNull(failurePathResponse, "failed to get response") + } + } + + @Test + fun testMultipleSkipFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, C>D/SUCCESS, D>E/SUCCESS, B>E/SUCCESS, E>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + @Test + fun testParallelFlow() { + runBlocking { + val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/SUCCESS, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" + .toGraph() + val simpleWorkflow = TestBluePrintWorkFlowService() + simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D"), null) + val input = "123456" + val response = simpleWorkflow.executeWorkflow(graph, mockBluePrintRuntimeService(), input) + assertNotNull(response, "failed to get response") + } + } + + private fun mockBluePrintRuntimeService(): BluePrintRuntimeService<*> { + return mockBluePrintRuntimeService("123456") + } + + private fun mockBluePrintRuntimeService(id: String): BluePrintRuntimeService<*> { + val bluePrintRuntimeService = mockk>() + every { bluePrintRuntimeService.id() } returns id + return bluePrintRuntimeService + } + + private fun prepareSimulation(successes: List?, failures: List?): MutableMap { + val simulatedState: MutableMap = hashMapOf() + successes?.forEach { + simulatedState[it] = EdgeLabel.SUCCESS + } + failures?.forEach { + simulatedState[it] = EdgeLabel.FAILURE + } + return simulatedState + } +} + +class TestBluePrintWorkFlowService : + AbstractBluePrintWorkFlowService() { + + val log = logger(TestBluePrintWorkFlowService::class) + + lateinit var simulatedState: MutableMap + + override suspend fun initializeWorkflow(input: String): EdgeLabel { + return EdgeLabel.SUCCESS + } + + override suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BluePrintRuntimeService<*>, input: String): String { + log.info("Executing Graph : $graph") + this.graph = graph + this.workflowId = bluePrintRuntimeService.id() + val output = CompletableDeferred() + val startMessage = WorkflowExecuteMessage(input, output) + val workflowActor = workflowActor() + if (!workflowActor.isClosedForSend) { + workflowActor().send(startMessage) + } else { + throw BluePrintProcessorException("workflow actor is closed for send $workflowActor") + } + return startMessage.output.await() + } + + override suspend fun prepareNodeExecutionMessage(node: Graph.Node): + NodeExecuteMessage { + return NodeExecuteMessage(node, "$node Input", "") + } + + override suspend fun executeNode( + node: Graph.Node, + nodeInput: String, + nodeOutput: String + ): EdgeLabel { + // val random = (1..10).random() * 100 + // log.info("workflow($workflowId) node(${node.id}) will reply in $random ms") + // kotlinx.coroutines.delay(random.toLong()) + // //Simulation for timeout + if (node.id == "TO") { + withTimeout(1) { + kotlinx.coroutines.delay(2) + } + } + return simulatedState[node.id] ?: throw BluePrintException("failed to get status for the node($node)") + } + + override suspend fun prepareNodeSkipMessage(node: Graph.Node): NodeSkipMessage { + val nodeOutput = "" + return NodeSkipMessage(node, "$node Skip Input", nodeOutput) + } + + override suspend fun skipNode( + node: Graph.Node, + nodeInput: String, + nodeOutput: String + ): EdgeLabel { + return simulatedState[node.id] ?: throw BluePrintException("failed to get status for the node($node)") + } + + override suspend fun cancelNode( + node: Graph.Node, + nodeInput: String, + nodeOutput: String + ): EdgeLabel { + TODO("not implemented") // To change body of created functions use File | Settings | File Templates. + } + + override suspend fun restartNode( + node: Graph.Node, + nodeInput: String, + nodeOutput: String + ): EdgeLabel { + TODO("not implemented") // To change body of created functions use File | Settings | File Templates. + } + + override suspend fun prepareWorkflowOutput(): String { + if (exceptions.isNotEmpty()) { + exceptions.forEach { + log.error("workflow($workflowId) exceptions :", it) + } + } + return "Final Response" + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContextTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContextTest.kt deleted file mode 100644 index 4ad4ab403..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintContextTest.kt +++ /dev/null @@ -1,588 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import com.fasterxml.jackson.databind.ObjectMapper -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import org.onap.ccsdk.cds.controllerblueprints.core.data.Activity -import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition -import org.onap.ccsdk.cds.controllerblueprints.core.data.CapabilityAssignment -import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType -import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceAssignment -import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment -import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType -import org.onap.ccsdk.cds.controllerblueprints.core.data.RequirementAssignment -import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.data.Step -import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull -import kotlin.test.assertTrue - -/** - * - * - * @author Brinda Santh - */ -class BlueprintContextTest { - - private val log = LoggerFactory.getLogger(this::class.toString()) - - val blueprintBasePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG - - @Test - fun testBlueprintContextCreation() { - runBlocking { - val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(blueprintBasePath) - assertNotNull(bluePrintContext, "Failed to populate Blueprint context") - } - } - - @Test - fun testChainedProperty() { - runBlocking { - val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(blueprintBasePath) - val nodeType = bluePrintContext.nodeTypeChained("component-resource-resolution") - assertNotNull(nodeType, "Failed to get chained node type") - log.trace("Properties {}", JacksonUtils.getJson(nodeType, true)) - } - } - - @Test - fun testImports() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.imports = mutableListOf() - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.imports()!!.isEmpty()) - - serviceTemplate.imports = null - assertNull(bluePrintContext.imports()) - } - - @Test - fun testDataTypes() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.dataTypes = mutableMapOf() - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.dataTypes()!!.isEmpty()) - - serviceTemplate.dataTypes = null - assertNull(bluePrintContext.dataTypes()) - } - - @Test - fun testInputs() { - val topologyTemplate = TopologyTemplate() - topologyTemplate.inputs = mutableMapOf() - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.inputs()!!.isEmpty()) - - topologyTemplate.inputs = null - - assertNull(bluePrintContext.inputs()) - } - - @Test - fun testBlueprintJson() { - val serviceTemplate = ServiceTemplate() - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("{\"tosca_definitions_version\":\"controller_blueprint_1_0_0\"}", bluePrintContext.blueprintJson()) - } - - @Test(expected = BlueprintException::class) - fun testName() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.metadata = mutableMapOf(BlueprintConstants.METADATA_TEMPLATE_NAME to "hello") - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.name()) - - serviceTemplate.metadata = mutableMapOf() - val bluePrintContext2 = BlueprintContext(serviceTemplate) - bluePrintContext2.name() - } - - @Test(expected = BlueprintException::class) - fun testVersion() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.metadata = mutableMapOf(BlueprintConstants.METADATA_TEMPLATE_VERSION to "hello") - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.version()) - - serviceTemplate.metadata = mutableMapOf() - val bluePrintContext2 = BlueprintContext(serviceTemplate) - bluePrintContext2.version() - } - - @Test(expected = BlueprintException::class) - fun testAuthor() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.metadata = mutableMapOf(BlueprintConstants.METADATA_TEMPLATE_AUTHOR to "hello") - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.author()) - - serviceTemplate.metadata = mutableMapOf() - val bluePrintContext2 = BlueprintContext(serviceTemplate) - bluePrintContext2.author() - } - - @Test - fun testWorkflows() { - val topologyTemplate = TopologyTemplate() - topologyTemplate.workflows = mutableMapOf() - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.workflows()!!.isEmpty()) - - topologyTemplate.workflows = null - assertNull(bluePrintContext.workflows()) - } - - @Test(expected = BlueprintException::class) - fun testWorkFlowsByName() { - val topologyTemplate = TopologyTemplate() - topologyTemplate.workflows = mutableMapOf("workflow" to Workflow()) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.workflowByName("workflow")) - - bluePrintContext.workflowByName("") - } - - @Test - fun testWorkflowInput() { - val topologyTemplate = TopologyTemplate() - val workflow = Workflow() - workflow.inputs = mutableMapOf() - topologyTemplate.workflows = mutableMapOf("workflow" to workflow) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.workflowInputs("workflow")!!.isEmpty()) - - workflow.inputs = null - - assertNull(bluePrintContext.workflowInputs("workflow")) - } - - @Test(expected = BlueprintException::class) - fun testWorkflowStepByName() { - val topologyTemplate = TopologyTemplate() - val workflow = Workflow() - workflow.steps = mutableMapOf("step" to Step()) - topologyTemplate.workflows = mutableMapOf("workflow" to workflow) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.workflowStepByName("workflow", "step")) - - bluePrintContext.workflowStepByName("workflow", "") - } - - @Test(expected = BlueprintException::class) - fun testWorkflowStepNodeTemplate() { - val topologyTemplate = TopologyTemplate() - val workflow = Workflow() - val step = Step() - step.target = "hello" - workflow.steps = mutableMapOf("step" to step) - topologyTemplate.workflows = mutableMapOf("workflow" to workflow) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.workflowStepNodeTemplate("workflow", "step")) - - bluePrintContext.workflowStepNodeTemplate("workflow", "") - } - - @Test(expected = BlueprintException::class) - fun testWorkflowFirstStepNodeTemplate() { - val topologyTemplate = TopologyTemplate() - val workflow = Workflow() - val step = Step() - step.target = "hello" - workflow.steps = mutableMapOf("step" to step, "step2" to Step()) - topologyTemplate.workflows = mutableMapOf("workflow" to workflow) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.workflowFirstStepNodeTemplate("workflow")) - - workflow.steps = null - bluePrintContext.workflowFirstStepNodeTemplate("workflow") - } - - @Test(expected = BlueprintException::class) - fun testWorkflowStepFirstCallOperation() { - val topologyTemplate = TopologyTemplate() - val workflow = Workflow() - val step = Step() - val activity = Activity() - activity.callOperation = "hello" - step.activities = arrayListOf(activity) - workflow.steps = mutableMapOf("step" to step) - topologyTemplate.workflows = mutableMapOf("workflow" to workflow) - val serviceTemplate = ServiceTemplate() - serviceTemplate.topologyTemplate = topologyTemplate - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.workflowStepFirstCallOperation("workflow", "step")) - - bluePrintContext.workflowStepFirstCallOperation("workflow", "") - } - - @Test - fun testDatatypeByName() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.dataTypes = mutableMapOf("data" to DataType()) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.dataTypeByName("data")) - assertNull(bluePrintContext.dataTypeByName("")) - } - - @Test - fun testArtifactTypes() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.artifactTypes = mutableMapOf() - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.artifactTypes()!!.isEmpty()) - - serviceTemplate.artifactTypes = null - assertNull(bluePrintContext.artifactTypes()) - } - - @Test - fun testPolicyTypes() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.policyTypes = mutableMapOf() - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.policyTypes()!!.isEmpty()) - - serviceTemplate.policyTypes = null - assertNull(bluePrintContext.policyTypes()) - } - - @Test(expected = BlueprintException::class) - fun testPolicyTypeByName() { - val serviceTemplate = ServiceTemplate() - serviceTemplate.policyTypes = mutableMapOf("policy" to PolicyType()) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.policyTypeByName("policy")) - - bluePrintContext.policyTypeByName("") - } - - @Test - fun testPolicyTypesDerivedFrom() { - val serviceTemplate = ServiceTemplate() - val policyType = PolicyType() - policyType.derivedFrom = "hi" - val policyType2 = PolicyType() - policyType2.derivedFrom = "hello" - serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals(1, bluePrintContext.policyTypesDerivedFrom("hi")!!.size) - - serviceTemplate.policyTypes = null - assertNull(bluePrintContext.policyTypesDerivedFrom("hi")) - } - - @Test - fun testPolicyTypesTarget() { - val serviceTemplate = ServiceTemplate() - val policyType = PolicyType() - policyType.targets = mutableListOf("hi") - val policyType2 = PolicyType() - policyType2.targets = mutableListOf() - serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals(1, bluePrintContext.policyTypesTarget("hi")!!.size) - - serviceTemplate.policyTypes = null - assertNull(bluePrintContext.policyTypesTarget("hi")) - } - - @Test - fun testPolicyTypesTargetNDerivedFrom() { - val serviceTemplate = ServiceTemplate() - val policyType = PolicyType() - policyType.targets = mutableListOf("hi") - policyType.derivedFrom = "hi" - val policyType2 = PolicyType() - policyType2.targets = mutableListOf() - policyType2.derivedFrom = "hi" - serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals(1, bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi")!!.size) - - serviceTemplate.policyTypes = null - assertNull(bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi")) - } - - @Test - fun testNodeTypeDerivedFrom() { - val serviceTemplate = ServiceTemplate() - val nodeType = NodeType() - nodeType.derivedFrom = "hi" - val nodeType2 = NodeType() - nodeType2.derivedFrom = "hiii" - serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType, "node2" to nodeType2) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals(1, bluePrintContext.nodeTypeDerivedFrom("hi")!!.size) - - serviceTemplate.nodeTypes = null - assertNull(bluePrintContext.nodeTypeDerivedFrom("hi")) - } - - @Test(expected = BlueprintException::class) - fun testInterfaceNameForNodeType() { - val serviceTemplate = ServiceTemplate() - val nodeType = NodeType() - nodeType.interfaces = mutableMapOf("hello" to InterfaceDefinition(), "hi" to InterfaceDefinition()) - serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("hello", bluePrintContext.interfaceNameForNodeType("node")) - - bluePrintContext.interfaceNameForNodeType("") - } - - @Test - fun testNodeTemplateForNodeType() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.type = "hello" - val nodeTemplate2 = NodeTemplate() - nodeTemplate2.type = "hi" - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = - mutableMapOf("node" to nodeTemplate, "node2" to nodeTemplate2) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals(1, bluePrintContext.nodeTemplateForNodeType("hello")!!.size) - - serviceTemplate.topologyTemplate!!.nodeTemplates = null - assertNull(bluePrintContext.nodeTemplateForNodeType("hello")) - } - - @Test - fun testNodeTemplateProperty() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateProperty("node", "prop")) - - assertNull(bluePrintContext.nodeTemplateProperty("node", "")) - - nodeTemplate.properties = null - assertNull(bluePrintContext.nodeTemplateProperty("node", "prop")) - } - - @Test - fun testNodeTemplateArtifacts() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.artifacts = mutableMapOf() - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertTrue(bluePrintContext.nodeTemplateArtifacts("node")!!.isEmpty()) - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateArtifact() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.artifacts = mutableMapOf("art" to ArtifactDefinition()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateArtifact("node", "art")) - - bluePrintContext.nodeTemplateArtifact("node", "") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateArtifactForArtifactType() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - val artifactDefinition = ArtifactDefinition() - artifactDefinition.type = "type" - val artifactDefinition2 = ArtifactDefinition() - artifactDefinition2.type = "No type" - nodeTemplate.artifacts = mutableMapOf("art" to artifactDefinition, "art2" to artifactDefinition2) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateArtifactForArtifactType("node", "type")) - - bluePrintContext.nodeTemplateArtifactForArtifactType("", "") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateFirstInterface() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateFirstInterface("node")) - - nodeTemplate.interfaces = null - bluePrintContext.nodeTemplateFirstInterface("node") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateFirstInterfaceName() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("interface", bluePrintContext.nodeTemplateFirstInterfaceName("node")) - - nodeTemplate.interfaces = null - bluePrintContext.nodeTemplateFirstInterfaceName("node") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateFirstInterfaceFirstOperationName() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - val interfaceAssignment = InterfaceAssignment() - interfaceAssignment.operations = mutableMapOf("op" to OperationAssignment(), "op2" to OperationAssignment()) - nodeTemplate.interfaces = mutableMapOf("intf" to interfaceAssignment) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertEquals("op", bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node")) - - interfaceAssignment.operations = null - bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateCapability() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.capabilities = mutableMapOf("cap" to CapabilityAssignment()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateCapability("node", "cap")) - - bluePrintContext.nodeTemplateCapability("node", "") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateRequirement() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - nodeTemplate.requirements = mutableMapOf("req" to RequirementAssignment()) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateRequirement("node", "req")) - - bluePrintContext.nodeTemplateRequirement("node", "") - } - - @Test(expected = BlueprintException::class) - fun testNodeTemplateRequirementNode() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - val requirementAssignment = RequirementAssignment() - requirementAssignment.node = "node" - nodeTemplate.requirements = mutableMapOf("req" to requirementAssignment) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateRequirementNode("node", "req")) - - bluePrintContext.nodeTemplateRequirementNode("node", "") - } - - @Test - fun testNodeTemplateCapabilityProperty() { - val serviceTemplate = ServiceTemplate() - val nodeTemplate = NodeTemplate() - val capabilityAssignment = CapabilityAssignment() - capabilityAssignment.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode()) - nodeTemplate.capabilities = mutableMapOf("cap" to capabilityAssignment) - serviceTemplate.topologyTemplate = TopologyTemplate() - serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate) - val bluePrintContext = BlueprintContext(serviceTemplate) - - assertNotNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop")) - - capabilityAssignment.properties = null - - assertNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop")) - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintExpressionServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintExpressionServiceTest.kt deleted file mode 100644 index 552f7b6f8..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintExpressionServiceTest.kt +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.cds.controllerblueprints.core.data.ExpressionData -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -/** - * - * - * @author Brinda Santh - */ -class BlueprintExpressionServiceTest { - - @Test - fun testInputExpression() { - val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_input\" : \"input-name\" }") - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.inputExpression, " Failed to populate input expression data") - assertEquals("input-name", expressionData.inputExpression?.propertyName, "Failed to get propertyName from expression data") - } - - @Test - fun testPropertyExpression() { - val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"property-name\"] }") - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.propertyExpression, " Failed to populate property expression data") - assertEquals("SELF", expressionData.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("property-name", expressionData.propertyExpression?.propertyName, " Failed to get expected propertyName") - - val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_property\" : [\"SELF\", \"\",\"property-name\", \"resource\", \"name\"] }") - val expressionData1: ExpressionData = BlueprintExpressionService.getExpressionData(node1) - assertNotNull(expressionData1, " Failed to populate expression data") - assertEquals(expressionData1.isExpression, true, "Failed to identify as nested property expression") - assertNotNull(expressionData1.propertyExpression, " Failed to populate nested property expression data") - assertEquals("SELF", expressionData1.propertyExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("property-name", expressionData1.propertyExpression?.propertyName, " Failed to get expected propertyName") - assertEquals( - "resource.name", - expressionData1.propertyExpression?.subPropertyName, - " Failed to populate nested subPropertyName expression data" - ) - } - - @Test - fun testAttributeExpression() { - val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"resource\"] }") - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.attributeExpression, " Failed to populate attribute expression data") - assertEquals("SELF", expressionData.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("resource", expressionData.attributeExpression?.attributeName, " Failed to get expected attributeName") - - val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_attribute\" : [\"SELF\", \"\",\"attribute-name\", \"resource\", \"name\"] }") - val expressionData1: ExpressionData = BlueprintExpressionService.getExpressionData(node1) - assertNotNull(expressionData1, " Failed to populate expression data") - assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData1.attributeExpression, " Failed to populate attribute expression data") - assertEquals("SELF", expressionData1.attributeExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("attribute-name", expressionData1.attributeExpression?.attributeName, " Failed to get expected attributeName") - assertEquals( - "resource.name", - expressionData1.attributeExpression?.subAttributeName, - " Failed to populate nested subAttributeName expression data" - ) - } - - @Test - fun testOutputOperationExpression() { - val node: JsonNode = - jacksonObjectMapper().readTree("{ \"get_operation_output\": [\"SELF\", \"interface-name\", \"operation-name\", \"output-property-name\"] }") - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.operationOutputExpression, " Failed to populate output expression data") - assertEquals("SELF", expressionData.operationOutputExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("interface-name", expressionData.operationOutputExpression?.interfaceName, " Failed to get expected interfaceName") - assertEquals("operation-name", expressionData.operationOutputExpression?.operationName, " Failed to get expected operationName") - assertEquals("output-property-name", expressionData.operationOutputExpression?.propertyName, " Failed to get expected propertyName") - } - - @Test - fun testArtifactExpression() { - val node: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\"] }") - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.artifactExpression, " Failed to populate Artifact expression data") - assertEquals("SELF", expressionData.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("artifact-template", expressionData.artifactExpression?.artifactName, " Failed to get expected artifactName") - - val node1: JsonNode = jacksonObjectMapper().readTree("{ \"get_artifact\" : [\"SELF\", \"artifact-template\", \"location\", true] }") - val expressionData1: ExpressionData = BlueprintExpressionService.getExpressionData(node1) - assertNotNull(expressionData1, " Failed to populate expression data") - assertEquals(expressionData1.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData1.artifactExpression, " Failed to populate Artifact expression data") - assertEquals("SELF", expressionData1.artifactExpression?.modelableEntityName, " Failed to get expected modelableEntityName") - assertEquals("artifact-template", expressionData1.artifactExpression?.artifactName, " Failed to get expected artifactName") - assertEquals("location", expressionData1.artifactExpression?.location, " Failed to get expected location") - assertEquals(true, expressionData1.artifactExpression?.remove, " Failed to get expected remove") - } - - @Test - fun testDSLExpression() { - val node: JsonNode = "*dynamic-rest-source".asJsonPrimitive() - val expressionData: ExpressionData = BlueprintExpressionService.getExpressionData(node) - assertNotNull(expressionData, " Failed to populate expression data") - assertEquals(expressionData.isExpression, true, "Failed to identify as expression") - assertNotNull(expressionData.dslExpression, " Failed to populate dsl expression data") - assertEquals( - "dynamic-rest-source", expressionData.dslExpression!!.propertyName, - " Failed to populate dsl property name" - ) - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRepoFileServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRepoFileServiceTest.kt deleted file mode 100644 index 5ef28cce2..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRepoFileServiceTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import kotlin.test.assertNotNull - -/** - * BlueprintRepoFileServiceTest - * @author Brinda Santh - * - */ -class BlueprintRepoFileServiceTest { - - private val basePath = TestConstants.PATH_TEST_DEFINITION_TYPE_STARTER - private val bluePrintRepoFileService = BlueprintRepoFileService(basePath) - - @Test - fun testGetDataType() { - val dataType = bluePrintRepoFileService.getDataType("dt-v4-aggregate") - assertNotNull(dataType, "Failed to get DataType from repo") - } - - @Test - fun testGetNodeType() { - val nodeType = bluePrintRepoFileService.getNodeType("component-resource-resolution") - assertNotNull(nodeType, "Failed to get NodeType from repo") - } - - @Test - fun testGetArtifactType() { - val nodeType = bluePrintRepoFileService.getArtifactType("artifact-template-velocity") - assertNotNull(nodeType, "Failed to get ArtifactType from repo") - } - - @Test(expected = BlueprintException::class) - fun testModelNotFound() { - val dataType = bluePrintRepoFileService.getDataType("dt-not-found") - assertNotNull(dataType, "Failed to get DataType from repo") - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRuntimeServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRuntimeServiceTest.kt deleted file mode 100644 index 268811091..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintRuntimeServiceTest.kt +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018-2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import com.fasterxml.jackson.databind.JsonNode -import com.fasterxml.jackson.databind.node.NullNode -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintRuntimeUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -/** - * - * - * @author Brinda Santh - */ -class BlueprintRuntimeServiceTest { - - private val log = LoggerFactory.getLogger(this::class.toString()) - - @Test - fun `test Resolve NodeTemplate Properties`() { - log.info("************************ testResolveNodeTemplateProperties **********************") - - val bluePrintRuntimeService = getBlueprintRuntimeService() - - val inputDataPath = "src/test/resources/data/default-context.json" - - val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath) - bluePrintRuntimeService.assignInputs(inputNode) - - val propContext: MutableMap = bluePrintRuntimeService - .resolveNodeTemplateProperties("activate-process") - - assertNotNull(propContext, "Failed to populate interface property values") - } - - @Test - fun `test Resolve Relationship Properties`() { - log.info("************************ testResolveRelationshipTemplateProperties **********************") - - val bluePrintRuntimeService = getBlueprintRuntimeService() - - val inputDataPath = "src/test/resources/data/default-context.json" - - val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath) - bluePrintRuntimeService.assignInputs(inputNode) - - val propContext: MutableMap = bluePrintRuntimeService - .resolveRelationshipTemplateProperties("cli-device-properties") - - assertNotNull(propContext, "Failed to populate relationship property values") - assertEquals( - "localhost".asJsonPrimitive(), - propContext["connection-config"]!!.get("host"), - "failed to resolve expression" - ) - } - - @Test - fun `test resolve NodeTemplate Capability Properties`() { - log.info("************************ testResolveNodeTemplateRequirementProperties **********************") - val bluePrintRuntimeService = getBlueprintRuntimeService() - - val executionContext = bluePrintRuntimeService.getExecutionContext() - - BlueprintRuntimeUtils.assignInputsFromClassPathFile( - bluePrintRuntimeService.bluePrintContext(), - "data/default-context.json", executionContext - ) - - val assignmentParams = "{\n" + - " \"ipAddress\": \"127.0.0.1\",\n" + - " \"hostName\": \"vnf-host\"\n" + - " }" - - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment", "assignment-params", - JacksonUtils.jsonNode(assignmentParams) - ) - - val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties( - "sample-netconf-device", - "netconf" - ) - assertNotNull(capProperties, "Failed to populate capability property values") - assertEquals( - capProperties["target-ip-address"], - "127.0.0.1".asJsonPrimitive(), - "Failed to populate parameter target-ip-address" - ) - assertEquals( - capProperties["port-number"], - JacksonUtils.jsonNodeFromObject(830), - "Failed to populate parameter port-number" - ) - } - - @Test - fun `test Resolve NodeTemplate Interface Operation Inputs`() { - log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************") - - val bluePrintRuntimeService = getBlueprintRuntimeService() - - val executionContext = bluePrintRuntimeService.getExecutionContext() - - BlueprintRuntimeUtils.assignInputsFromClassPathFile( - bluePrintRuntimeService.bluePrintContext(), - "data/default-context.json", executionContext - ) - - val inContext: MutableMap = bluePrintRuntimeService - .resolveNodeTemplateInterfaceOperationInputs( - "resource-assignment", - "ResourceResolutionComponent", "process" - ) - - assertNotNull(inContext, "Failed to populate interface input property values") - assertEquals( - inContext["action-name"], - JacksonUtils.jsonNodeFromObject("sample-action"), - "Failed to populate parameter action-name" - ) - assertEquals( - inContext["request-id"], - JacksonUtils.jsonNodeFromObject("12345"), - "Failed to populate parameter action-name" - ) - } - - @Test - fun `test Resolve NodeTemplate Interface Operation Outputs`() { - log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************") - - val bluePrintRuntimeService = getBlueprintRuntimeService() - - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment", - "assignment-params", - NullNode.getInstance() - ) - - bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs( - "resource-assignment", - "ResourceResolutionComponent", "process" - ) - - val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue( - "resource-assignment", - "ResourceResolutionComponent", "process", "status" - ) - assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status") - - val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue( - "resource-assignment", - "ResourceResolutionComponent", "process", "resource-assignment-params" - ) - assertEquals( - NullNode.getInstance(), - outputParams, - "Failed to get operation property resource-assignment-params" - ) - } - - @Test - fun `test NodeTemplate Context Property`() { - log.info("************************ testNodeTemplateContextProperty **********************") - val bluePrintRuntimeService = getBlueprintRuntimeService() - - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment-ra-component", "context1", - JacksonUtils.jsonNodeFromObject("context1-value") - ) - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment-ra-component", "context2", - JacksonUtils.jsonNodeFromObject("context2-value") - ) - - val keys = listOf("context1", "context2") - - val jsonValueNode = - bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys) - assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties") - log.info("JSON Prepared Value Context {}", jsonValueNode) - } - - @Test - fun `test Resolve DSL Properties`() { - log.info("************************ resolveDSLExpression **********************") - - val bluePrintRuntimeService = getBlueprintRuntimeService() - - bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive()) - - val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source") - assertNotNull(resolvedJsonNode, "Failed to populate dsl property values") - } - - @Test - fun `test Resolve Workflow Outputs`() { - log.info("************************ resolvePropertyAssignments **********************") - val bluePrintRuntimeService = getBlueprintRuntimeService() - - val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}" - - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment", "assignment-params", - JacksonUtils.jsonNode(assignmentParams) - ) - - val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment") - assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values") - } - - @Test - fun `test resolvePropertyDefinitions using sub attributes`() { - val bluePrintRuntimeService = getBlueprintRuntimeService() - - bluePrintRuntimeService.setNodeTemplateAttributeValue( - "resource-assignment", "assignment-map", - JacksonUtils.jsonNode( - """ - { - "a-prefix":{ - "an-object":{ - "a-key":123 - } - } - } - """.trimIndent() - ) - ) - - val propertyDefinitions = mutableMapOf( - "resolution" to PropertyDefinition().apply { - this.type = "json" - this.value = JacksonUtils.jsonNode( - """ - { - "get_attribute":[ - "resource-assignment", - "", - "assignment-map", - "a-prefix", - "an-object", - "a-key" - ] - } - """.trimIndent() - ) - } - ) - - val result = bluePrintRuntimeService.resolvePropertyDefinitions("workflow", "WORKFLOW", propertyDefinitions) - - assertEquals("123", result["resolution"]!!.asText()) - } - - private fun getBlueprintRuntimeService(): BlueprintRuntimeService> { - val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG) - val blueprintRuntime = BlueprintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath) - val checkProcessId = blueprintRuntime.get(BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID) - val checkBasePath = blueprintRuntime.get(BlueprintConstants.PROPERTY_BLUEPRINT_BASE_PATH) - - assertEquals( - "1234".asJsonPrimitive(), - checkProcessId, "Failed to get process id after runtime creation" - ) - assertEquals( - blueprintBasePath.asJsonPrimitive(), - checkBasePath, "Failed to get base path after runtime creation" - ) - - return blueprintRuntime - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateServiceTest.kt deleted file mode 100644 index 6ebb6b7ff..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintTemplateServiceTest.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Modifications Copyright © 2019 IBM, Bell Canada. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import kotlin.test.BeforeTest -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -class BlueprintTemplateServiceTest { - - lateinit var blueprintRuntime: BlueprintRuntimeService<*> - - @BeforeTest - fun setup() { - val blueprintBasePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG - blueprintRuntime = BlueprintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath) - } - - @Test - fun testVelocityGeneratedContent() { - runBlocking { - val template = JacksonUtils.getClassPathFileContent("templates/base-config-velocity-template.vtl") - val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-velocity.json") - - val content = BlueprintVelocityTemplateService.generateContent(template, json) - assertNotNull(content, "failed to generate content for velocity template") - } - } - - @Test - fun testJinjaGeneratedContent() { - runBlocking { - val template = JacksonUtils.getClassPathFileContent("templates/master.jinja") - val json = JacksonUtils.getClassPathFileContent("templates/base-config-data-jinja.json") - - val element: MutableMap = mutableMapOf() - element["additional_array"] = arrayListOf( - hashMapOf("name" to "Element1", "location" to "Region0"), - hashMapOf("name" to "Element2", "location" to "Region1") - ) - - val content = BlueprintJinjaTemplateService.generateContent(template, json, false, element) - assertNotNull(content, "failed to generate content for velocity template") - } - } - - @Test - fun `no value variable should evaluate to default value - standalone template mesh test`() { - runBlocking { - val template = - JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") - val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json") - - val content = BlueprintVelocityTemplateService.generateContent(template, json) - // first line represents a variable whose value was successfully retrieved, second line contains a variable - // whose value could not be evaluated - val expected = "sample-hostname\n\${node0_backup_router_address}" - assertEquals(expected, content, "No value variable should use default value") - } - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintWorkflowServiceTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintWorkflowServiceTest.kt deleted file mode 100644 index 291a81f28..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BlueprintWorkflowServiceTest.kt +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.service - -import io.mockk.every -import io.mockk.mockk -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.async -import kotlinx.coroutines.awaitAll -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withTimeout -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.data.EdgeLabel -import org.onap.ccsdk.cds.controllerblueprints.core.data.Graph -import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.toGraph -import kotlin.test.assertNotNull - -class BlueprintWorkflowServiceTest { - - @Test - fun testSimpleFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>E/SUCCESS, E>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testMultipleFlows() { - runBlocking { - coroutineScope { - val wfs = listOf("12345", "12346").map { - async { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D"), null) - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(it), it) - assertNotNull(response, "failed to get response") - } - } - wfs.awaitAll() - } - } - } - - @Test - fun testMissingEdgeForBFailureState() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "C", "D", "E"), arrayListOf("B")) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testBExceptionFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, B>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "C", "D", "E"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testTimeoutExceptionFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>TO/SUCCESS, TO>C/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "TO", "C", "D", "E"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testConditionalFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testBothConditionalFlow() { - runBlocking { - // Failure Flow - val failurePatGraph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val failurePathWorkflow = TestBlueprintWorkFlowService() - failurePathWorkflow.simulatedState = prepareSimulation( - arrayListOf("B", "C", "D", "E"), - arrayListOf("A") - ) - val failurePathWorkflowInput = "123456" - val failurePathResponse = failurePathWorkflow.executeWorkflow(failurePatGraph, mockBlueprintRuntimeService(), failurePathWorkflowInput) - assertNotNull(failurePathResponse, "failed to get response") - } - } - - @Test - fun testMultipleSkipFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/FAILURE, C>D/SUCCESS, D>E/SUCCESS, B>E/SUCCESS, E>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D", "E"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - @Test - fun testParallelFlow() { - runBlocking { - val graph = "[START>A/SUCCESS, A>B/SUCCESS, A>C/SUCCESS, B>D/SUCCESS, C>D/SUCCESS, D>END/SUCCESS]" - .toGraph() - val simpleWorkflow = TestBlueprintWorkFlowService() - simpleWorkflow.simulatedState = prepareSimulation(arrayListOf("A", "B", "C", "D"), null) - val input = "123456" - val response = simpleWorkflow.executeWorkflow(graph, mockBlueprintRuntimeService(), input) - assertNotNull(response, "failed to get response") - } - } - - private fun mockBlueprintRuntimeService(): BlueprintRuntimeService<*> { - return mockBlueprintRuntimeService("123456") - } - - private fun mockBlueprintRuntimeService(id: String): BlueprintRuntimeService<*> { - val bluePrintRuntimeService = mockk>() - every { bluePrintRuntimeService.id() } returns id - return bluePrintRuntimeService - } - - private fun prepareSimulation(successes: List?, failures: List?): MutableMap { - val simulatedState: MutableMap = hashMapOf() - successes?.forEach { - simulatedState[it] = EdgeLabel.SUCCESS - } - failures?.forEach { - simulatedState[it] = EdgeLabel.FAILURE - } - return simulatedState - } -} - -class TestBlueprintWorkFlowService : - AbstractBlueprintWorkFlowService() { - - val log = logger(TestBlueprintWorkFlowService::class) - - lateinit var simulatedState: MutableMap - - override suspend fun initializeWorkflow(input: String): EdgeLabel { - return EdgeLabel.SUCCESS - } - - override suspend fun executeWorkflow(graph: Graph, bluePrintRuntimeService: BlueprintRuntimeService<*>, input: String): String { - log.info("Executing Graph : $graph") - this.graph = graph - this.workflowId = bluePrintRuntimeService.id() - val output = CompletableDeferred() - val startMessage = WorkflowExecuteMessage(input, output) - val workflowActor = workflowActor() - if (!workflowActor.isClosedForSend) { - workflowActor().send(startMessage) - } else { - throw BlueprintProcessorException("workflow actor is closed for send $workflowActor") - } - return startMessage.output.await() - } - - override suspend fun prepareNodeExecutionMessage(node: Graph.Node): - NodeExecuteMessage { - return NodeExecuteMessage(node, "$node Input", "") - } - - override suspend fun executeNode( - node: Graph.Node, - nodeInput: String, - nodeOutput: String - ): EdgeLabel { - // val random = (1..10).random() * 100 - // log.info("workflow($workflowId) node(${node.id}) will reply in $random ms") - // kotlinx.coroutines.delay(random.toLong()) - // //Simulation for timeout - if (node.id == "TO") { - withTimeout(1) { - kotlinx.coroutines.delay(2) - } - } - return simulatedState[node.id] ?: throw BlueprintException("failed to get status for the node($node)") - } - - override suspend fun prepareNodeSkipMessage(node: Graph.Node): NodeSkipMessage { - val nodeOutput = "" - return NodeSkipMessage(node, "$node Skip Input", nodeOutput) - } - - override suspend fun skipNode( - node: Graph.Node, - nodeInput: String, - nodeOutput: String - ): EdgeLabel { - return simulatedState[node.id] ?: throw BlueprintException("failed to get status for the node($node)") - } - - override suspend fun cancelNode( - node: Graph.Node, - nodeInput: String, - nodeOutput: String - ): EdgeLabel { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override suspend fun restartNode( - node: Graph.Node, - nodeInput: String, - nodeOutput: String - ): EdgeLabel { - TODO("not implemented") // To change body of created functions use File | Settings | File Templates. - } - - override suspend fun prepareWorkflowOutput(): String { - if (exceptions.isNotEmpty()) { - exceptions.forEach { - log.error("workflow($workflowId) exceptions :", it) - } - } - return "Final Response" - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt new file mode 100644 index 000000000..6e19656ec --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintFileUtilsTest.kt @@ -0,0 +1,57 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.utils + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import java.io.File +import java.nio.file.Paths +import kotlin.test.assertTrue + +class BluePrintFileUtilsTest { + + @Test + fun testNewBlueprint() = runBlocking { + val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-new-test") + BluePrintFileUtils.createEmptyBluePrint(targetPath) + } + + @Test + fun testBlueprintCopy() = runBlocking { + val sourcePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG + + val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-copy-test") + + val targetDir = File(targetPath) + targetDir.deleteOnExit() + // Copy the BP file + BluePrintFileUtils.copyBluePrint(sourcePath, targetDir.absolutePath) + + assertTrue(targetDir.exists(), "faield to copy blueprint to ${targetDir.absolutePath}") + + // Delete Type Files + BluePrintFileUtils.deleteBluePrintTypes(targetDir.absolutePath) + + // Generate the Type Files + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(sourcePath) + bluePrintContext.rootPath = targetDir.absolutePath + + BluePrintFileUtils.writeBluePrintTypes(bluePrintContext) + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt new file mode 100644 index 000000000..62bb0afcb --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintIOUtilsTest.kt @@ -0,0 +1,41 @@ +/* + * Copyright © 2019 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.utils + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintRetryException + +class BluePrintIOUtilsTest { + + @Test + fun testRetry() { + runBlocking { + val executionBlock: suspend (Int) -> String = { count: Int -> + "success" + } + val exceptionBlock = { e: Exception -> + if (e is BluePrintRetryException) { + println("this is blueprint error") + } else { + throw e + } + } + BluePrintIOUtils.retry(4, 0, 500, executionBlock, exceptionBlock) + } + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt new file mode 100644 index 000000000..6ccfe1e95 --- /dev/null +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintMetadataUtilsTest.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.utils + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants +import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintCompileCache +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class BluePrintMetadataUtilsTest { + + @Test + fun testToscaMetaData() { + + runBlocking { + val basePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG + + val toscaMetaData: ToscaMetaData = BluePrintMetadataUtils.toscaMetaData(basePath) + assertNotNull(toscaMetaData, "Missing Tosca Definition Object") + assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") + assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") + assertNotNull(toscaMetaData.createdBy, "Missing Created by") + assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") + assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") + } + } + + @Test + fun testKotlinBluePrintContext() { + runBlocking { + val path = normalizedPathName("src/test/resources/compile") + val blueprintContext = BluePrintMetadataUtils.getBluePrintContext(path) + assertNotNull(blueprintContext, "failed to get blueprint context") + assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template") + assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template") + assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions") + + var cachePresent = BluePrintCompileCache.hasClassLoader(path) + assertTrue(cachePresent, "failed to generate cache key ($path)") + + /** Cleaning Cache */ + BluePrintCompileCache.cleanClassLoader(path) + cachePresent = BluePrintCompileCache.hasClassLoader(path) + assertTrue(!cachePresent, "failed to remove cache key ($path)") + } + } + + @Test + fun environmentDataTest() { + val environmentPath = "./src/test/resources/environments" + + val properties = BluePrintMetadataUtils.bluePrintEnvProperties(environmentPath) + + assertNotNull(properties, "Could not read the properties") + assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.username"), "username1", "failed 1") + assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.password"), "password1", "failed 2") + assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.username"), "username2", "failed 3") + assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.password"), "password2", "failed 4") + assertNull(properties.getProperty("blueprintsprocessor.database.alt3.password"), "failed 5") + } +} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintFileUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintFileUtilsTest.kt deleted file mode 100644 index ac74f7ab1..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintFileUtilsTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.utils - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import java.io.File -import java.nio.file.Paths -import kotlin.test.assertTrue - -class BlueprintFileUtilsTest { - - @Test - fun testNewBlueprint() = runBlocking { - val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-new-test") - BlueprintFileUtils.createEmptyBlueprint(targetPath) - } - - @Test - fun testBlueprintCopy() = runBlocking { - val sourcePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG - - val targetPath: String = Paths.get("target").toUri().toURL().path.plus("/bp-copy-test") - - val targetDir = File(targetPath) - targetDir.deleteOnExit() - // Copy the BP file - BlueprintFileUtils.copyBlueprint(sourcePath, targetDir.absolutePath) - - assertTrue(targetDir.exists(), "faield to copy blueprint to ${targetDir.absolutePath}") - - // Delete Type Files - BlueprintFileUtils.deleteBlueprintTypes(targetDir.absolutePath) - - // Generate the Type Files - val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(sourcePath) - bluePrintContext.rootPath = targetDir.absolutePath - - BlueprintFileUtils.writeBlueprintTypes(bluePrintContext) - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintIOUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintIOUtilsTest.kt deleted file mode 100644 index d0c32cc39..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintIOUtilsTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.utils - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintRetryException - -class BlueprintIOUtilsTest { - - @Test - fun testRetry() { - runBlocking { - val executionBlock: suspend (Int) -> String = { count: Int -> - "success" - } - val exceptionBlock = { e: Exception -> - if (e is BlueprintRetryException) { - println("this is blueprint error") - } else { - throw e - } - } - BlueprintIOUtils.retry(4, 0, 500, executionBlock, exceptionBlock) - } - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintMetadataUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintMetadataUtilsTest.kt deleted file mode 100644 index b03fb9fc1..000000000 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BlueprintMetadataUtilsTest.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.utils - -import kotlinx.coroutines.runBlocking -import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.TestConstants -import org.onap.ccsdk.cds.controllerblueprints.core.data.ToscaMetaData -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BlueprintCompileCache -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull -import kotlin.test.assertTrue - -class BlueprintMetadataUtilsTest { - - @Test - fun testToscaMetaData() { - - runBlocking { - val basePath = TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG - - val toscaMetaData: ToscaMetaData = BlueprintMetadataUtils.toscaMetaData(basePath) - assertNotNull(toscaMetaData, "Missing Tosca Definition Object") - assertNotNull(toscaMetaData.toscaMetaFileVersion, "Missing Tosca Metadata Version") - assertNotNull(toscaMetaData.csarVersion, "Missing CSAR version") - assertNotNull(toscaMetaData.createdBy, "Missing Created by") - assertNotNull(toscaMetaData.entityDefinitions, "Missing Tosca Entity Definition") - assertNotNull(toscaMetaData.templateTags, "Missing Template Tags") - } - } - - @Test - fun testKotlinBlueprintContext() { - runBlocking { - val path = normalizedPathName("src/test/resources/compile") - val blueprintContext = BlueprintMetadataUtils.getBlueprintContext(path) - assertNotNull(blueprintContext, "failed to get blueprint context") - assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template") - assertNotNull(blueprintContext.serviceTemplate, "failed to get blueprint context service template") - assertNotNull(blueprintContext.otherDefinitions, "failed to get blueprint contextother definitions") - - var cachePresent = BlueprintCompileCache.hasClassLoader(path) - assertTrue(cachePresent, "failed to generate cache key ($path)") - - /** Cleaning Cache */ - BlueprintCompileCache.cleanClassLoader(path) - cachePresent = BlueprintCompileCache.hasClassLoader(path) - assertTrue(!cachePresent, "failed to remove cache key ($path)") - } - } - - @Test - fun environmentDataTest() { - val environmentPath = "./src/test/resources/environments" - - val properties = BlueprintMetadataUtils.bluePrintEnvProperties(environmentPath) - - assertNotNull(properties, "Could not read the properties") - assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.username"), "username1", "failed 1") - assertEquals(properties.getProperty("blueprintsprocessor.database.alt1.password"), "password1", "failed 2") - assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.username"), "username2", "failed 3") - assertEquals(properties.getProperty("blueprintsprocessor.database.alt2.password"), "password2", "failed 4") - assertNull(properties.getProperty("blueprintsprocessor.database.alt3.password"), "failed 5") - } -} diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtilsTest.kt index ec12639fb..d78e62f28 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtilsTest.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtilsTest.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.slf4j.LoggerFactory import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -57,19 +57,19 @@ class JacksonUtilsTest { val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath) assertNotNull(rootJson, "Failed to get all type data json node") val intValue = rootJson.get("intValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value") val floatValue = rootJson.get("floatValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value") val stringValue = rootJson.get("stringValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value") val booleanValue = rootJson.get("booleanValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value") val arrayStringValue = rootJson.get("arrayStringValue") - assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value") + assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value") // FIX needed for ("complex type JSON & MAP") // val mapValue = rootJson.get("mapValue") - // assertTrue(JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value") + // assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value") - assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BlueprintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed") + assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed") } } diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/PropertyDefinitionUtilsTest.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/PropertyDefinitionUtilsTest.kt index f2d63531d..83764c517 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/PropertyDefinitionUtilsTest.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/PropertyDefinitionUtilsTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.utils import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants.LOG_PROTECT +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants.LOG_PROTECT import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.cds.controllerblueprints.core.utils.PropertyDefinitionUtils.Companion.hasLogProtect import kotlin.test.assertFalse diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/resources/compile/Scripts/kotlin/ActivateBlueprintDefinitions.kt b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/resources/compile/Scripts/kotlin/ActivateBlueprintDefinitions.kt index 4ba7694ee..5dd1937f8 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/resources/compile/Scripts/kotlin/ActivateBlueprintDefinitions.kt +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/test/resources/compile/Scripts/kotlin/ActivateBlueprintDefinitions.kt @@ -16,13 +16,13 @@ package cba.scripts -import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate import org.onap.ccsdk.cds.controllerblueprints.core.dsl.dataType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBlueprintDefinitions +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.AbstractBluePrintDefinitions -class ActivateBlueprintDefinitions : AbstractBlueprintDefinitions() { +class ActivateBlueprintDefinitions : AbstractBluePrintDefinitions() { override fun serviceTemplate(): ServiceTemplate { @@ -46,10 +46,10 @@ class ActivateBlueprintDefinitions : AbstractBlueprintDefinitions() { /** Sample Definitions */ val customDataType = dataType( "custom-datatype", "1.0.0", - BlueprintConstants.MODEL_TYPE_DATATYPES_ROOT, "" + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT, "" ) { - property("name", BlueprintConstants.DATA_TYPE_STRING, true, "") - property("value", BlueprintConstants.DATA_TYPE_STRING, true, "") + property("name", BluePrintConstants.DATA_TYPE_STRING, true, "") + property("value", BluePrintConstants.DATA_TYPE_STRING, true, "") } /** Loading to definitions */ addOtherDefinition("datatype-custom-datatype", customDataType) -- cgit 1.2.3-korg