aboutsummaryrefslogtreecommitdiffstats
path: root/integration-test/src/test/groovy
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-02-13 11:12:29 +0000
committerDaniel Hanrahan <daniel.hanrahan@est.tech>2024-02-14 11:25:44 +0000
commit741fafc5b59e974b79a1e48d9e57e12efa70c219 (patch)
tree4643508c2ef7f2b2ac527e819b14ece80c7fdf9d /integration-test/src/test/groovy
parent4f5671a73677db89bf21f6c1a9ff6a0585f5783e (diff)
Clean up of integration-test base classes
- Remove TestConfig and instead use auto-configuration - Add needed application.yml config - Refactor helper methods for creating JSON Issue-ID: CPS-2090 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I4f618a1d4a83e9c75e468928c257b817d449c22f
Diffstat (limited to 'integration-test/src/test/groovy')
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy48
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy2
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy131
3 files changed, 13 insertions, 168 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
index b59e0ff55..27a987747 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
@@ -20,64 +20,54 @@
package org.onap.cps.integration.base
+import java.time.OffsetDateTime
import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
import org.onap.cps.integration.DatabaseTestContainer
-import org.onap.cps.spi.config.CpsSessionFactory
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.repository.DataspaceRepository
-import org.onap.cps.spi.impl.utils.CpsValidatorImpl
import org.onap.cps.spi.utils.SessionManager
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.ComponentScan
-import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.testcontainers.spock.Testcontainers
import spock.lang.Shared
import spock.lang.Specification
-import java.time.OffsetDateTime
-
-@SpringBootTest(classes = [TestConfig, CpsValidatorImpl, SessionManager, CpsSessionFactory])
+@SpringBootTest(classes = [CpsDataspaceService])
@Testcontainers
@EnableAutoConfiguration
@EnableJpaRepositories(basePackageClasses = [DataspaceRepository])
-@ComponentScan(basePackages = ['org.onap.cps.api', 'org.onap.cps.spi.repository'])
+@ComponentScan(basePackages = ['org.onap.cps'])
@EntityScan('org.onap.cps.spi.entities')
-class CpsIntegrationSpecBase extends Specification {
+abstract class CpsIntegrationSpecBase extends Specification {
@Shared
DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance()
@Autowired
- @Lazy
CpsDataspaceService cpsDataspaceService
@Autowired
- @Lazy
CpsAnchorService cpsAnchorService
@Autowired
- @Lazy
CpsDataService cpsDataService
@Autowired
- @Lazy
CpsModuleService cpsModuleService
@Autowired
- @Lazy
CpsQueryService cpsQueryService
@Autowired
- @Lazy
SessionManager sessionManager
def static GENERAL_TEST_DATASPACE = 'generalTestDataspace'
@@ -90,7 +80,7 @@ class CpsIntegrationSpecBase extends Specification {
if (!initialized) {
cpsDataspaceService.createDataspace(GENERAL_TEST_DATASPACE)
createStandardBookStoreSchemaSet(GENERAL_TEST_DATASPACE)
- initialized = true;
+ initialized = true
}
}
@@ -127,7 +117,7 @@ class CpsIntegrationSpecBase extends Specification {
def dataspaceExists(dataspaceName) {
try {
cpsDataspaceService.getDataspace(dataspaceName)
- } catch (DataspaceNotFoundException dataspaceNotFoundException) {
+ } catch (DataspaceNotFoundException ignored) {
return false
}
return true
@@ -141,29 +131,15 @@ class CpsIntegrationSpecBase extends Specification {
}
def createJsonArray(name, numberOfElements, keyName, keyValuePrefix, dataPerKey) {
- def json = '{"' + name + '":['
- (1..numberOfElements).each {
- json += '{"' + keyName + '":"' + keyValuePrefix + '-' + it + '"'
- if (!dataPerKey.isEmpty()) {
- json += ',' + dataPerKey
- }
- json += '}'
- if (it < numberOfElements) {
- json += ','
- }
- }
- json += ']}'
+ def innerJson = (1..numberOfElements).collect {
+ '{"' + keyName + '":"' + keyValuePrefix + '-' + it + '"' + (dataPerKey.empty? '': ',' + dataPerKey) + '}'
+ }.join(',')
+ return '{"' + name + '":[' + innerJson + ']}'
}
def createLeafList(name, numberOfElements, valuePrefix) {
- def json = '"' + name + '":['
- (1..numberOfElements).each {
- json += '"' + valuePrefix + '-' + it + '"'
- if (it < numberOfElements) {
- json += ','
- }
- }
- json += ']'
+ def innerJson = (1..numberOfElements).collect {'"' + valuePrefix + '-' + it + '"'}.join(',')
+ return '"' + name + '":[' + innerJson + ']'
}
}
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy
index b3b584214..6929a2b67 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy
@@ -23,7 +23,7 @@ package org.onap.cps.integration.base
import java.time.OffsetDateTime
-class FunctionalSpecBase extends CpsIntegrationSpecBase {
+abstract class FunctionalSpecBase extends CpsIntegrationSpecBase {
def static FUNCTIONAL_TEST_DATASPACE_1 = 'functionalTestDataspace1'
def static FUNCTIONAL_TEST_DATASPACE_2 = 'functionalTestDataspace2'
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy
deleted file mode 100644
index 69c2d1744..000000000
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.integration.base
-
-import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.cps.api.impl.YangTextSchemaSourceSetCache
-import org.onap.cps.spi.CpsDataPersistenceService
-import org.onap.cps.spi.CpsModulePersistenceService
-import org.onap.cps.spi.impl.CpsAdminPersistenceServiceImpl
-import org.onap.cps.spi.impl.CpsDataPersistenceServiceImpl
-import org.onap.cps.spi.impl.CpsModulePersistenceServiceImpl
-import org.onap.cps.spi.repository.AnchorRepository
-import org.onap.cps.spi.repository.DataspaceRepository
-import org.onap.cps.spi.repository.FragmentRepository
-import org.onap.cps.spi.repository.ModuleReferenceRepository
-import org.onap.cps.spi.repository.SchemaSetRepository
-import org.onap.cps.spi.repository.YangResourceRepository
-import org.onap.cps.spi.utils.SessionManager
-import org.onap.cps.spi.utils.TimeLimiterProvider
-import org.onap.cps.utils.JsonObjectMapper
-import org.onap.cps.utils.YangParser
-import org.onap.cps.utils.YangParserHelper
-import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.context.annotation.Bean
-import org.springframework.context.annotation.Configuration
-import org.springframework.context.annotation.Lazy
-import spock.lang.Specification
-
-@Configuration
-class TestConfig extends Specification{
- @Autowired
- @Lazy
- DataspaceRepository dataspaceRepository
-
- @Autowired
- @Lazy
- AnchorRepository anchorRepository
-
- @Autowired
- @Lazy
- SchemaSetRepository schemaSetRepository
-
- @Autowired
- @Lazy
- YangResourceRepository yangResourceRepository
-
- @Autowired
- @Lazy
- FragmentRepository fragmentRepository
-
- @Autowired
- @Lazy
- ModuleReferenceRepository moduleReferenceRepository
-
- @Autowired
- @Lazy
- JsonObjectMapper jsonObjectMapper
-
- @Autowired
- @Lazy
- SessionManager sessionManager
-
- @Autowired
- @Lazy
- YangParserHelper yangParserHelper
-
- @Autowired
- @Lazy
- YangTextSchemaSourceSetCache YangTextSchemaSourceSetCache
-
-
- @Bean
- CpsAdminPersistenceServiceImpl cpsAdminPersistenceService() {
- new CpsAdminPersistenceServiceImpl(dataspaceRepository, anchorRepository, schemaSetRepository, yangResourceRepository)
- }
-
- @Bean
- CpsDataPersistenceService cpsDataPersistenceService() {
- return (CpsDataPersistenceService) new CpsDataPersistenceServiceImpl(dataspaceRepository, anchorRepository, fragmentRepository, jsonObjectMapper, sessionManager)
- }
-
- @Bean
- CpsModulePersistenceService cpsModulePersistenceService() {
- return (CpsModulePersistenceService) new CpsModulePersistenceServiceImpl(yangResourceRepository, schemaSetRepository, dataspaceRepository, moduleReferenceRepository)
- }
-
- @Bean
- JsonObjectMapper jsonObjectMapper() {
- return new JsonObjectMapper(new ObjectMapper())
- }
-
- @Bean
- YangParserHelper yangParserHelper() {
- return new YangParserHelper()
- }
-
- @Bean
- YangParser yangParser() {
- return new YangParser(yangParserHelper, yangTextSchemaSourceSetCache)
- }
-
- @Bean
- TimedYangTextSchemaSourceSetBuilder textSchemaSourceSetBuilder() {
- return new TimedYangTextSchemaSourceSetBuilder()
- }
-
- @Bean
- TimeLimiterProvider timeLimiterProvider() {
- return new TimeLimiterProvider()
- }
-
-}