From ebdd198e47b2da08a2aa470177a3baa4a2cf1c4c Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 27 Nov 2019 19:42:17 -0500 Subject: Optimize spring data JPA UT. Test case based database configuration, so that we can define what repositories and entities can be used for testing. Issue-ID: CCSDK-1735 Signed-off-by: Brinda Santh Change-Id: I4f8a7eb4ed47fec9ab17eb9552648ebd0de01236 --- .../api/BluePrintProcessingGRPCHandlerTest.kt | 11 ++-- .../api/SelfServiceApiTestConfiguration.kt | 29 +++++++++++ .../selfservice/api/TestDatabaseConfiguration.kt | 60 ++++++++++++++++++++++ .../BluePrintRuntimeValidatorServiceTest.kt | 3 +- 4 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceApiTestConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/TestDatabaseConfiguration.kt (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test') diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt index e990c90d8..af23e7902 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt @@ -33,19 +33,16 @@ import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceIn import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan import org.springframework.test.annotation.DirtiesContext +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) @DirtiesContext -@EnableAutoConfiguration -@ComponentScan( - basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", - "org.onap.ccsdk.cds.controllerblueprints"] +@ContextConfiguration( + classes = [SelfServiceApiTestConfiguration::class, TestDatabaseConfiguration::class] ) @TestPropertySource(locations = ["classpath:application-test.properties"]) class BluePrintProcessingGRPCHandlerTest { @@ -69,7 +66,7 @@ class BluePrintProcessingGRPCHandlerTest { requestObs = blockingStub.process(object : StreamObserver { override fun onNext(executionServiceOuput: ExecutionServiceOutput) { log.debug("onNext {}", executionServiceOuput) - if ("1234".equals(executionServiceOuput.commonHeader.requestId)) { + if ("1234" == executionServiceOuput.commonHeader.requestId) { Assert.assertEquals( "Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceApiTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceApiTestConfiguration.kt new file mode 100644 index 000000000..98b882934 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/SelfServiceApiTestConfiguration.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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.selfservice.api + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.controllerblueprints", + "org.onap.ccsdk.cds.blueprintsprocessor"] +) +@EnableAutoConfiguration +open class SelfServiceApiTestConfiguration diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/TestDatabaseConfiguration.kt new file mode 100644 index 000000000..94da0f574 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/TestDatabaseConfiguration.kt @@ -0,0 +1,60 @@ +/* + * Copyright © 2018-2019 AT&T Intellectual Property. + * + * 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.selfservice.api + +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDatabaseConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.data.jpa.repository.config.EnableJpaAuditing +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.transaction.PlatformTransactionManager +import javax.sql.DataSource + +@Configuration +@Import(BluePrintDBLibConfiguration::class) +@EnableJpaRepositories( + basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution"], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" +) +@EnableJpaAuditing +open class TestDatabaseConfiguration(primaryDataSourceProperties: PrimaryDataSourceProperties) : + PrimaryDatabaseConfiguration(primaryDataSourceProperties) { + + @Bean("primaryEntityManager") + open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + return primaryEntityManager( + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution" + ) + } + + @Bean("primaryDataSource") + override fun primaryDataSource(): DataSource { + return super.primaryDataSource() + } + + @Bean("primaryTransactionManager") + override fun primaryTransactionManager(): PlatformTransactionManager { + return super.primaryTransactionManager() + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt index 820c4be42..75d9f487a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/selfservice/api/validation/BluePrintRuntimeValidatorServiceTest.kt @@ -37,7 +37,8 @@ class BluePrintRuntimeValidatorServiceTest { @Test fun testBlueprintRuntimeValidation() { - val blueprintBasePath = "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + val blueprintBasePath = + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" assertNotNull(bluePrintRuntimeValidatorService, " failed to initilize bluePrintRuntimeValidatorService") bluePrintRuntimeValidatorService.validateBluePrints(blueprintBasePath) -- cgit 1.2.3-korg