diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2024-06-06 08:16:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-06-06 08:16:39 +0000 |
commit | f8ca09bf4e5d76fb95bd1eda17f15a7fd92d0f63 (patch) | |
tree | 050f4c34ffd7f247beee4392697184b80642dbb3 /cps-ncmp-service | |
parent | 1decb39aa016bdfc7ac870aec738c9c08484c32f (diff) | |
parent | da0af8d3c666a06fad03099118343d47144e0b17 (diff) |
Merge "Change ApplicationEvent for ModelLoading"
Diffstat (limited to 'cps-ncmp-service')
5 files changed, 25 insertions, 26 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java index 4cc8cdaa66..554501127c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java @@ -39,7 +39,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.utils.JsonObjectMapper; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.context.event.ApplicationStartedEvent; @Slf4j @RequiredArgsConstructor @@ -61,12 +61,12 @@ abstract class AbstractModelLoader implements ModelLoader { long retryTimeMs; @Override - public void onApplicationEvent(@NonNull final ApplicationReadyEvent applicationReadyEvent) { + public void onApplicationEvent(@NonNull final ApplicationStartedEvent applicationStartedEvent) { try { onboardOrUpgradeModel(); } catch (final NcmpStartUpException ncmpStartUpException) { log.error("Onboarding model for NCMP failed: {} ", ncmpStartUpException.getMessage()); - SpringApplication.exit(applicationReadyEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR); + SpringApplication.exit(applicationStartedEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/ModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/ModelLoader.java index c61bf1c9b1..9832ba3f9e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/ModelLoader.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/ModelLoader.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * 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. @@ -21,13 +21,13 @@ package org.onap.cps.ncmp.init; import lombok.NonNull; -import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; -public interface ModelLoader extends ApplicationListener<ApplicationReadyEvent> { +public interface ModelLoader extends ApplicationListener<ApplicationStartedEvent> { @Override - void onApplicationEvent(@NonNull ApplicationReadyEvent applicationReadyEvent); + void onApplicationEvent(@NonNull ApplicationStartedEvent applicationStartedEvent); void onboardOrUpgradeModel(); 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 b0be29d933..162a9831ce 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 @@ -32,7 +32,7 @@ import org.onap.cps.spi.CascadeDeleteAllowed import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.springframework.boot.SpringApplication import org.slf4j.LoggerFactory -import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.boot.context.event.ApplicationStartedEvent import org.springframework.context.annotation.AnnotationConfigApplicationContext import spock.lang.Specification @@ -64,18 +64,18 @@ class AbstractModelLoaderSpec extends Specification { applicationContext.close() } - def 'Application ready event'() { - when: 'Application (ready) event is triggered' - objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent)) + def 'Application started event'() { + when: 'Application (started) event is triggered' + objectUnderTest.onApplicationEvent(Mock(ApplicationStartedEvent)) then: 'the onboard/upgrade method is executed' 1 * objectUnderTest.onboardOrUpgradeModel() } - def 'Application ready event with start up exception'() { + def 'Application started event with start up exception'() { given: 'a start up exception is thrown doing model onboarding' objectUnderTest.onboardOrUpgradeModel() >> { throw new NcmpStartUpException('test message','details are not logged') } - when: 'Application (ready) event is triggered' - objectUnderTest.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, applicationContext, null)) + when: 'Application (started) event is triggered' + objectUnderTest.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(), null, applicationContext, null)) then: 'the exception message is logged' def logs = loggingListAppender.list.toString() assert logs.contains('test message') diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy index f3b405b117..3d490c861c 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoaderSpec.groovy @@ -31,7 +31,7 @@ import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.model.Dataspace import org.slf4j.LoggerFactory -import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.boot.context.event.ApplicationStartedEvent import org.springframework.context.annotation.AnnotationConfigApplicationContext import spock.lang.Specification @@ -65,11 +65,11 @@ class CmDataSubscriptionModelLoaderSpec extends Specification { applicationContext.close() } - def 'Onboard subscription model via application ready event.'() { + def 'Onboard subscription model via application started event.'() { given: 'dataspace is ready for use' mockCpsDataspaceService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('') when: 'the application is ready' - objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent)) + objectUnderTest.onApplicationEvent(Mock(ApplicationStartedEvent)) then: 'the module service to create schema set is called once' 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', expectedYangResourcesToContentMap) and: 'the admin service to create an anchor set is called once' 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 index cd659bb528..d432886888 100644 --- 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 @@ -20,23 +20,22 @@ package org.onap.cps.ncmp.init -import org.onap.cps.api.CpsAnchorService - -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME -import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR - import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger import ch.qos.logback.core.read.ListAppender -import org.onap.cps.api.CpsDataspaceService +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.spi.model.Dataspace import org.slf4j.LoggerFactory -import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.boot.context.event.ApplicationStartedEvent import org.springframework.context.annotation.AnnotationConfigApplicationContext import spock.lang.Specification +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME +import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR + class InventoryModelLoaderSpec extends Specification { def mockCpsAdminService = Mock(CpsDataspaceService) @@ -68,8 +67,8 @@ class InventoryModelLoaderSpec extends Specification { def 'Onboard subscription model via application ready event.'() { given: 'dataspace is ready for use' mockCpsAdminService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('') - when: 'the application is ready' - objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent)) + when: 'the application is started' + objectUnderTest.onApplicationEvent(Mock(ApplicationStartedEvent)) then: 'the module service is used to create the new schema set from the correct resource' 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2024-02-23', expectedYangResourceToContentMap) and: 'the admin service is used to update the anchor' |