diff options
author | 2024-02-07 17:07:25 +0000 | |
---|---|---|
committer | 2024-02-08 11:27:01 +0000 | |
commit | a670176caac46fb68ef0a8ced0160c980f4cce05 (patch) | |
tree | 566bdf839c98825b9b5ed4e5b0e53ab9993e420d /cps-ncmp-service/src/test/groovy | |
parent | a3096b9d22b7a3517c7933dfeb10984f6bedf063 (diff) |
Correct use of Spock setup and cleanup methods (no need for @Before @After)
- unfortunately we copied the bad test code for logging about 4 times alraedy...
- simplified setup for WatchdogSchedulingConfigurerSpec
Issue-ID:CPS-465
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: I8d068541263272fdf99a6e30d365d85e31726432
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
3 files changed, 12 insertions, 39 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventConsumerSpec.groovy index 57e77eba3..44d6eb6a0 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/CmSubscriptionNcmpInEventConsumerSpec.groovy @@ -28,8 +28,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import io.cloudevents.CloudEvent import io.cloudevents.core.builder.CloudEventBuilder import org.apache.kafka.clients.consumer.ConsumerRecord -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent import org.onap.cps.ncmp.utils.TestUtils @@ -50,15 +48,13 @@ class CmSubscriptionNcmpInEventConsumerSpec extends MessagingBaseSpec { @Autowired ObjectMapper objectMapper - @BeforeEach void setup() { - ((Logger) LoggerFactory.getLogger(CmSubscriptionNcmpInEventConsumer.class)).addAppender(logger); - logger.start(); + ((Logger) LoggerFactory.getLogger(CmSubscriptionNcmpInEventConsumer.class)).addAppender(logger) + logger.start() } - @AfterEach - void teardown() { - ((Logger) LoggerFactory.getLogger(CmSubscriptionNcmpInEventConsumer.class)).detachAndStopAllAppenders(); + void cleanup() { + ((Logger) LoggerFactory.getLogger(CmSubscriptionNcmpInEventConsumer.class)).detachAndStopAllAppenders() } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy index 3bdac1855..ece2d9f86 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-2024 Nordix Foundation * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,6 @@ package org.onap.cps.ncmp.api.impl.inventory.sync - import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_SYNC_FAILED import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE_FAILED @@ -32,8 +31,6 @@ import ch.qos.logback.core.read.ListAppender import com.hazelcast.config.Config import com.hazelcast.instance.impl.HazelcastInstanceFactory import com.hazelcast.map.IMap -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.impl.inventory.CmHandleState @@ -50,15 +47,13 @@ class ModuleSyncTasksSpec extends Specification { def logger = Spy(ListAppender<ILoggingEvent>) - @BeforeEach void setup() { - ((Logger) LoggerFactory.getLogger(ModuleSyncTasks.class)).addAppender(logger); - logger.start(); + ((Logger) LoggerFactory.getLogger(ModuleSyncTasks.class)).addAppender(logger) + logger.start() } - @AfterEach - void teardown() { - ((Logger) LoggerFactory.getLogger(ModuleSyncTasks.class)).detachAndStopAllAppenders(); + void cleanup() { + ((Logger) LoggerFactory.getLogger(ModuleSyncTasks.class)).detachAndStopAllAppenders() } def mockInventoryPersistence = Mock(InventoryPersistence) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy index 7760b39cb..f37d5a41e 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation + * Copyright (C) 2022-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. @@ -20,35 +20,17 @@ package org.onap.cps.ncmp.api.impl.inventory.sync.config -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.BeforeEach -import org.onap.cps.ncmp.api.impl.inventory.sync.config.WatchdogSchedulingConfigurer import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest -import org.springframework.context.ConfigurableApplicationContext import org.springframework.test.context.ContextConfiguration import spock.lang.Specification @SpringBootTest -@ContextConfiguration(classes = [ConfigurableApplicationContext, WatchdogSchedulingConfigurer]) +@ContextConfiguration(classes = [WatchdogSchedulingConfigurer]) class WatchdogSchedulingConfigurerSpec extends Specification { @Autowired - private ConfigurableApplicationContext applicationContext; - - def watchdogSchedulingConfigurer; - - @BeforeEach - void setup() { - watchdogSchedulingConfigurer = (WatchdogSchedulingConfigurer) applicationContext.getBean("watchdogSchedulingConfigurer") - } - - @AfterEach - void tearDown() { - if (applicationContext != null) { - applicationContext.close() - } - } + WatchdogSchedulingConfigurer watchdogSchedulingConfigurer def 'Validate watchdog scheduling configuration'() { given: 'task scheduler configuration properties are loaded as map' |