Merge "added test case to VlanTagTest.java"
[ccsdk/apps.git] / components / core / src / test / kotlin / org / onap / ccsdk / apps / controllerblueprints / core / validation / BluePrintValidatorServiceImplTest.kt
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.core.validation
18
19 import io.mockk.every
20 import io.mockk.mockk
21 import org.junit.Ignore
22 import org.junit.Test
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
35
36 class BluePrintValidatorServiceImplTest {
37
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)
43
44     @Test
45     fun testValidateOfType() {
46         val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
47         assertTrue(valid, "failed in blueprint Validation")
48     }
49
50     @Test
51     fun testValidateWorkflowFailToFoundNodeTemplate() {
52         val workflowName = "resource-assignment"
53
54         val step = Step()
55         step.target = "TestCaseFailNoNodeTemplate"
56         val workflow = Workflow()
57         workflow.steps = mutableMapOf("test" to step)
58         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
59
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])
62     }
63
64     @Test
65     fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
66         val workflowName = "resource-assignment"
67         val nodeTemplateName = "resource-assignment-process"
68
69         val nodeTemplate = mockk<NodeTemplate>()
70         every { nodeTemplate.type } returns "TestNodeType"
71
72         val nodeType = mockk<NodeType>()
73         every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
74
75         val blueprintContext = mockk<BluePrintContext>()
76         every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
77         every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
78
79         val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
80
81         every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
82         every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
83
84         val step = Step()
85         step.target = nodeTemplateName
86         val workflow = Workflow()
87         workflow.steps = mutableMapOf("test" to step)
88         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
89
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])
92     }
93
94     @Test
95     fun testValidateWorkflowSuccess() {
96         val workflowName = "resource-assignment"
97         workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))
98     }
99
100 }
101