2  * Copyright © 2017-2018 AT&T Intellectual Property.
 
   3  * Modifications Copyright © 2018 IBM.
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *     http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  18 package org.onap.ccsdk.apps.controllerblueprints.core.validation
 
  23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
 
  24 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
 
  25 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
 
  26 import org.onap.ccsdk.apps.controllerblueprints.core.data.Step
 
  27 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
 
  28 import org.onap.ccsdk.apps.controllerblueprints.core.mock.MockBluePrintTypeValidatorService
 
  29 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 
  30 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
 
  31 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 
  32 import kotlin.test.assertEquals
 
  33 import kotlin.test.assertTrue
 
  35 class BluePrintValidatorServiceImplTest {
 
  37     private val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
 
  38     private val bluePrintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
 
  39     private val mockBluePrintTypeValidatorService = MockBluePrintTypeValidatorService()
 
  40     private val defaultBluePrintValidatorService = BluePrintValidatorServiceImpl(mockBluePrintTypeValidatorService)
 
  41     private val workflowValidator = BluePrintWorkflowValidatorImpl(mockBluePrintTypeValidatorService)
 
  44     fun testValidateOfType() {
 
  45         val valid = defaultBluePrintValidatorService.validateBluePrints(bluePrintRuntime)
 
  46         assertTrue(valid, "failed in blueprint Validation")
 
  50     fun testValidateWorkflowFailToFoundNodeTemplate() {
 
  51         val workflowName = "resource-assignment"
 
  54         step.target = "TestCaseFailNoNodeTemplate"
 
  55         val workflow = Workflow()
 
  56         workflow.steps = mutableMapOf("test" to step)
 
  57         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
 
  59         assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
 
  60         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])
 
  64     fun testValidateWorkflowFailNodeTemplateNotDgGeneric() {
 
  65         val workflowName = "resource-assignment"
 
  66         val nodeTemplateName = "resource-assignment-process"
 
  68         val nodeTemplate = mockk<NodeTemplate>()
 
  69         every { nodeTemplate.type } returns "TestNodeType"
 
  71         val nodeType = mockk<NodeType>()
 
  72         every { nodeType.derivedFrom } returns "tosca.nodes.TEST"
 
  74         val blueprintContext = mockk<BluePrintContext>()
 
  75         every { blueprintContext.nodeTemplateByName(nodeTemplateName) } returns nodeTemplate
 
  76         every { blueprintContext.nodeTemplateNodeType(nodeTemplateName) } returns nodeType
 
  78         val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
 
  80         every { bluePrintRuntime.getBluePrintError() } returns BluePrintError()
 
  81         every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
 
  84         step.target = nodeTemplateName
 
  85         val workflow = Workflow()
 
  86         workflow.steps = mutableMapOf("test" to step)
 
  87         workflowValidator.validate(bluePrintRuntime, workflowName, workflow)
 
  89         assertEquals(1, bluePrintRuntime.getBluePrintError().errors.size)
 
  90         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])
 
  94     fun testValidateWorkflowSuccess() {
 
  95         val workflowName = "resource-assignment"
 
  96         workflowValidator.validate(bluePrintRuntime, workflowName, bluePrintRuntime.bluePrintContext().workflowByName(workflowName))