From e1db2469a8e42d591bd905e588975be0f2a8861e Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Sun, 7 Aug 2022 23:01:52 -0400 Subject: Refactoring Code to remove NRM Renaming Classes, API's, variabled and removing NRM word from codebase Issue-ID: CCSDK-3741 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I8150eec7e8fb0bc1d33e80991215e745e9aa79d0 (cherry picked from commit cc2dbf6d08840ba0e105e44022568d9afd130273) --- .../functions/restful-executor/pom.xml | 4 +- .../restful/executor/RestfulCMComponentFunction.kt | 25 ++-- .../executor/function/RestfulServiceClient.kt | 111 +++++++++++++++ .../nrmfunction/RestfulNRMServiceClient.kt | 111 --------------- .../executor/function/RestfulServiceClientTest.kt | 156 +++++++++++++++++++++ .../nrmfunction/RestfulNRMServiceClientTest.kt | 156 --------------------- 6 files changed, 281 insertions(+), 282 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/function/RestfulServiceClient.kt delete mode 100644 ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt create mode 100644 ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/function/RestfulServiceClientTest.kt delete mode 100644 ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt (limited to 'ms') diff --git a/ms/blueprintsprocessor/functions/restful-executor/pom.xml b/ms/blueprintsprocessor/functions/restful-executor/pom.xml index ed0fdc950..9c154f10f 100644 --- a/ms/blueprintsprocessor/functions/restful-executor/pom.xml +++ b/ms/blueprintsprocessor/functions/restful-executor/pom.xml @@ -26,8 +26,8 @@ org.onap.ccsdk.cds.blueprintsprocessor.functions restful-executor - MS Blueprints Processor Functions - NRM Restful executor - Blueprints Processor Function - NRM Restful executor + MS Blueprints Processor Functions - Restful executor + Blueprints Processor Function - Restful executor diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt index 9cd6f57a4..6b5af807e 100644 --- a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt +++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/RestfulCMComponentFunction.kt @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.ArrayNode import com.fasterxml.jackson.databind.node.ObjectNode import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.nrmfunction.RestfulNRMServiceClient +import org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor.function.RestfulServiceClient import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService @@ -49,7 +49,7 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { fun processNRM(executionRequest: ExecutionServiceInput, input_params: ArrayNode): String { // process the managed object instances - log.info("Processing NRM Object") + log.info("Processing Object") operationInputs = executionServiceInput.stepData!!.properties val dynamic_properties = operationInputs.get("dynamic-properties") // instantiate one restClientService instance @@ -75,9 +75,9 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { for (managed_object_instance in managed_object_instances) { // invoke createMOI for each managed-object-instance log.info("invoke createMOI for each managed-object-instance") - var NRM_Restful_client = RestfulNRMServiceClient() - val MOI_id = NRM_Restful_client.generateMOIid() - var httpresponse = NRM_Restful_client.createMOI(web_client_service, MOI_id, managed_object_instance) + var Restful_client = RestfulServiceClient() + val MOI_id = Restful_client.generateMOIid() + var httpresponse = Restful_client.createMOI(web_client_service, MOI_id, managed_object_instance) var MOIname = managed_object_instance.get("className").toString().replace("\"", "") response.put("/$MOIname/$MOI_id", httpresponse) } @@ -86,9 +86,9 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { for (managed_object_instance in managed_object_instances) { // invoke getMOIAttributes for each managed-object-instance log.info("invoke getMOIAttributes for each managed-object-instance") - var NRM_Restful_client = RestfulNRMServiceClient() + var Restful_client = RestfulServiceClient() val MOI_id = managed_object_instance.get("id").toString().replace("\"", "") - var httpresponse = NRM_Restful_client.getMOIAttributes(web_client_service, MOI_id, managed_object_instance) + var httpresponse = Restful_client.getMOIAttributes(web_client_service, MOI_id, managed_object_instance) var MOIname = managed_object_instance.get("className").toString().replace("\"", "") response.put("/$MOIname/$MOI_id", httpresponse) } @@ -97,9 +97,9 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { for (managed_object_instance in managed_object_instances) { // invoke modifyMOIAttributes for each managed-object-instance log.info("invoke modifyMOIAttributes for each managed-object-instance") - var NRM_Restful_client = RestfulNRMServiceClient() + var Restful_client = RestfulServiceClient() val MOI_id = managed_object_instance.get("id").toString().replace("\"", "") - var httpresponse = NRM_Restful_client.modifyMOIAttributes(web_client_service, MOI_id, managed_object_instance) + var httpresponse = Restful_client.modifyMOIAttributes(web_client_service, MOI_id, managed_object_instance) var MOIname = managed_object_instance.get("className").toString().replace("\"", "") response.put("/$MOIname/$MOI_id", httpresponse) } @@ -108,9 +108,9 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { for (managed_object_instance in managed_object_instances) { // invoke deleteMOI for each managed-object-instance log.info("invoke deleteMOI for each managed-object-instance") - var NRM_Restful_client = RestfulNRMServiceClient() + var Restful_client = RestfulServiceClient() val MOI_id = managed_object_instance.get("id").toString().replace("\"", "") - var httpresponse = NRM_Restful_client.deleteMOI(web_client_service, MOI_id, managed_object_instance) + var httpresponse = Restful_client.deleteMOI(web_client_service, MOI_id, managed_object_instance) var MOIname = managed_object_instance.get("className").toString().replace("\"", "") response.put("/$MOIname/$MOI_id", httpresponse) } @@ -120,7 +120,6 @@ abstract class RestfulCMComponentFunction : AbstractScriptComponentFunction() { response.put(this.workflowName, "Not Implemented") } } - val strresponse = "$response" - return strresponse + return "$response" } } diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/function/RestfulServiceClient.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/function/RestfulServiceClient.kt new file mode 100644 index 000000000..8b3fd2a5f --- /dev/null +++ b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/function/RestfulServiceClient.kt @@ -0,0 +1,111 @@ +/* + * 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.function + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.http.HttpMethod +import org.springframework.web.util.UriComponentsBuilder +import java.util.UUID + +class RestfulServiceClient() { + + private val log = logger(RestfulServiceClient::class.java) + + fun createMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { + val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") + val pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" + log.info("MOI Path: " + pathStr) + var request_object_value = JacksonUtils.jsonNode("{}") as ObjectNode + request_object_value.put("attributes", managed_object_instance.get("data")) + request_object_value.put("href", "/" + classNameStr + "/" + idStr) + request_object_value.put("class", classNameStr) + request_object_value.put("id", idStr) + var request_object = JacksonUtils.jsonNode("{}") as ObjectNode + request_object.put("data", request_object_value) + val requestBodystr = request_object.toString() + log.info("MOI request body: " + requestBodystr) + val response = web_client_service.exchangeResource(HttpMethod.PUT.name, pathStr, requestBodystr) + var response_object = generateResponse(response.status, response.body) + log.info("MOI response status: " + response.status) + return response_object + } + + fun getMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { + val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") + var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" + pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) + pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) + for (attribute_value in managed_object_instance.get("fields")) { + pathStr = addQueryParameters(pathStr, "fields", attribute_value.toString().replace("\"", "")) + } + log.info("MOI Path: " + pathStr) + val response = web_client_service.exchangeResource(HttpMethod.GET.name, pathStr, "") + log.info("MOI response status: " + response.status) + var response_object = generateResponse(response.status, response.body) + return response_object + } + + fun modifyMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { + val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") + var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" + pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) + pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) + log.info("MOI Path: " + pathStr) + var request_object = JacksonUtils.jsonNode("{}") as ObjectNode + request_object.put("data", managed_object_instance.get("data")) + val requestBodystr = request_object.toString() + log.info("MOI request body: " + requestBodystr) + val response = web_client_service.exchangeResource(HttpMethod.PATCH.name, pathStr, requestBodystr) + log.info("MOI response status: " + response.status) + var response_object = generateResponse(response.status, response.body) + return response_object + } + + fun deleteMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { + val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") + var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" + pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) + pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) + log.info("MOI Path: " + pathStr) + val response = web_client_service.exchangeResource(HttpMethod.DELETE.name, pathStr, "") + log.info("MOI response status: " + response.status) + var response_object = generateResponse(response.status, response.body) + return response_object + } + + fun generateResponse(status: Int, body: String): ObjectNode { + var response_object = JacksonUtils.jsonNode("{}") as ObjectNode + response_object.put("status", status) + val mapper = ObjectMapper() + val response_body: JsonNode = mapper.readTree(body) + response_object.put("body", response_body) + return response_object + } + + fun generateMOIid(): String { + return UUID.randomUUID().toString() + } + + fun addQueryParameters(old_uri: String, key: String, value: String): String { + return UriComponentsBuilder.fromUriString(old_uri).queryParam(key, value).build().toString() + } +} diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt b/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt deleted file mode 100644 index 259670d47..000000000 --- a/ms/blueprintsprocessor/functions/restful-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/restful/executor/nrmfunction/RestfulNRMServiceClient.kt +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.JsonNode -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.node.ObjectNode -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.cds.controllerblueprints.core.logger -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.http.HttpMethod -import org.springframework.web.util.UriComponentsBuilder -import java.util.UUID - -class RestfulNRMServiceClient() { - - private val log = logger(RestfulNRMServiceClient::class.java) - - fun createMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { - val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") - val pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" - log.info("MOI Path: " + pathStr) - var request_object_value = JacksonUtils.jsonNode("{}") as ObjectNode - request_object_value.put("attributes", managed_object_instance.get("data")) - request_object_value.put("href", "/" + classNameStr + "/" + idStr) - request_object_value.put("class", classNameStr) - request_object_value.put("id", idStr) - var request_object = JacksonUtils.jsonNode("{}") as ObjectNode - request_object.put("data", request_object_value) - val requestBodystr = request_object.toString() - log.info("MOI request body: " + requestBodystr) - val response = web_client_service.exchangeResource(HttpMethod.PUT.name, pathStr, requestBodystr) - var response_object = generateResponse(response.status, response.body) - log.info("MOI response status: " + response.status) - return response_object - } - - fun getMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { - val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") - var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" - pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) - pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) - for (attribute_value in managed_object_instance.get("fields")) { - pathStr = addQueryParameters(pathStr, "fields", attribute_value.toString().replace("\"", "")) - } - log.info("MOI Path: " + pathStr) - val response = web_client_service.exchangeResource(HttpMethod.GET.name, pathStr, "") - log.info("MOI response status: " + response.status) - var response_object = generateResponse(response.status, response.body) - return response_object - } - - fun modifyMOIAttributes(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { - val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") - var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" - pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) - pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) - log.info("MOI Path: " + pathStr) - var request_object = JacksonUtils.jsonNode("{}") as ObjectNode - request_object.put("data", managed_object_instance.get("data")) - val requestBodystr = request_object.toString() - log.info("MOI request body: " + requestBodystr) - val response = web_client_service.exchangeResource(HttpMethod.PATCH.name, pathStr, requestBodystr) - log.info("MOI response status: " + response.status) - var response_object = generateResponse(response.status, response.body) - return response_object - } - - fun deleteMOI(web_client_service: BlueprintWebClientService, idStr: String, managed_object_instance: JsonNode): ObjectNode { - val classNameStr = managed_object_instance.get("className").toString().replace("\"", "") - var pathStr = "/ProvisioningMnS/v1500/$classNameStr/$idStr" - pathStr = addQueryParameters(pathStr, "scope", managed_object_instance.get("scope").toString().replace("\"", "")) - pathStr = addQueryParameters(pathStr, "filter", managed_object_instance.get("filter").toString().replace("\"", "")) - log.info("MOI Path: " + pathStr) - val response = web_client_service.exchangeResource(HttpMethod.DELETE.name, pathStr, "") - log.info("MOI response status: " + response.status) - var response_object = generateResponse(response.status, response.body) - return response_object - } - - fun generateResponse(status: Int, body: String): ObjectNode { - var response_object = JacksonUtils.jsonNode("{}") as ObjectNode - response_object.put("status", status) - val mapper = ObjectMapper() - val response_body: JsonNode = mapper.readTree(body) - response_object.put("body", response_body) - return response_object - } - - fun generateMOIid(): String { - return UUID.randomUUID().toString() - } - - fun addQueryParameters(old_uri: String, key: String, value: String): String { - return UriComponentsBuilder.fromUriString(old_uri).queryParam(key, value).build().toString() - } -} diff --git a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/function/RestfulServiceClientTest.kt b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/function/RestfulServiceClientTest.kt new file mode 100644 index 000000000..e450d1150 --- /dev/null +++ b/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/function/RestfulServiceClientTest.kt @@ -0,0 +1,156 @@ +/* + * 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.function + +import com.fasterxml.jackson.databind.node.ObjectNode +import org.junit.Ignore +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +@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 RestfulServiceClientTest { + + @Autowired + lateinit var restfulServiceClient: RestfulServiceClient + lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + + @Test + fun testCreateMOI() { + val restClientService = bluePrintRestLibPropertyService.blueprintWebClientService("nrm") + val idStr = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 = restfulServiceClient.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 { + var a = "{\n" + "\"data\" : \"Create MOI object successfully" + "}" + return ResponseEntity(a, HttpStatus.OK) + } + + @GetMapping("/TestMangedObjectInstance") + fun getMOI(): ResponseEntity { + var a = "{\n" + "\"data\" : \"Get MOI object attributes successfully" + "}" + return ResponseEntity(a, HttpStatus.OK) + } + + @PatchMapping("/TestMangedObjectInstance") + fun patchMOI(): ResponseEntity { + var a = "{\n" + "\"data\" : \"Modify MOI object attributes successfully" + "}" + return ResponseEntity(a, HttpStatus.OK) + } + + @DeleteMapping("/TestMangedObjectInstance") + fun deleteMOI(): ResponseEntity { + var a = "{\n" + "\"data\" : \"Delete MOI object attributes successfully" + "}" + return ResponseEntity(a, HttpStatus.OK) + } +} 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 deleted file mode 100644 index 6f76c9b40..000000000 --- a/ms/blueprintsprocessor/functions/restful-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/restful/executor/nrmfunction/RestfulNRMServiceClientTest.kt +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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.junit.Ignore -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.rest.BluePrintRestLibConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PutMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import kotlin.test.assertEquals -import kotlin.test.assertNotNull - -@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 { - var a = "{\n" + "\"data\" : \"Create MOI object successfully" + "}" - return ResponseEntity(a, HttpStatus.OK) - } - - @GetMapping("/TestMangedObjectInstance") - fun getMOI(): ResponseEntity { - var a = "{\n" + "\"data\" : \"Get MOI object attributes successfully" + "}" - return ResponseEntity(a, HttpStatus.OK) - } - - @PatchMapping("/TestMangedObjectInstance") - fun patchMOI(): ResponseEntity { - var a = "{\n" + "\"data\" : \"Modify MOI object attributes successfully" + "}" - return ResponseEntity(a, HttpStatus.OK) - } - - @DeleteMapping("/TestMangedObjectInstance") - fun deleteMOI(): ResponseEntity { - var a = "{\n" + "\"data\" : \"Delete MOI object attributes successfully" + "}" - return ResponseEntity(a, HttpStatus.OK) - } -} -- cgit 1.2.3-korg