2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.validation
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.Step
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
27 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
28 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import kotlin.test.assertEquals
31 import kotlin.test.assertTrue
33 class BluePrintValidatorServiceImplTest {
35 private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
36 private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
37 private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
38 private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService)
39 private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
42 fun testValidateOfType() {
43 val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
44 assertTrue(valid, "failed in blueprint Validation")
48 fun testValidateWorkflowFailToFoundNodeTemplate() {
49 val workflowName = "resource-assignment"
52 step.target = "TestCaseFailNoNodeTemplate"
53 val workflow = Workflow()
54 workflow.steps = mutableMapOf("test" to step)
55 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
57 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
58 assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : could't get node template for the name(TestCaseFailNoNodeTemplate)", bluePrintRuntime.getBluePrintError().errors[0])
62 fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
63 val workflowName = "resource-assignment"
64 val nodeTemplateName = "resource-assignment-process"
66 val nodeTemplate = mockk<NodeTemplate>()
67 every { nodeTemplate.type } returns "TestNodeType"
69 val nodeType = mockk<NodeType>()
70 every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
72 val blueprintContext = mockk<BluePrintContext>()
73 every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
74 every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
76 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
78 every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
79 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
82 step.target = nodeTemplateName
83 val workflow = Workflow()
84 workflow.steps = mutableMapOf("test" to step)
85 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
87 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
88 assertEquals("Failed to validate Workflow(resource-assignment)'s step(test)'s definition : resource-assignment/steps/test : NodeType(TestNodeType) derived from is 'tosca.nodes.TEST', Expected is 'tosca.nodes.DG'", bluePrintRuntime.getBluePrintError().errors[0])
92 fun testValidateWorkflowSuccess() {
93 val workflowName = "resource-assignment"
94 workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))