Clean up of integration-test base classes 12/137212/4
authordanielhanrahan <daniel.hanrahan@est.tech>
Tue, 13 Feb 2024 11:12:29 +0000 (11:12 +0000)
committerDaniel Hanrahan <daniel.hanrahan@est.tech>
Wed, 14 Feb 2024 11:25:44 +0000 (11:25 +0000)
- 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

integration-test/pom.xml
integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
integration-test/src/test/groovy/org/onap/cps/integration/base/FunctionalSpecBase.groovy
integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy [deleted file]
integration-test/src/test/resources/application.yml

index 6947a94..c3a5eee 100644 (file)
             <artifactId>spock</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.kafka</groupId>
-            <artifactId>spring-kafka-test</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
index b59e0ff..27a9877 100644 (file)
 
 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 + ']'
     }
 
 }
index b3b5842..6929a2b 100644 (file)
@@ -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 (file)
index 69c2d17..0000000
+++ /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()
-    }
-
-}
index dbff207..1a08e54 100644 (file)
 #  SPDX-License-Identifier: Apache-2.0
 #  ============LICENSE_END=========================================================
 
+rest:
+  api:
+    cps-base-path: /cps/api
+    ncmp-base-path: /ncmp
+    ncmp-inventory-base-path: /ncmpInventory
+
 spring:
+  main:
+    banner-mode: off
+
+  application:
+    name: cps-integration-test
+
   jpa:
-    ddl-auto: create
-    show-sql: false
     properties:
       hibernate.enable_lazy_load_no_trans: true
       hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
-      hibernate.format_sql: true
+      hibernate.format_sql: false
       hibernate.show_sql: false
       # Please ensure these values match those used in cps-application/src/main/resources/application.yml
       hibernate.id.new_generator_mappings: true
@@ -34,6 +44,84 @@ spring:
     password: ${DB_PASSWORD}
     driverClassName: org.postgresql.Driver
     initialization-mode: always
+    hikari:
+      minimumIdle: 5
+      maximumPoolSize: 80
+      idleTimeout: 60000
+      connectionTimeout: 120000
+      leakDetectionThreshold: 30000
+      pool-name: CpsDatabasePool
+
+  cache:
+    type: caffeine
+    cache-names: yangSchema
+    caffeine:
+      spec: maximumSize=10000,expireAfterAccess=10m
 
   liquibase:
     change-log: classpath:changelog/changelog-master.yaml
+
+  servlet:
+    multipart:
+      enabled: true
+      max-file-size: 100MB
+      max-request-size: 100MB
+
+  jackson:
+    default-property-inclusion: NON_NULL
+    serialization:
+      FAIL_ON_EMPTY_BEANS: false
+
+  sql:
+    init:
+      mode: ALWAYS
+
+notification:
+  enabled: false
+
+springdoc:
+  swagger-ui:
+    disable-swagger-default-url: true
+    urlsPrimaryName: cps-core
+    urls:
+      - name: cps-core
+        url: /api-docs/cps-core/openapi.yaml
+      - name: cps-ncmp
+        url: /api-docs/cps-ncmp/openapi.yaml
+      - name: cps-ncmp-inventory
+        url: /api-docs/cps-ncmp/openapi-inventory.yaml
+
+security:
+  # comma-separated uri patterns which do not require authorization
+  permit-uri: /actuator/**,/swagger-ui.html,/swagger-ui/**,/swagger-resources/**,/api-docs/**,/v3/api-docs/**
+  auth:
+    username: cps
+    password: cpsr0cks!
+
+# Actuator
+management:
+  endpoints:
+    web:
+      exposure:
+        include: info,health,loggers,prometheus
+  endpoint:
+    health:
+      show-details: always
+      # kubernetes probes: liveness and readiness
+      probes:
+        enabled: false
+
+logging:
+  format: text
+  level:
+    org:
+      springframework: INFO
+      onap:
+        cps: INFO
+
+hazelcast:
+  cluster-name: cps-and-ncmp-test-caches
+  mode:
+    kubernetes:
+      enabled: false
+      service-name: cps-and-ncmp-service