aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-05 11:38:01 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-08 14:59:46 +0200
commitf9999359c898143d0fb9a4a62063cbc51a40e25e (patch)
tree0cf789c1403af4607e557ffeb2c37a8fb9e72be0 /src/test/java/org
parent598c2469a004c50a1b29882e02e2fab7a8407d8b (diff)
Model distribution fails with model-loader 1.13.5
- move sdc-distribution-client instantiation out of the ModelController into a separate class - add integration test with embedded kafka (not fully implemented) Issue-ID: AAI-3818 Change-Id: I0b5dd118d9145372ddf123319b58829d0ef9275a Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/aai/modelloader/distribution/EventCallbackAspect.java49
-rw-r--r--src/test/java/org/onap/aai/modelloader/distribution/NotificationIntegrationTest.java66
-rw-r--r--src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java2
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java1
-rw-r--r--src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java2
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelController.java1
6 files changed, 118 insertions, 3 deletions
diff --git a/src/test/java/org/onap/aai/modelloader/distribution/EventCallbackAspect.java b/src/test/java/org/onap/aai/modelloader/distribution/EventCallbackAspect.java
new file mode 100644
index 0000000..16f311b
--- /dev/null
+++ b/src/test/java/org/onap/aai/modelloader/distribution/EventCallbackAspect.java
@@ -0,0 +1,49 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.distribution;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.stereotype.Component;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Aspect
+@Getter
+@Setter
+@Component
+/**
+ * Aspect to asynchronously wait for the EventCallback being called after a distribution event from sdc was published
+ */
+public class EventCallbackAspect {
+
+ private CountDownLatch countDownLatch;
+
+ @After(
+ "execution(* org.onap.aai.modelloader.notification.EventCallback.activateCallback(..))")
+ private void afterEventCallbackCalled() {
+ if (countDownLatch != null) {
+ countDownLatch.countDown();
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/aai/modelloader/distribution/NotificationIntegrationTest.java b/src/test/java/org/onap/aai/modelloader/distribution/NotificationIntegrationTest.java
new file mode 100644
index 0000000..2645871
--- /dev/null
+++ b/src/test/java/org/onap/aai/modelloader/distribution/NotificationIntegrationTest.java
@@ -0,0 +1,66 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.distribution;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.test.context.EmbeddedKafka;
+import org.springframework.test.annotation.DirtiesContext;
+
+@DirtiesContext
+@SpringBootTest(properties = { "model-loader.sdc.connection.enabled=true"})
+@EmbeddedKafka(partitions = 1, brokerProperties = { "listeners=PLAINTEXT://localhost:9092", "port=9092" })
+public class NotificationIntegrationTest {
+
+ @Autowired EventCallbackAspect eventCallbackAspect;
+
+ @Autowired
+ private KafkaTemplate<String, String> kafkaTemplate;
+
+ @Value("${test.topic}")
+ private String topic;
+
+ @Test
+ @Disabled("This test is not yet implemented")
+ public void thatActivateCallbackIsCalled()
+ throws Exception {
+ String data = "Smth";
+
+ // TODO: send distribution event here
+ kafkaTemplate.send(topic, data);
+
+ // TODO: mock distribution client requests to /sdc/v1/artifactTypes
+ // TODO: mock distribution client requests to /sdc/v1/distributionKafkaData
+
+ // aspect will wait for EventCallback.activateCallback to be called
+ eventCallbackAspect.setCountDownLatch(new CountDownLatch(1));
+ boolean callbackCalled = eventCallbackAspect.getCountDownLatch().await(10, TimeUnit.SECONDS);
+ assertTrue(callbackCalled);
+ }
+}
diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java
index fac50cb..177a8d2 100644
--- a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java
+++ b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java
@@ -57,7 +57,7 @@ public class TestModelArtifactHandler {
@BeforeEach
public void setupMocks() {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.openMocks(this);
}
@Test
diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java
index c09eff5..48b9a66 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java
@@ -27,7 +27,6 @@ import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithInvalidType;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithModelQuerySpec;
diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
index 19e35ca..77e1594 100644
--- a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
+++ b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java
@@ -90,6 +90,8 @@ public class TestBabelServiceClient {
configProperties.put("ml.babel.TRUSTSTORE_FILE", "src/test/resources/auth/aai-client-dummy.p12");
configProperties.put("ml.babel.BASE_URL", url);
configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate");
+ configProperties.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "12000");
+ configProperties.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "12000");
BabelServiceClient client =
new HttpsBabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, "."));
List<BabelArtifact> result =
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelController.java b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
index 9106342..82f7203 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
@@ -23,7 +23,6 @@ package org.onap.aai.modelloader.service;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;