Merge "fixed sonar issue in AssignVlanTagResponse"
[ccsdk/apps.git] / ms / blueprintsprocessor / modules / services / workflow-service / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / services / workflow / BlueprintServiceLogicTest.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.blueprintsprocessor.services.workflow
18
19 import org.junit.Test
20 import org.junit.runner.RunWith
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
22 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
23 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.PrototypeComponentFunction
24 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.mock.SingletonComponentFunction
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
27 import org.slf4j.LoggerFactory
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.context.ApplicationContext
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.junit4.SpringRunner
32 import kotlin.test.assertEquals
33
34 @RunWith(SpringRunner::class)
35 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
36 class BlueprintServiceLogicTest {
37
38     private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
39
40     @Autowired
41     lateinit var applicationContext: ApplicationContext
42
43     @Autowired
44     lateinit var blueprintDGExecutionService: BlueprintDGExecutionService
45
46     @Test
47     fun testExecuteGraphWithSingleComponent() {
48
49         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
50                 "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
51
52         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", ExecutionServiceInput::class.java)!!
53
54
55         blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput)
56
57     }
58
59     @Test
60     fun testExecuteGraphWithMultipleComponents() {
61
62         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
63                 "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
64
65         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/assign-activate-input.json", ExecutionServiceInput::class.java)!!
66
67         blueprintDGExecutionService.executeDirectedGraph(bluePrintRuntimeService, executionServiceInput)
68
69     }
70
71     @Test
72     fun testSingleton() {
73         val singleton1 = applicationContext.getBean(SingletonComponentFunction::class.java)
74         singleton1.stepName = "step1"
75         val singleton2 = applicationContext.getBean(SingletonComponentFunction::class.java)
76         assertEquals(singleton1.stepName, singleton2.stepName, " failed to get singleton data")
77     }
78
79     @Test
80     fun testProtoTypeFunction() {
81         val stepName1 = "step1"
82         val stepName2 = "step2"
83         val proto1 = applicationContext.getBean(PrototypeComponentFunction::class.java)
84         proto1.stepName = stepName1
85
86         val proto2 = applicationContext.getBean(PrototypeComponentFunction::class.java)
87         proto2.stepName = stepName2
88
89         assertEquals(stepName1, proto1.stepName, " Failed to match the step1 name")
90         assertEquals(stepName2, proto2.stepName, " Failed to match the step2 name")
91     }
92
93 }