Optimise dictionary dummy data creation reusability and property usage optimisation.
Change-Id: Ibbd56d514f437f29943cebc0e607becb6798e4b6
Issue-ID: CCSDK-491
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
}\r
\r
fun nodeTypeInterface(nodeTypeName: String, interfaceName: String): InterfaceDefinition? {\r
- return nodeTypeByName(nodeTypeName).interfaces?.values?.first()\r
+ return nodeTypeByName(nodeTypeName).interfaces?.get(interfaceName)\r
}\r
\r
fun nodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, operationName: String): OperationDefinition? {\r
}\r
\r
fun nodeTemplateRequirementNode(nodeTemplateName: String, requirementName: String): NodeTemplate {\r
- val nodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node\r
+ val requirementNodeTemplateName: String = nodeTemplateByName(nodeTemplateName).requirements?.get(requirementName)?.node\r
?: throw BluePrintException(String.format("failed to get node name for node template's (%s) requirement's (%s) " + nodeTemplateName, requirementName))\r
- return nodeTemplateByName(nodeTemplateName)\r
+ return nodeTemplateByName(requirementNodeTemplateName)\r
}\r
\r
fun nodeTemplateCapabilityProperty(nodeTemplateName: String, capabilityName: String, propertyName: String): Any? {\r
arrayNode.size() > 3 -> {\r
reqOrCapEntityName = arrayNode[1].textValue()\r
propertyName = arrayNode[2].textValue()\r
- val propertyPaths: List<String> = arrayNode.filterIndexed { index, obj ->\r
+ val propertyPaths: List<String> = arrayNode.filterIndexed { index, _ ->\r
index >= 3\r
}.map { it.textValue() }\r
subProperty = propertyPaths.joinToString("/")\r
\r
open fun assignWorkflowInputs(workflowName: String, jsonNode: JsonNode) {\r
log.info("assign workflow {} input value ({})", workflowName, jsonNode.toString())\r
- bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, property ->\r
+ bluePrintContext.workflowByName(workflowName)?.inputs?.forEach { propertyName, _ ->\r
val valueNode: JsonNode = jsonNode.at(BluePrintConstants.PATH_DIVIDER + propertyName)\r
?: NullNode.getInstance()\r
setWorkflowInputValue(workflowName, propertyName, valueNode)\r
message.appendln("---> Workflow :" + paths.joinToString(separator))\r
// Step Validation Start\r
paths.add("steps")\r
- workflow.steps?.forEach { stepName, step ->\r
+ workflow.steps?.forEach { stepName, _ ->\r
paths.add(stepName)\r
message.appendln("----> Steps :" + paths.joinToString(separator))\r
paths.removeAt(paths.lastIndex)\r
}\r
}\r
\r
- private fun checkPropertyDataType(dataType: String, propertyName: String) {\r
+ private fun checkPropertyDataType(dataTypeName: String, propertyName: String) {\r
\r
- val dataType = serviceTemplate.dataTypes?.get(dataType)\r
- ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataType, propertyName))\r
+ val dataType = serviceTemplate.dataTypes?.get(dataTypeName)\r
+ ?: throw BluePrintException(format("DataType ({}) for the property ({}) not found", dataTypeName, propertyName))\r
\r
checkValidDataTypeDerivedFrom(propertyName, dataType.derivedFrom)\r
\r
if (BluePrintTypes.validPrimitiveTypes().contains(dataType) || checkDataType(dataType)) {\r
return true\r
} else {\r
- throw BluePrintException(format("DataType ({}) for the property ({}) is not valid", dataType))\r
+ throw BluePrintException(format("DataType({}) for the property({}) is not valid", dataType, propertyName))\r
}\r
}\r
\r
\r
fun assignInputs(bluePrintContext: BluePrintContext, jsonNode: JsonNode, context: MutableMap<String, Any>) {\r
log.info("assignInputs from input JSON ({})", jsonNode.toString())\r
- bluePrintContext.inputs?.forEach { propertyName, property ->\r
+ bluePrintContext.inputs?.forEach { propertyName, _ ->\r
val valueNode: JsonNode = jsonNode.at("/".plus(propertyName)) ?: NullNode.getInstance()\r
\r
val path = BluePrintConstants.PATH_INPUTS.plus(BluePrintConstants.PATH_DIVIDER).plus(propertyName)\r
\r
@Test\r
fun testGetDataType() {\r
- val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate")?.block()\r
+ val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-v4-aggregate").block()\r
assertNotNull(dataType, "Failed to get DataType from repo")\r
}\r
\r
@Test\r
fun testGetNodeType() {\r
- val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment")?.block()\r
+ val nodeType = bluePrintEnhancerRepoFileService.getNodeType("component-resource-assignment").block()\r
assertNotNull(nodeType, "Failed to get NodeType from repo")\r
}\r
\r
@Test\r
fun testGetArtifactType() {\r
- val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")?.block()\r
+ val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity").block()\r
assertNotNull(nodeType, "Failed to get ArtifactType from repo")\r
}\r
\r
@Test(expected = FileNotFoundException::class)\r
fun testModelNotFound() {\r
- val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")?.block()\r
+ val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found").block()\r
assertNotNull(dataType, "Failed to get DataType from repo")\r
}\r
}
\ No newline at end of file
open fun validateSources(resourceAssignments: List<ResourceAssignment>) {
log.info("validating resource assignment sources")
+ // Check the Resource Assignment Source(Dynamic Instance) is valid.
resourceAssignments.forEach { resourceAssignment ->
try {
ResourceSourceMappingFactory.getRegisterSourceMapping(resourceAssignment.dictionarySource!!)
resourceAssignmentMap = resourceAssignments.map { it.name to it }.toMap()
+ // Check the Resource Assignment has Duplicate Key Names
val duplicateKeyNames = resourceAssignments.groupBy { it.name }
.filter { it.value.size > 1 }
.map { it.key }
validationMessage.appendln(String.format("Duplicate Assignment Template Keys (%s) is Present", duplicateKeyNames))
}
+ // Check the Resource Assignment has Duplicate Dictionary Names
val duplicateDictionaryKeyNames = resourceAssignments.groupBy { it.dictionaryName }
.filter { it.value.size > 1 }
.map { it.key }
validationMessage.appendln(String.format("Duplicate Assignment Dictionary Keys (%s) is Present", duplicateDictionaryKeyNames))
}
+ // Collect all the dependencies as a single list
val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten()
+ // Check all the dependencies keys have Resource Assignment mappings.
val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct()
if (notPresentDictionaries.isNotEmpty()) {
validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries))
resourceDefinition.sources.forEach { (name, nodeTemplate) ->
val sourceType = nodeTemplate.type
- val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block()
+ val sourceNodeType = bluePrintRepoService.getNodeType(sourceType).block()
?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType))
// Validate Property Name, expression, values and Data Type
isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)
} else {
- bluePrintRepoService.getDataType(propertyType)
+ bluePrintRepoService.getDataType(propertyType).block()
?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository",
propertyName, propertyType))
isValid = true
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory\r
+\r
+object ResourceDictionaryTestUtils {\r
+\r
+ @JvmStatic\r
+ fun setUpResourceSourceMapping() {\r
+ ResourceSourceMappingFactory.registerSourceMapping("db", "source-db")\r
+ ResourceSourceMappingFactory.registerSourceMapping("input", "source-input")\r
+ ResourceSourceMappingFactory.registerSourceMapping("default", "source-default")\r
+ ResourceSourceMappingFactory.registerSourceMapping("mdsal", "source-rest")\r
+ }\r
+}
\ No newline at end of file
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
import com.att.eelf.configuration.EELFManager\r
+import org.junit.Before\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryTestUtils\r
+\r
/**\r
* ResourceAssignmentValidationServiceTest.\r
*\r
*/\r
class ResourceAssignmentValidationServiceTest {\r
private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentValidationServiceTest::class.java)\r
+ @Before\r
+ fun setUp() {\r
+ // Setup dummy Source Instance Mapping\r
+ ResourceDictionaryTestUtils.setUpResourceSourceMapping()\r
+ }\r
+\r
@Test\r
fun testValidateSuccess() {\r
log.info("**************** testValidateSuccess *****************")\r