diff options
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r-- | cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy | 35 | ||||
-rw-r--r-- | cps-ncmp-service/src/test/resources/application.yml | 5 |
2 files changed, 37 insertions, 3 deletions
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 65c0497c9a..907208228c 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 @@ -26,9 +26,11 @@ import ch.qos.logback.core.read.ListAppender import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach 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.exceptions.AlreadyDefinedException +import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.exceptions.SchemaSetNotFoundException import org.springframework.boot.SpringApplication import org.slf4j.LoggerFactory @@ -39,11 +41,13 @@ class SubscriptionModelLoaderSpec extends Specification { def mockCpsAdminService = Mock(CpsAdminService) def mockCpsModuleService = Mock(CpsModuleService) - def objectUnderTest = new SubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService) + def mockCpsDataService = Mock(CpsDataService) + def objectUnderTest = new SubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService) def SUBSCRIPTION_DATASPACE_NAME = objectUnderTest.SUBSCRIPTION_DATASPACE_NAME; def SUBSCRIPTION_ANCHOR_NAME = objectUnderTest.SUBSCRIPTION_ANCHOR_NAME; def SUBSCRIPTION_SCHEMASET_NAME = objectUnderTest.SUBSCRIPTION_SCHEMASET_NAME; + def SUBSCRIPTION_REGISTRY_DATANODE_NAME = objectUnderTest.SUBSCRIPTION_REGISTRY_DATANODE_NAME; def sampleYangContentMap = ['subscription.yang':'module subscription { *sample content* }'] @@ -67,12 +71,16 @@ class SubscriptionModelLoaderSpec extends Specification { } def 'Onboard subscription model successfully via application ready event'() { - when: 'the application is ready' + when:'model loader is enabled' + objectUnderTest.subscriptionModelLoaderEnabled = true + and: 'the application is ready' objectUnderTest.onApplicationEvent(applicationReadyEvent) then: 'the module service to create schema set is called once' 1 * mockCpsModuleService.createSchemaSet(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_SCHEMASET_NAME,sampleYangContentMap) and: 'the admin service to create an anchor set is called once' 1 * mockCpsAdminService.createAnchor(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_SCHEMASET_NAME, SUBSCRIPTION_ANCHOR_NAME) + and: 'the data service to create a top level datanode is called once' + 1 * mockCpsDataService.saveData(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME, '{"' + SUBSCRIPTION_REGISTRY_DATANODE_NAME + '":{}}', _) } def 'Create schema set from model file'() { @@ -136,6 +144,29 @@ class SubscriptionModelLoaderSpec extends Specification { thrown(NcmpStartUpException) } + def 'Create top level node fails due to an AlreadyDefined exception'() { + given: 'the saving of the node data will throw an Already Defined exception' + mockCpsDataService.saveData(*_) >> + { AlreadyDefinedException.forDataNode('/xpath', "sampleContextName", null) } + when: 'the method to onboard model is called' + objectUnderTest.onboardSubscriptionModel() + then: 'no exception thrown' + noExceptionThrown() + } + + def 'Create top level node fails due to any other exception'() { + given: 'the saving of the node data will throw an exception' + mockCpsDataService.saveData(*_) >> + { throw new DataValidationException("Invalid JSON", "JSON Data is invalid") } + when: 'the method to onboard model is called' + objectUnderTest.onboardSubscriptionModel() + then: 'the log message contains the correct exception message' + def debugMessage = appender.list[0].toString() + assert debugMessage.contains("Creating data node for subscription model failed: Invalid JSON") + and: 'exception is thrown' + thrown(NcmpStartUpException) + } + def 'Get file content as string'() { when: 'the method to get yang content is called' def response = objectUnderTest.getFileContentAsString() diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml index e8b4be4bcf..b7dfe86c10 100644 --- a/cps-ncmp-service/src/test/resources/application.yml +++ b/cps-ncmp-service/src/test/resources/application.yml @@ -31,4 +31,7 @@ ncmp: modules-sync-watchdog: async-executor: - parallelism-level: 3
\ No newline at end of file + parallelism-level: 3 + + model-loader: + subscription: true
\ No newline at end of file |