summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2023-08-28 15:21:59 +0100
committerToineSiebelink <toine.siebelink@est.tech>2023-08-29 11:25:34 +0100
commitc1183d7d14f1257b5dfa3dc67fa2f0814d1f4598 (patch)
treead64048c1c4eb2aee28fbc77195b1a0f27a0f2d5 /cps-ncmp-service/src/test/groovy
parent7dbd1856887a3e8a315752a10d7a0bf83d7da077 (diff)
Extend model loader to support model-upgrade (part 2)
- add upgrade related methods to common abstract class - add new (agreed) inventory model - add InventoryModelLoader - add more logging for success cases - simplified constant names considering the context (class name) Issue-ID: CPS-1804 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I61a5c6d320d340a5c469ce20140f984439ba71a2
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy43
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy75
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy6
3 files changed, 120 insertions, 4 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
index a271ca4312..28eae8df14 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
@@ -27,6 +27,7 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException
+import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.springframework.boot.SpringApplication
import org.slf4j.LoggerFactory
@@ -114,10 +115,32 @@ class AbstractModelLoaderSpec extends Specification {
assert thrown.details.contains('unable to read file')
}
+ def 'Delete unused schema sets.'() {
+ when: 'several unused schemas are deleted '
+ objectUnderTest.deleteUnusedSchemaSets('some dataspace','schema set 1', 'schema set 2')
+ then: 'a request to delete each (without cascade) is delegated to the module service'
+ 1 * mockCpsModuleService.deleteSchemaSet('some dataspace', 'schema set 1', CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED)
+ 1 * mockCpsModuleService.deleteSchemaSet('some dataspace', 'schema set 2', CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED)
+
+ }
+
+ def 'Delete unused schema sets with exception.'() {
+ given: 'deleting the first schemaset causes an exception'
+ mockCpsModuleService.deleteSchemaSet(_, 'schema set 1', _) >> { throw new RuntimeException('test message')}
+ when: 'several unused schemas are deleted '
+ objectUnderTest.deleteUnusedSchemaSets('some dataspace','schema set 1', 'schema set 2')
+ then: 'the exception message is logged'
+ def logs = loggingListAppender.list.toString()
+ assert logs.contains('Deleting schema set failed')
+ assert logs.contains('test message')
+ and: 'the second schema set is still deleted'
+ 1 * mockCpsModuleService.deleteSchemaSet('some dataspace', 'schema set 2', CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED)
+ }
+
def 'Create anchor.'() {
when: 'creating an anchor'
objectUnderTest.createAnchor('some dataspace','some schema set','new name')
- then: 'thr operation is delegated to the admin service'
+ then: 'the operation is delegated to the admin service'
1 * mockCpsAdminService.createAnchor('some dataspace','some schema set', 'new name')
}
@@ -174,6 +197,24 @@ class AbstractModelLoaderSpec extends Specification {
assert thrown.details.contains('test message')
}
+ def 'Update anchor schema set.'() {
+ when: 'a schema set for an anchor is updated'
+ objectUnderTest.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
+ then: 'the request is delegated to the admin service'
+ 1 * mockCpsAdminService.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
+ }
+
+ def 'Update anchor schema set with exception.'() {
+ given: 'the admin service throws an exception'
+ mockCpsAdminService.updateAnchorSchemaSet(*_) >> { throw new RuntimeException('test message') }
+ when: 'a schema set for an anchor is updated'
+ objectUnderTest.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
+ then: 'a startup exception with correct message and details is thrown'
+ def thrown = thrown(NcmpStartUpException)
+ assert thrown.message.contains('Updating schema set failed')
+ assert thrown.details.contains('test message')
+ }
+
class TestModelLoader extends AbstractModelLoader {
TestModelLoader(final CpsAdminService cpsAdminService,
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy
new file mode 100644
index 0000000000..9195bc74ca
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/InventoryModelLoaderSpec.groovy
@@ -0,0 +1,75 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.ncmp.init
+
+import ch.qos.logback.classic.Level
+import ch.qos.logback.classic.Logger
+import ch.qos.logback.core.read.ListAppender
+import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataService
+import org.onap.cps.api.CpsModuleService
+import org.onap.cps.spi.model.Dataspace
+import org.slf4j.LoggerFactory
+import org.springframework.boot.context.event.ApplicationReadyEvent
+import org.springframework.context.annotation.AnnotationConfigApplicationContext
+import spock.lang.Specification
+
+class InventoryModelLoaderSpec extends Specification {
+
+ def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsModuleService = Mock(CpsModuleService)
+ def mockCpsDataService = Mock(CpsDataService)
+ def objectUnderTest = new InventoryModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
+
+ def applicationContext = new AnnotationConfigApplicationContext()
+
+ def expectedYangResourceToContentMap
+ def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
+ def loggingListAppender
+
+ void setup() {
+ expectedYangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('dmi-registry@2023-08-23.yang')
+ logger.setLevel(Level.DEBUG)
+ loggingListAppender = new ListAppender()
+ logger.addAppender(loggingListAppender)
+ loggingListAppender.start()
+ applicationContext.refresh()
+ }
+
+ void cleanup() {
+ ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
+ applicationContext.close()
+ }
+
+ def 'Onboard subscription model via application ready event.'() {
+ given: 'dataspace is ready for use'
+ mockCpsAdminService.getDataspace('NCMP-Admin') >> new Dataspace('')
+ when: 'the application is ready'
+ objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
+ then: 'the module service is used to create the new schema set from the correct resource'
+ 1 * mockCpsModuleService.createSchemaSet('NCMP-Admin', 'dmi-registry-2023-08-23', expectedYangResourceToContentMap)
+ and: 'the admin service is used to update the anchor'
+ 1 * mockCpsAdminService.updateAnchorSchemaSet('NCMP-Admin', 'ncmp-dmi-registry', 'dmi-registry-2023-08-23')
+ and: 'No schema sets are being removed by the module service (yet)'
+ 0 * mockCpsModuleService.deleteSchemaSet('NCMP-Admin', _, _)
+ }
+
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy
index 305fe4c062..d99874ad6c 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy
@@ -41,12 +41,12 @@ class SubscriptionModelLoaderSpec extends Specification {
def applicationContext = new AnnotationConfigApplicationContext()
- def yangResourceToContentMap
+ def expectedYangResourceToContentMap
def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
def loggingListAppender
void setup() {
- yangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('subscription.yang')
+ expectedYangResourceToContentMap = objectUnderTest.createYangResourceToContentMap('subscription.yang')
logger.setLevel(Level.DEBUG)
loggingListAppender = new ListAppender()
logger.addAppender(loggingListAppender)
@@ -67,7 +67,7 @@ class SubscriptionModelLoaderSpec extends Specification {
when: 'the application is ready'
objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
then: 'the module service to create schema set is called once'
- 1 * mockCpsModuleService.createSchemaSet('NCMP-Admin', 'subscriptions', yangResourceToContentMap)
+ 1 * mockCpsModuleService.createSchemaSet('NCMP-Admin', 'subscriptions', expectedYangResourceToContentMap)
and: 'the admin service to create an anchor set is called once'
1 * mockCpsAdminService.createAnchor('NCMP-Admin', 'subscriptions', 'AVC-Subscriptions')
and: 'the data service to create a top level datanode is called once'