43c3e0e3e5023fd7c8a7f5bf4d13c123e7c0cab1
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.validation
18
19 import io.mockk.every
20 import io.mockk.mockk
21 import org.junit.Test
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
32
33 class BluePrintDesignTimeValidatorServiceTest {
34
35     private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
36     private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
37     private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
38     private val defaultBluePrintValidatorService = BluePrintDesignTimeValidatorService(mockBluePrintTypeValidatorService)
39     private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
40
41     @Test
42     fun testValidateOfType() {
43         val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
44         assertTrue(valid, "failed in blueprint Validation")
45     }
46
47     @Test
48     fun testValidateWorkflowFailToFoundNodeTemplate() {
49         val workflowName = "resource-assignment"
50
51         val step = Step()
52         step.target = "TestCaseFailNoNodeTemplate"
53         val workflow = Workflow()
54         workflow.steps = mutableMapOf("test" to step)
55         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
56
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])
59     }
60
61     @Test
62     fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
63         val workflowName = "resource-assignment"
64         val nodeTemplateName = "resource-assignment-process"
65
66         val nodeTemplate = mockk<NodeTemplate>()
67         every { nodeTemplate.type } returns "TestNodeType"
68
69         val nodeType = mockk<NodeType>()
70         every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
71
72         val blueprintContext = mockk<BluePrintContext>()
73         every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
74         every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
75
76         val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
77
78         every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
79         every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
80
81         val step = Step()
82         step.target = nodeTemplateName
83         val workflow = Workflow()
84         workflow.steps = mutableMapOf("test" to step)
85         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
86
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])
89     }
90
91     @Test
92     fun testValidateWorkflowSuccess() {
93         val workflowName = "resource-assignment"
94         workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))
95     }
96
97 }
98