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
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.Step
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
29 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
30 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
31 import org.onap.ccsdk.cds.controllerblueprints.validation.extension.ResourceDefinitionValidator
32 import kotlin.test.assertEquals
33 import kotlin.test.assertTrue
35 class BluePrintDesignTimeValidatorServiceTest {
37 private val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
38 private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
39 private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
40 private val resourceDefinitionValidator = mockk<ResourceDefinitionValidator>()
41 private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService, resourceDefinitionValidator)
42 private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
45 fun testValidateOfType() {
46 every { resourceDefinitionValidator.validate(bluePrintRuntime, any(), any()) } returns Unit
48 val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
49 assertTrue(valid, "failed in blueprint Validation")
53 fun testValidateWorkflowFailToFoundNodeTemplate() {
54 val workflowName = "resource-assignment"
57 step.target = "TestCaseFailNoNodeTemplate"
58 val workflow = Workflow()
59 workflow.steps = mutableMapOf("test" to step)
60 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
62 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
64 "Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)",
65 bluePrintRuntime.getBluePrintError().errors[0]
70 fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
71 val workflowName = "resource-assignment"
72 val nodeTemplateName = "resource-assignment-process"
74 val nodeTemplate = mockk<NodeTemplate>()
75 every { nodeTemplate.type } returns "TestNodeType"
77 val nodeType = mockk<NodeType>()
78 every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
80 val blueprintContext = mockk<BluePrintContext>()
81 every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
82 every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
84 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
86 every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
87 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
90 step.target = nodeTemplateName
91 val workflow = Workflow()
92 workflow.steps = mutableMapOf("test" to step)
93 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
95 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
97 "Failed to validate Workflow(resource-assignment)'s step(test)'s definition : " +
98 "resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', " +
99 "Expected 'tosca.nodes.Workflow' or 'tosca.nodes.Component'", bluePrintRuntime.getBluePrintError().errors[0]
104 fun testValidateWorkflowSuccess() {
105 val workflowName = "resource-assignment"
106 workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))