aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin
diff options
context:
space:
mode:
authorHuang Cheng <duke.huangcheng@huawei.com>2020-02-04 03:53:15 +0000
committerHuang Cheng <duke.huangcheng@huawei.com>2020-03-06 01:21:14 +0000
commitfdfeef7ae2f543553e2f7a7cf322b6d075599e20 (patch)
tree9bb5488db6a724c7a70bcf182df8f609456b4ff6 /ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin
parentc2c379246a6d231e9424308c398a15fcb6618fc3 (diff)
Add the executor and the component function to support 5G NRM CM
The executor and the component function are designed to invoke the 5G NRM CM opertions: createMOI getMOIAttributes modifyMOIAttributes and deleteMOI Issue-ID: CCSDK-2003 Signed-off-by: Huang Cheng <duke.huangcheng@huawei.com> Change-Id: I20d3e97c01f6499e73ab0ec77abbc24775f428b7
Diffstat (limited to 'ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin')
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt105
-rw-r--r--ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt150
2 files changed, 255 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
new file mode 100644
index 000000000..ad70ac021
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/ComponentRestfulExecutorTest.kt
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2020 Huawei Intellectual Property.
+ *
+ * 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.blueprintsprocessor.functions.restful.executor
+
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.mockk.every
+import io.mockk.mockk
+import kotlinx.coroutines.runBlocking
+import org.junit.Test
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
+import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.springframework.context.ApplicationContext
+
+class ComponentRestfulExecutorTest {
+
+ @Test
+ fun testComponentRestfulExecutor() {
+ runBlocking {
+
+ val applicationContext = mockk<ApplicationContext>()
+ every { applicationContext.getBean(any()) } returns mockk()
+
+ val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
+
+ val componentRestfulExecutor = ComponentRestfulExecutor(componentFunctionScriptingService)
+
+ val executionServiceInput = ExecutionServiceInput().apply {
+ commonHeader = CommonHeader().apply {
+ requestId = "1234"
+ }
+ actionIdentifiers = ActionIdentifiers().apply {
+ actionName = "config-deploy"
+ }
+ payload = JacksonUtils.jsonNode("{}") as ObjectNode
+ }
+
+ val blueprintContext = mockk<BluePrintContext>()
+ every {
+ blueprintContext.nodeTemplateOperationImplementation(
+ any(), any(), any()
+ )
+ } returns Implementation()
+
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
+ every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
+
+ componentRestfulExecutor.bluePrintRuntimeService = bluePrintRuntime
+ componentRestfulExecutor.stepName = "sample-step"
+
+ val operationInputs = hashMapOf<String, JsonNode>()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "config-deploy-process".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
+ operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
+ operationInputs["script-type"] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
+ operationInputs["script-class-reference"] = "internal.scripts.TestRestfulConfigure".asJsonPrimitive()
+
+ val stepInputData = StepData().apply {
+ name = "call-config-deploy-process"
+ properties = operationInputs
+ }
+ executionServiceInput.stepData = stepInputData
+
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationInputs
+
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
+ "config-deploy-process",
+ "interfaceName", "operationName"
+ )
+ } returns operationOutputs
+
+ componentRestfulExecutor.applyNB(executionServiceInput)
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
new file mode 100644
index 000000000..e7f04a5d4
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt
@@ -0,0 +1,150 @@
+/*
+ * Copyright © 2019 Huawei.
+ *
+ * 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.blueprintsprocessor.functions.restful.executor.nrmfunction
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.junit.Test
+import org.junit.Ignore
+import org.springframework.beans.factory.annotation.Autowired
+import org.junit.runner.RunWith
+import org.springframework.test.context.junit4.SpringRunner
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.ContextConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import kotlin.test.assertNotNull
+import kotlin.test.assertEquals
+import org.springframework.web.bind.annotation.RestController
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.PutMapping
+import org.springframework.web.bind.annotation.GetMapping
+import org.springframework.web.bind.annotation.PatchMapping
+import org.springframework.web.bind.annotation.DeleteMapping
+import org.springframework.http.ResponseEntity
+import org.springframework.http.HttpStatus
+
+@RunWith(SpringRunner::class)
+@EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class])
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
+@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, NrmTestController::class])
+@TestPropertySource(properties = [
+ "blueprintsprocessor.restclient.nrm.type=basic-auth",
+ "blueprintsprocessor.restclient.nrm.url=http://127.0.0.1:8080",
+ "blueprintsprocessor.restclient.nrm.username=admin",
+ "blueprintsprocessor.restclient.nrm.password=admin"
+])
+
+@Ignore
+class RestfulNRMServiceClientTest {
+
+ @Autowired
+ lateinit var restfulNRMServiceClient: RestfulNRMServiceClient
+ lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
+
+ @Test
+ fun testCreateMOI() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ var test_attributes_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_attributes_data.put("test_attribute_key", "test_attribute_value")
+ test_moi_data.put("data", test_attributes_data)
+ val response = restfulNRMServiceClient.createMOI(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get createMOI response")
+ assertEquals("Create MOI object successfully", response.get("body").get("data").toString(), "failed to get createMOI response")
+ }
+
+ @Test
+ fun testGetMOIAttributes() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ test_moi_data.put("fields", "test_attribute_key")
+ val response = restfulNRMServiceClient.getMOIAttributes(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get getMOIAttributes response")
+ assertEquals("Get MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get getMOIAttributes response")
+ }
+
+ @Test
+ fun testModifyMOIAttributes() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ var test_attributes_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_attributes_data.put("test_attribute_key", "modified_attribute_value")
+ test_moi_data.put("data", test_attributes_data)
+ val response = restfulNRMServiceClient.modifyMOIAttributes(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get modifyMOIAttributes response")
+ assertEquals("Modify MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get modifyMOIAttributes response")
+ }
+
+ @Test
+ fun testDeleteMOI() {
+ val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm")
+ val idStr = restfulNRMServiceClient.generateMOIid()
+ var test_moi_data = JacksonUtils.jsonNode("{}") as ObjectNode
+ test_moi_data.put("className", "TestMangedObjectInstance")
+ test_moi_data.put("scope", "BASE_ONLY")
+ test_moi_data.put("filter", "TestMangedObjectInstance")
+ val response = restfulNRMServiceClient.deleteMOI(restClientService, idStr, test_moi_data)
+ assertNotNull(response, "failed to get delete response")
+ assertEquals("Delete MOI object attributes successfully", response.get("body").get("data").toString(), "failed to get delete response")
+ }
+}
+
+/**
+ * Sample controller code for testing the above four functions.
+ */
+@RestController
+@RequestMapping("/ProvisioningMnS/v1500")
+open class NrmTestController {
+
+ @PutMapping("/TestMangedObjectInstance")
+ fun putMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Create MOI object successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @GetMapping("/TestMangedObjectInstance")
+ fun getMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Get MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @PatchMapping("/TestMangedObjectInstance")
+ fun patchMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Modify MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+
+ @DeleteMapping("/TestMangedObjectInstance")
+ fun deleteMOI(): ResponseEntity<Any> {
+ var a = "{\n" + "\"data\" : \"Delete MOI object attributes successfully" + "}"
+ return ResponseEntity(a, HttpStatus.OK)
+ }
+}