From c0e77765214b94cc493b181bcc1d58165ac8b09f Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 28 Aug 2018 23:58:12 +0000 Subject: Controller Blueprints Microservice Add Resource Assignment Validation Service and their Test cases. Change-Id: I106be2bfc03115867041ca341947a4662cf126c4 Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../core/service/BluePrintRepoService.kt | 12 ++++++------ .../controllerblueprints/core/utils/JacksonUtils.kt | 18 ++++++++++++++++-- .../core/service/BluePrintRepoFileServiceTest.kt | 5 +---- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'ms/controllerblueprints/modules/core') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt index 8c444618..8c254732 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt @@ -61,12 +61,12 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService { private val log: Logger = LoggerFactory.getLogger(BluePrintRepoFileService::class.java) - val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) - val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) - val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) - val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) - val extension = ".json" + private val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + private val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE) + private val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE) + private val capabilityTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE) + private val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE) + private val extension = ".json" override fun getDataType(dataTypeName: String): Mono? { val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER) diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 697a7100..886c3d2a 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -102,6 +102,20 @@ object JacksonUtils { return objectMapper.readValue>(content, javaType) } + @JvmStatic + fun getListFromFile(fileName: String, valueType: Class): List? { + val content: String = FileUtils.readFileToString(File(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(format("Failed to read json file : {}", fileName)) + return getListFromJson(content, valueType) + } + + @JvmStatic + fun getListFromClassPathFile(fileName: String, valueType: Class): List? { + val content: String = IOUtils.toString(JacksonUtils::class.java.classLoader.getResourceAsStream(fileName), Charset.defaultCharset()) + ?: throw BluePrintException(String.format("Failed to read json file : %s", fileName)) + return getListFromJson(content, valueType) + } + @JvmStatic fun getMapFromJson(content: String, valueType: Class): MutableMap? { val objectMapper = jacksonObjectMapper() @@ -110,13 +124,13 @@ object JacksonUtils { } @JvmStatic - fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode) : Boolean { + fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode): Boolean { if (BluePrintTypes.validPrimitiveTypes().contains(type)) { return checkJsonNodeValueOfPrimitiveType(type, jsonNode) } else if (BluePrintTypes.validCollectionTypes().contains(type)) { return checkJsonNodeValueOfCollectionType(type, jsonNode) } - return false; + return false } @JvmStatic diff --git a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt index 4731935e..081f4fe3 100644 --- a/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt +++ b/ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt @@ -29,31 +29,28 @@ import kotlin.test.assertNotNull class BluePrintRepoFileServiceTest { val basePath = "load/model_type" + private val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) @Test fun testGetDataType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate") assertNotNull(dataType, "Failed to get DataType from repo") } @Test fun testGetNodeType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment") assertNotNull(nodeType, "Failed to get NodeType from repo") } @Test fun testGetArtifactType() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity") assertNotNull(nodeType, "Failed to get ArtifactType from repo") } @Test(expected = FileNotFoundException::class) fun testModelNotFound() { - val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath) val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found") assertNotNull(dataType, "Failed to get DataType from repo") } -- cgit 1.2.3-korg