6fe767ce2b6002948afd5baa026f7faea1ecac00
[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.blueprintsprocessor.services.workflow
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.junit.Test
21 import org.junit.runner.RunWith
22 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
24 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
25 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor
26 import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils
27 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
28 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import org.slf4j.LoggerFactory
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.junit4.SpringRunner
34
35 @RunWith(SpringRunner::class)
36 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class, ComponentExecuteNodeExecutor::class])
37 class BlueprintServiceLogicTest {
38
39     private val log = LoggerFactory.getLogger(BlueprintServiceLogicTest::class.java)
40
41     val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
42             "./../../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
43
44     @Autowired
45     lateinit var blueprintSvcLogicService: BlueprintSvcLogicService
46
47     @Test
48     fun testExecuteGraphWithSingleComponent() {
49
50         val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/one-component.xml")
51         val svcLogicContext = BlueprintSvcLogicContext()
52         svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
53         svcLogicContext.setRequest(getDefaultExecutionServiceInput())
54         blueprintSvcLogicService.execute(graph, svcLogicContext)
55
56     }
57
58     @Test
59     fun testExecuteGraphWithMultipleComponents() {
60         val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/two-component.xml")
61         val svcLogicContext = BlueprintSvcLogicContext()
62         svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService)
63         svcLogicContext.setRequest(getDefaultExecutionServiceInput())
64         blueprintSvcLogicService.execute(graph, svcLogicContext)
65
66     }
67
68     private fun getDefaultExecutionServiceInput(): ExecutionServiceInput {
69         val executionServiceInput = ExecutionServiceInput()
70         val commonHeader = CommonHeader()
71         commonHeader.requestId = "1234"
72         executionServiceInput.commonHeader = commonHeader
73
74         val actionIdentifiers = ActionIdentifiers()
75         actionIdentifiers.blueprintName = "baseconfiguration"
76         actionIdentifiers.blueprintVersion = "1.0.0"
77         actionIdentifiers.actionName = "activate"
78         executionServiceInput.actionIdentifiers = actionIdentifiers
79
80         val metaData: MutableMap<String, JsonNode> = hashMapOf()
81         metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP,"resource-assignment-py")
82         metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment-py")
83         metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "DefaultComponentNode")
84         metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
85         executionServiceInput.metadata = metaData
86
87         return executionServiceInput
88     }
89 }