diff options
Diffstat (limited to 'ms/blueprintsprocessor')
21 files changed, 713 insertions, 56 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt index feec74058..cd51b338e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt @@ -1,7 +1,10 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * * Modifications Copyright © 2018 IBM. * + * Modifications Copyright © 2019 IBM, Bell Canada. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -79,4 +82,28 @@ class ResourceResolutionComponentTest { resourceResolutionComponent.applyNB(executionServiceInput) } } + + @Test + fun testRecover() { + runBlocking { + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json", + ExecutionServiceInput::class.java)!! + + // Prepare Inputs + PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment") + + val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ResourceResolutionComponent") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + bluePrintRuntimeService.put("resource-assignment-step-inputs", stepMetaData.asJsonNode()) + + resourceResolutionComponent.bluePrintRuntimeService = bluePrintRuntimeService + resourceResolutionComponent.stepName = "resource-assignment" + resourceResolutionComponent.recoverNB(RuntimeException("TEST PASSED"), executionServiceInput) + } + } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt index 5ad9b3ace..4a82dbd21 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt @@ -1,7 +1,10 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * * Modifications Copyright © 2018 IBM. * + * Modifications Copyright © 2019 IBM, Bell Canada. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -91,4 +94,50 @@ class ResourceResolutionServiceTest { } } + @Test + @Throws(Exception::class) + fun testResolveResources() { + + Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json", + ExecutionServiceInput::class.java)!! + + val artefactNames = listOf("baseconfig", "another") + + // Prepare Inputs + PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment") + + resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artefactNames, mapOf()) + + } + + @Test + @Throws(Exception::class) + fun testResolveResourcesWithMappingAndTemplate() { + + Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-resourceresolution-request.json", + ExecutionServiceInput::class.java)!! + + val artifactPrefix = "another" + + // Velocity Artifact Definition Name + val artifactTemplate = "$artifactPrefix-template" + // Resource Assignment Artifact Definition Name + val artifactMapping = "$artifactPrefix-mapping" + + // Prepare Inputs + PayloadUtils.prepareInputsFromWorkflowPayload(bluePrintRuntimeService, executionServiceInput.payload, "resource-assignment") + + resourceResolutionService.resolveResources(bluePrintRuntimeService, "resource-assignment", artifactMapping, artifactTemplate) + + } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt new file mode 100644 index 000000000..22e043b11 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/mock/MockDatabaseConfiguration.kt @@ -0,0 +1,42 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock + +import io.mockk.mockk +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +open class MockDatabaseConfiguration { + + @Bean(name = ["MariaDatabaseConfiguration", "MySqlDatabaseConfiguration", "PrimaryDatabaseConfiguration"]) + open fun createDatabaseConfiguration(): BluePrintDBLibGenericService { + return mockk<BluePrintDBLibGenericService>() + } +} + +@Configuration +open class MockBlueprintProcessorCatalogServiceImpl { + + @Bean(name = ["blueprintProcessorCatalogServiceImpl"]) + open fun createBlueprintProcessorCatalogServiceImpl(): BluePrintValidatorService { + return mockk<BluePrintValidatorService>() + } + + +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt index 489d971a5..2af15c2be 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt @@ -120,8 +120,8 @@ class CapabilityResourceResolutionProcessorTest { val processorName = capabilityResourceResolutionProcessor.processNB(resourceAssignment) assertNotNull(processorName, "couldn't get Jython script resource assignment processor name") + println(processorName) } - } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt new file mode 100644 index 000000000..f76d95a11 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt @@ -0,0 +1,75 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintProcessorProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockBlueprintProcessorCatalogServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockDatabaseConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DatabaseResourceAssignmentProcessor::class, BlueprintPropertyConfiguration::class, + BluePrintProperties::class, BluePrintDBLibPropertySevice::class, BluePrintDBLibConfiguration::class, + BluePrintCoreConfiguration::class, MockDatabaseConfiguration::class, MockBlueprintProcessorCatalogServiceImpl::class, + BlueprintProcessorProperties::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class DatabaseResourceResolutionProcessorTest { + + @Autowired + lateinit var databaseResourceAssignmentProcessor: DatabaseResourceAssignmentProcessor + + @Test + fun `test database resource resolution`() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + databaseResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService + databaseResourceAssignmentProcessor.resourceDictionaries = hashMapOf() + + val resourceAssignment = ResourceAssignment().apply { + name = "rr-name" + dictionaryName = "rr-dict-name" + dictionarySource = "primary-db" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment) + assertNotNull(processorName, "couldn't get Database resource assignment processor name") + println(processorName) + } + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessorTest.kt new file mode 100644 index 000000000..093a3347a --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessorTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [DefaultResourceResolutionProcessor::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class DefaultResourceResolutionProcessorTest { + + @Autowired + lateinit var defaultResourceResolutionProcessor: DefaultResourceResolutionProcessor + + @Test + fun `test default resource resolution`() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + defaultResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService + defaultResourceResolutionProcessor.resourceDictionaries = hashMapOf() + + val resourceAssignment = ResourceAssignment().apply { + name = "rr-name" + dictionaryName = "rr-dict-name" + dictionarySource = "default" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = defaultResourceResolutionProcessor.applyNB(resourceAssignment) + assertNotNull(processorName, "couldn't get Default resource assignment processor name") + println(processorName) + } + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessorTest.kt new file mode 100644 index 000000000..68ef4d20b --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessorTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [InputResourceResolutionProcessor::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class InputResourceResolutionProcessorTest { + + @Autowired + lateinit var inputResourceResolutionProcessor: InputResourceResolutionProcessor + + @Test + fun `test input resource resolution`() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + inputResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService + inputResourceResolutionProcessor.resourceDictionaries = hashMapOf() + + val resourceAssignment = ResourceAssignment().apply { + name = "rr-name" + dictionaryName = "rr-dict-name" + dictionarySource = "input" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = inputResourceResolutionProcessor.applyNB(resourceAssignment) + assertNotNull(processorName, "couldn't get Input resource assignment processor name") + println(processorName) + } + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt new file mode 100644 index 000000000..a4636f141 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessorTest.kt @@ -0,0 +1,68 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [RestResourceResolutionProcessor::class, BluePrintRestLibPropertyService::class, + BlueprintPropertyConfiguration::class, BluePrintProperties::class]) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class RestResourceResolutionProcessorTest { + + @Autowired + lateinit var restResourceResolutionProcessor: RestResourceResolutionProcessor + + @Test + fun `test rest resource resolution`() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService + restResourceResolutionProcessor.resourceDictionaries = hashMapOf() + + val resourceAssignment = ResourceAssignment().apply { + name = "rr-name" + dictionaryName = "rr-dict-name" + dictionarySource = "primary-config-data" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment) + assertNotNull(processorName, "couldn't get Rest resource assignment processor name") + println(processorName) + } + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties index 3f37d1b9e..071b27afc 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties @@ -2,8 +2,6 @@ # # Copyright © 2017-2018 AT&T Intellectual Property. # -# Modifications Copyright © 2019 IBM, Bell Canada. -# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE +blueprintsprocessor.db.primary.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 blueprintsprocessor.db.primary.username=sa blueprintsprocessor.db.primary.password= blueprintsprocessor.db.primary.driverClassName=org.h2.Driver @@ -27,17 +25,7 @@ blueprintsprocessor.db.primary.hibernateDialect=org.hibernate.dialect.H2Dialect # Controller Blueprints Core Configuration blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive - -blueprintsprocessor.restclient.primary-config-data.type=basic-auth -blueprintsprocessor.restclient.primary-config-data.url=http://127.0.0.1:9111 -blueprintsprocessor.restclient.primary-config-data.userId=sampleuser -blueprintsprocessor.restclient.primary-config-data.token=sampletoken - +blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work # Python executor blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints -blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints - - -# CBA examples for tests cases -controllerblueprints.loadBlueprintsExamplesPath=./../../../../components/model-catalog/blueprint-model/test-blueprint -controllerblueprints.loadBluePrintPaths=./../../../../components/model-catalog/blueprint-model/test-blueprint
\ No newline at end of file +blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt index 2fda15906..e40efd0c4 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/BlueprintProcessorCatalogServiceImplTest.kt @@ -1,6 +1,8 @@ /* * Copyright (C) 2019 Bell Canada. * + * Copyright (C) 2019 IBM, Bell Canada. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,11 +23,18 @@ import org.junit.runner.RunWith import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.mock.MockBlueprintProcessorCatalogServiceImpl +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner +import java.io.File import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.assertTrue @@ -33,15 +42,29 @@ import kotlin.test.assertTrue @RunWith(SpringRunner::class) @EnableAutoConfiguration @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@ContextConfiguration(classes = [BlueprintProcessorCatalogServiceImpl::class, BluePrintCoreConfiguration::class, + MockBlueprintProcessorCatalogServiceImpl::class]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BlueprintProcessorCatalogServiceImplTest { @Autowired lateinit var blueprintCatalog: BluePrintCatalogService + @Autowired + lateinit var blueprintProcessorCatalogServiceImpl: BlueprintProcessorCatalogServiceImpl + + @Autowired + lateinit var blueprintCoreConfiguration: BluePrintCoreConfiguration + + private lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + private val blueprintId = "1234" + @BeforeTest fun setup() { deleteDir("target", "blueprints") + bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(blueprintId, + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") } @AfterTest @@ -51,6 +74,7 @@ class BlueprintProcessorCatalogServiceImplTest { @Test fun `test catalog service`() { + //TODO: I thing this test function should be remve and replace by the other one. runBlocking { //FIXME("Create ZIP from test blueprints") @@ -58,11 +82,46 @@ class BlueprintProcessorCatalogServiceImplTest { assertTrue(file.exists(), "couldn't get file ${file.absolutePath}") blueprintCatalog.saveToDatabase("1234", file) - blueprintCatalog.getFromDatabase("baseconfiguration", "1.0.0") blueprintCatalog.deleteFromDatabase("baseconfiguration", "1.0.0") + } + } + + @Test + fun `test save function`() { + runBlocking { + val file = normalizedFile("./src/test/resources/test-cba.zip") + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId + blueprintProcessorCatalogServiceImpl.save(metadata, file) + } + } + + @Test + fun `test get function`() { + runBlocking { + val file = normalizedFile("./src/test/resources/test-cba.zip") + assertTrue(file.exists(), "couldnt get file ${file.absolutePath}") + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] = blueprintId + + blueprintProcessorCatalogServiceImpl.save(metadata, file) + blueprintProcessorCatalogServiceImpl.get("baseconfiguration", "1.0.0", true) + } + + assertTrue(File(blueprintCoreConfiguration.bluePrintPathConfiguration().blueprintArchivePath + + "/baseconfiguration").deleteRecursively(),"Couldn't get blueprint archive " + + "${blueprintCoreConfiguration.bluePrintPathConfiguration().blueprintArchivePath}/baseconfiguration " + + "from data base.") + } + + @Test + fun `test delete function`() { + runBlocking { + blueprintProcessorCatalogServiceImpl.delete("baseconfiguration", "1.0.0") } } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt new file mode 100644 index 000000000..08de33270 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/mock/MockBlueprintProcessorCatalogServiceImpl.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.db.mock + +import io.mockk.mockk +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +@Configuration +open class MockBlueprintProcessorCatalogServiceImpl { + + @Bean(name = ["blueprintProcessorCatalogServiceImpl"]) + open fun createBlueprintProcessorCatalogServiceImpl(): BluePrintValidatorService { + return mockk<BluePrintValidatorService>() + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt index fb6a0832a..badd70065 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/api/data/BlueprintProcessorData.kt @@ -86,7 +86,7 @@ open class Status { @get:ApiModelProperty(required = true) var code: Int = 200 @get:ApiModelProperty(required = true) - var eventType: String = "EVENT-ACTION-RESPONSE" + var eventType: String = "" @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z") @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") var timestamp: Date = Date() diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt index 274346917..1e09bee8d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/ExecutionServiceHandler.kt @@ -62,7 +62,7 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP return bluePrintCatalogService.saveToDatabase(saveId, compressedFile, true) } catch (e: IOException) { throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Upload CBA: ${e.message}", e) + "Error in Upload CBA: ${e.message}", e) } finally { deleteNBDir(blueprintArchive) deleteNBDir(blueprintWorking) @@ -90,41 +90,42 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP responseObserver.onCompleted() } else -> responseObserver.onNext(response(executionServiceInput, - "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", - true).toProto()); + "Failed to process request, 'actionIdentifiers.mode' not specified. Valid value are: 'sync' or 'async'.", + true).toProto()); } } suspend fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { val requestId = executionServiceInput.commonHeader.requestId log.info("processing request id $requestId") - val actionIdentifiers = executionServiceInput.actionIdentifiers - val blueprintName = actionIdentifiers.blueprintName val blueprintVersion = actionIdentifiers.blueprintVersion + try { + val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion) + log.info("blueprint base path $basePath") - val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion) - log.info("blueprint base path $basePath") - - val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) + val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(requestId, basePath.toString()) - val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, + val output = bluePrintWorkflowExecutionService.executeBluePrintWorkflow(blueprintRuntimeService, executionServiceInput, hashMapOf()) - val errors = blueprintRuntimeService.getBluePrintError().errors - if (errors.isNotEmpty()) { - val errorMessage = errors.stream().map { it.toString() }.collect(Collectors.joining(", ")) - setErrorStatus(errorMessage, output.status) + val errors = blueprintRuntimeService.getBluePrintError().errors + if (errors.isNotEmpty()) { + val errorMessage = errors.stream().map { it.toString() }.collect(Collectors.joining(", ")) + setErrorStatus(errorMessage, output.status) + } + return output + } catch (e: Exception) { + log.error("fail processing request id $requestId", e) + return response(executionServiceInput, e.localizedMessage, true) } - - return output } private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { return filePart.transferTo(targetFile) - .thenReturn(targetFile) - .awaitSingle() + .thenReturn(targetFile) + .awaitSingle() } private fun setErrorStatus(errorMessage: String, status: Status) { @@ -139,10 +140,10 @@ class ExecutionServiceHandler(private val bluePrintPathConfiguration: BluePrintP val executionServiceOutput = ExecutionServiceOutput() executionServiceOutput.commonHeader = executionServiceInput.commonHeader executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers - executionServiceOutput.payload = JsonNodeFactory.instance.objectNode() val status = Status() if (failure) { + executionServiceOutput.payload = JsonNodeFactory.instance.objectNode() setErrorStatus(errorMessage, status) } else { status.eventType = EventType.EVENT_COMPONENT_PROCESSING.name diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index e78e87523..14feb28bf 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status +import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.asObjectNode @@ -97,7 +98,7 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic log.info("Preparing Response...") executionServiceOutput.commonHeader = executionServiceInput.commonHeader executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers - var status: Status? + var status = Status() try { // Resolve the Output Expression val stepOutputs = bluePrintRuntimeService @@ -105,12 +106,12 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic bluePrintRuntimeService.put("$stepName-step-outputs", stepOutputs.asObjectNode()) // Set the Default Step Status - status = Status() + status.eventType = EventType.EVENT_COMPONENT_EXECUTED.name } catch (e: Exception) { - status = Status() status.message = BluePrintConstants.STATUS_FAILURE + status.eventType = EventType.EVENT_COMPONENT_FAILURE.name } - executionServiceOutput.status = status!! + executionServiceOutput.status = status return this.executionServiceOutput } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt index 2a4509033..586888bab 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt @@ -33,7 +33,7 @@ import java.io.File @Service class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, - private val applicationContext: ApplicationContext) { + private val applicationContext: ApplicationContext) { val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java) @@ -57,7 +57,6 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): BlueprintFunctionNode<*, *> { - val blueprintBasePath: String = bluePrintContext.rootPath val pythonFileName = bluePrintContext.rootPath .plus(File.separator) @@ -68,10 +67,6 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, val content: String = JacksonUtils.getContent(pythonFileName) - val pythonPath: MutableList<String> = arrayListOf() - pythonPath.add(blueprintBasePath) - pythonPath.addAll(pythonExecutorProperty.modulePaths) - val jythonInstances: MutableMap<String, Any> = hashMapOf() jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt index 430692ce0..658b0c291 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt @@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.Configuration import java.io.File -import java.util.* +import java.util.Properties @Configuration @ComponentScan diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt index c8c9f0b6a..ceb824d13 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt @@ -30,6 +30,7 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import kotlin.test.assertNotNull +import kotlin.test.BeforeTest @RunWith(SpringRunner::class) @ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class]) @@ -38,25 +39,39 @@ import kotlin.test.assertNotNull "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) class BlueprintJythonServiceTest { + lateinit var blueprintContext: BluePrintContext @Autowired private lateinit var blueprintJythonService: BlueprintJythonService + @BeforeTest + fun init() { + blueprintContext = mockk<BluePrintContext>() + every { blueprintContext.rootPath } returns normalizedPathName("target") + } + @Test fun testGetAbstractPythonPlugin() { - val bluePrintContext = mockk<BluePrintContext>() - every { bluePrintContext.rootPath } returns normalizedPathName("target") - - val dependencies: MutableMap<String, Any> = hashMapOf() val content = JacksonUtils.getClassPathFileContent("scripts/SamplePythonComponentNode.py") + val dependencies: MutableMap<String, Any> = hashMapOf() - val abstractComponentFunction = blueprintJythonService - .jythonInstance<AbstractComponentFunction>(bluePrintContext, "SamplePythonComponentNode", + val abstractPythonPlugin = blueprintJythonService + .jythonInstance<AbstractComponentFunction>(blueprintContext, "SamplePythonComponentNode", content, dependencies) - assertNotNull(abstractComponentFunction, "failed to get python component") + assertNotNull(abstractPythonPlugin, "failed to get python component") + + abstractPythonPlugin.process(ExecutionServiceInput()) + + } + + @Test + fun testGetAbstractJythonComponent() { + + val scriptInstance = "test-classes/scripts/SamplePythonComponentNode.py" - abstractComponentFunction.process(ExecutionServiceInput()) + val abstractJythonComponent = blueprintJythonService.jythonComponentInstance(blueprintContext, scriptInstance) + assertNotNull(abstractJythonComponent, "failed to get Jython component") } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt new file mode 100644 index 000000000..3c3efa252 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonHostTest.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts + +import org.junit.Test + +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull +import kotlin.test.BeforeTest + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintPython::class, PythonExecutorProperty::class, String::class]) +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) +class BlueprintPythonHostTest { + + lateinit var blueprintPythonHost: BlueprintPythonHost + + @Autowired + lateinit var pythonExecutorProperty: PythonExecutorProperty + + @BeforeTest + fun init() { + val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + val pythonPath: MutableList<String> = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + blueprintPythonHost = BlueprintPythonHost(BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf())) + } + + @Test + fun testGetPythonComponent() { + val content = JacksonUtils.getContent("./src/test/resources/PythonTestScript.py") + + val pythonClassName = "PythonTestScript" + val dependencies: MutableMap<String, Any> = hashMapOf() + + val pythonObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencies) + + assertNotNull(pythonObject, "failed to get python object") + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxyTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxyTest.kt new file mode 100644 index 000000000..12ef9733a --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxyTest.kt @@ -0,0 +1,48 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils + +import kotlin.test.assertNotNull +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.BeforeTest + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintPython::class, PythonExecutorProperty::class, String::class]) +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"]) +class BlueprintPythonInterpreterProxyTest { + + lateinit var blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy + + @Autowired + lateinit var pythonExecutorProperty: PythonExecutorProperty + + @BeforeTest + fun init() { + val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + val pythonPath: MutableList<String> = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + val pythonClassName = "PythonTestScript" + val content = JacksonUtils.getContent("./src/test/resources/PythonTestScript.py") + + val blueprintPython = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf()) + blueprintPython.content = content + blueprintPython.pythonClassName = pythonClassName + blueprintPython.moduleName = "Unit test - Blueprint Python Script [Class Name = $pythonClassName]" + + blueprintPythonInterpreterProxy = BlueprintPythonInterpreterProxy(blueprintPython) + } + + @Test + fun getPythonInterpreter() { + val pythonObject = blueprintPythonInterpreterProxy.getPythonInstance(hashMapOf()) + assertNotNull(pythonObject, "failed to get python interpreter") + } +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/PythonTestScript.py b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/PythonTestScript.py new file mode 100644 index 000000000..42b611b88 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/resources/PythonTestScript.py @@ -0,0 +1,9 @@ +class PythonTestScript(): + + def process(self, execution_request): + print "Processing calling..." + PROPERTY_BLUEPRINT_BASE_PATH + return None + + def recover(self, runtime_exception, execution_request): + print "Recovering calling..." + PROPERTY_BLUEPRINT_BASE_PATH + return None diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionServiceTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionServiceTest.kt new file mode 100644 index 000000000..05cd99785 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/NodeTemplateExecutionServiceTest.kt @@ -0,0 +1,61 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [WorkflowServiceConfiguration::class]) + +class NodeTemplateExecutionServiceTest { + @Autowired + lateinit var nodeTemplateExecutionService: NodeTemplateExecutionService + + @Test + fun testExecuteNodeTemplate() { + runBlocking { + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json", + ExecutionServiceInput::class.java)!! + + // Assign Workflow inputs Mock + val input = executionServiceInput.payload.get("resource-assignment-request") + bluePrintRuntimeService.assignWorkflowInputs("resource-assignment", input) + + val nodeTemplate = "resource-assignment" + + val executionServiceOutput = nodeTemplateExecutionService + .executeNodeTemplate(bluePrintRuntimeService, nodeTemplate, executionServiceInput) + + assertNotNull(executionServiceOutput, "failed to get response") + assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message, + "failed to get successful response") + } + } +}
\ No newline at end of file |