summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-07-31 15:35:45 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-08-01 09:46:49 +0200
commita64f197927959af5764eeadba26f3b100702af9b (patch)
treeb23e92b071cc3490eba096f336afa8ab50d29142 /aai-core/src/main
parent3eba43d76cf41205d12c0c930b7a16bc24f98875 (diff)
Add tests for the NotificationService
- change approach how ValidationService is injected into NotificationService - add tests for NotificationService - assert invokation of NotificationService instead of ValidationService in HttpEntryTest now Issue-ID: AAI-3940 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: I4476857f7192f53de216f0515f0e69c642c33d1c
Diffstat (limited to 'aai-core/src/main')
-rw-r--r--aai-core/src/main/java/org/onap/aai/prevalidation/ValidationConfiguration.java3
-rw-r--r--aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java18
-rw-r--r--aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java3
3 files changed, 8 insertions, 16 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationConfiguration.java b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationConfiguration.java
index 7030cf7d..c1a4f2a7 100644
--- a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationConfiguration.java
+++ b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationConfiguration.java
@@ -26,10 +26,9 @@ import org.onap.aai.restclient.RestClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
-@Profile("pre-validation")
@Configuration
+@ConditionalOnProperty(name = "aai.notification.validation.enabled", havingValue = "true")
public class ValidationConfiguration {
@Bean(name = "validationRestClient")
diff --git a/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java b/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
index d6a3f897..9c3dde15 100644
--- a/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
+++ b/aai-core/src/main/java/org/onap/aai/rest/notification/NotificationService.java
@@ -35,7 +35,6 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.prevalidation.ValidationService;
-import org.onap.aai.rest.db.HttpEntry;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.query.QueryEngine;
import org.onap.aai.setup.SchemaVersion;
@@ -43,8 +42,8 @@ import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.delta.DeltaEvents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
@Service
@@ -52,28 +51,23 @@ public class NotificationService {
public static final Logger LOGGER = LoggerFactory.getLogger(NotificationService.class);
+ private final ValidationService validationService;
private final LoaderFactory loaderFactory;
private final boolean isDeltaEventsEnabled;
private final String basePath;
public NotificationService(
+ @Nullable ValidationService validationService,
LoaderFactory loaderFactory,
@Value("${schema.uri.base.path}") String basePath,
@Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled) {
+ this.validationService = validationService;
this.loaderFactory = loaderFactory;
this.basePath = basePath;
this.isDeltaEventsEnabled = isDeltaEventsEnabled;
}
/**
- * Inject the validation service if the profile pre-valiation is enabled,
- * Otherwise this variable will be set to null and thats why required=false
- * so that it can continue even if pre validation isn't enabled
- */
- @Autowired(required = false)
- private ValidationService validationService;
-
- /**
* Generate notification events for the resulting db requests.
*/
public void generateEvents(UEBNotification notification, int notificationDepth, String sourceOfTruth, DBSerializer serializer,
@@ -100,9 +94,7 @@ public class NotificationService {
LOGGER.warn("Encountered exception generating events", e);
}
- // Since @Autowired required is set to false, we need to do a null check
- // for the existence of the validationService since its only enabled if profile
- // is enabled
+ // validation is configurable via aai.notification.validation.enabled
if (validationService != null) {
validationService.validate(notification.getEvents());
}
diff --git a/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java b/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
index 05e4768d..c1e8357d 100644
--- a/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/web/KafkaConfig.java
@@ -176,9 +176,10 @@ public class KafkaConfig {
}
@Bean
+ @ConditionalOnMissingBean
public NotificationService notificationService(LoaderFactory loaderFactory,
@Value("${schema.uri.base.path}") String basePath,
@Value("${delta.events.enabled:false}") boolean isDeltaEventsEnabled) {
- return new NotificationService(loaderFactory, basePath, isDeltaEventsEnabled);
+ return new NotificationService(null, loaderFactory, basePath, isDeltaEventsEnabled);
}
}