2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.controllerblueprints.validation
22 import kotlinx.coroutines.runBlocking
24 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintError
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
29 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
30 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBlueprintRuntimeService
31 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils
32 import org.onap.ccsdk.cds.controllerblueprints.validation.extension.ResourceDefinitionValidator
33 import kotlin.test.assertEquals
34 import kotlin.test.assertTrue
36 class BlueprintDesignTimeValidatorServiceTest {
38 private val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
39 private val bluePrintRuntime = BlueprintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
40 private val mockBlueprintTypeValidatorService = MockBlueprintTypeValidatorService()
41 private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>()
42 private val defaultBlueprintValidatorService =
43 BlueprintDesignTimeValidatorService(mockBlueprintTypeValidatorService, resourceDefinitionValidator)
44 private val workflowValidator = BlueprintWorkflowValidatorImpl(mockBlueprintTypeValidatorService)
47 fun testValidateOfType() {
49 every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
51 val valid = defaultBlueprintValidatorService.validateBlueprints(bluePrintRuntime)
52 assertTrue(valid, "failed in blueprint Validation")
57 fun testValidateWorkflowFailToFoundNodeTemplate() {
58 val workflowName = "resource-assignment"
61 step.target = "TestCaseFailNoNodeTemplate"
62 val workflow = Workflow()
63 workflow.steps = mutableMapOf("test" to step)
64 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
66 assertEquals(1, bluePrintRuntime.getBlueprintError().allErrors().size)
68 "Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)",
69 bluePrintRuntime.getBlueprintError().allErrors()[0]
74 fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
75 val workflowName = "resource-assignment"
76 val nodeTemplateName = "resource-assignment-process"
78 val nodeTemplate = mockk<NodeTemplate>()
79 every { nodeTemplate.type } returns "TestNodeType"
81 val nodeType = mockk<NodeType>()
82 every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
84 val blueprintContext = mockk<BlueprintContext>()
85 every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
86 every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
88 val bluePrintRuntime = mockk<DefaultBlueprintRuntimeService>("1234")
90 every { bluePrintRuntime.getBlueprintError() } returns BlueprintError()
91 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
94 step.target = nodeTemplateName
95 val workflow = Workflow()
96 workflow.steps = mutableMapOf("test" to step)
97 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
99 assertEquals(1, bluePrintRuntime.getBlueprintError().allErrors().size)
101 "Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " +
102 "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " +
103 "Expected 'tosca.nodes.Workflow' or 'tosca.nodes.Component'",
104 bluePrintRuntime.getBlueprintError().allErrors()[0]
109 fun testValidateWorkflowSuccess() {
110 val workflowName = "resource-assignment"
111 workflowValidator.validate(
114 bluePrintRuntime.bluePrintContext().workflowByName(workflowName)