summaryrefslogtreecommitdiffstats
path: root/sdc-distribution-ci/src/test/java
diff options
context:
space:
mode:
authorEdyta Krukowska <edyta.krukowska@nokia.com>2021-01-05 12:27:02 +0100
committerEdyta Krukowska <edyta.krukowska@nokia.com>2021-01-07 08:26:09 +0100
commitfe52f1b0054d4551f83d9448d894160981c4e07f (patch)
tree4d87fbc8a19d055211400b47d590e59f26eaf8eb /sdc-distribution-ci/src/test/java
parent2ca084cf51507724d771c15bb57997af35cbed75 (diff)
Create IT test for downloading artifacts
Issue-ID: SDC-3417 Signed-off-by: Edyta Krukowska <edyta.krukowska@nokia.com> Change-Id: I8bd24c34902a2d59d0d0dd1b0c1e8c08352a4cc2
Diffstat (limited to 'sdc-distribution-ci/src/test/java')
-rw-r--r--sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java46
1 files changed, 43 insertions, 3 deletions
diff --git a/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java b/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java
index 40278b1..797009d 100644
--- a/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java
+++ b/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java
@@ -19,6 +19,8 @@
*/
package org.onap.test.core.service;
+import org.awaitility.Duration;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -26,17 +28,26 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.sdc.impl.DistributionClientDownloadResultImpl;
import org.onap.sdc.impl.DistributionClientImpl;
import org.onap.test.core.config.DistributionClientConfig;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.verify;
@Testcontainers
@@ -47,12 +58,16 @@ class ClientInitializerTest {
private static final int SUCCESSFUL_UNREGISTER_MSG_INDEX = 3;
private static final int SUCCESSFUL_INIT_MSG_INDEX = 0;
private static final int SUCCESSFUL_DIST_MSG_INDEX = 3;
+ private static final int EXPECTED_HEAT_ARTIFACTS = 4;
private ClientInitializer clientInitializer;
+ private ClientNotifyCallback clientNotifyCallback;
+ private static final Logger testLog = LoggerFactory.getLogger(ClientInitializerTest.class);
@Container
public GenericContainer mockDmaap = new GenericContainer("registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-dmaap:latest")
.withNetworkMode("host");
+
@Container
public GenericContainer mockSdc = new GenericContainer("registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-sdc:latest")
.withNetworkMode("host");
@@ -62,13 +77,14 @@ class ClientInitializerTest {
@Mock
Logger distClientLog;
+
@BeforeEach
public void initializeClient() {
DistributionClientConfig clientConfig = new DistributionClientConfig();
List<ArtifactsValidator> validators = new ArrayList<>();
DistributionClientImpl client = new DistributionClientImpl(distClientLog);
- ClientNotifyCallback callback = new ClientNotifyCallback(validators, client);
- clientInitializer = new ClientInitializer(clientConfig, callback, client);
+ clientNotifyCallback = new ClientNotifyCallback(validators, client);
+ clientInitializer = new ClientInitializer(clientConfig, clientNotifyCallback, client);
}
@Test
@@ -98,4 +114,28 @@ class ClientInitializerTest {
assertThat(allValues.get(SUCCESSFUL_STOP_MSG_INDEX)).isEqualTo("stop DistributionClient");
assertThat(allValues.get(SUCCESSFUL_UNREGISTER_MSG_INDEX)).isEqualTo("client unregistered from topics successfully");
}
-} \ No newline at end of file
+
+ @Test
+ public void shouldDownloadArtifactsWithArtifactTypeHeat() throws IOException, InterruptedException {
+
+ //given
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create("http://localhost:3904/events/testName/add"))
+ .POST(HttpRequest.BodyPublishers.ofFile(Paths.get("src/test/resources/artifacts.json")))
+ .build();
+ HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
+ //when
+ clientInitializer.initialize();
+ waitForArtifacts();
+ List<DistributionClientDownloadResultImpl> calls = clientNotifyCallback.getPulledArtifacts();
+ //then
+ Assertions.assertEquals(EXPECTED_HEAT_ARTIFACTS, calls.size());
+ }
+
+ private void waitForArtifacts() {
+ testLog.info("Waiting for artifacts");
+ await()
+ .atMost(Duration.ONE_MINUTE)
+ .until(() -> !clientNotifyCallback.getPulledArtifacts().isEmpty());
+ }
+}