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.core.validation
21 import org.junit.Ignore
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
25 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.apps.controllerblueprints.core.data.Step
28 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
29 import org.onap.ccsdk.apps.controllerblueprints.core.mock.MockBluePrintTypeValidatorService
30 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
31 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
32 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
33 import kotlin.test.assertEquals
34 import kotlin.test.assertTrue
36 class BluePrintValidatorServiceImplTest {
38 private val blueprintBasePath: String = ("./../model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
39 private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
40 private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
41 private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService)
42 private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
45 fun testValidateOfType() {
46 val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
47 assertTrue(valid, "failed in blueprint Validation")
51 fun testValidateWorkflowFailToFoundNodeTemplate() {
52 val workflowName = "resource-assignment"
55 step.target = "TestCaseFailNoNodeTemplate"
56 val workflow = Workflow()
57 workflow.steps = mutableMapOf("test" to step)
58 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
60 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
61 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])
65 fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
66 val workflowName = "resource-assignment"
67 val nodeTemplateName = "resource-assignment-process"
69 val nodeTemplate = mockk<NodeTemplate>()
70 every { nodeTemplate.type } returns "TestNodeType"
72 val nodeType = mockk<NodeType>()
73 every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
75 val blueprintContext = mockk<BluePrintContext>()
76 every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
77 every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
79 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
81 every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
82 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
85 step.target = nodeTemplateName
86 val workflow = Workflow()
87 workflow.steps = mutableMapOf("test" to step)
88 workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
90 assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
91 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])
95 fun testValidateWorkflowSuccess() {
96 val workflowName = "resource-assignment"
97 workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))