summaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2019-06-14 11:42:38 +0000
committerPatrikBuhr <patrik.buhr@est.tech>2019-06-14 11:42:38 +0000
commit21f0997ab8b1d16b05a0dd5929ff0491ea47c466 (patch)
tree705d1e4c09899f1e8ed72f50be2bf0b0a2c2e7e5 /datafile-app-server/src/test
parentdafd553cf1694585b35fd7132c6bafdef1e98ed6 (diff)
Code formatting with maven
This commit only contains code formastting changes done by command: mvn formatter:format spotless:apply process-sources Change-Id: I0fb9d166ad5d9171cdeee9f26b6d353bca74069c Issue-ID: DCAEGEN2-1538 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'datafile-app-server/src/test')
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java174
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java13
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java4
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java5
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java70
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java84
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java547
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java1
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java3
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java150
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java73
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java106
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java14
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java199
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java128
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java3
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java1
17 files changed, 791 insertions, 784 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java
index 31c542d3..b3710fe3 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.JsonElement;
@@ -36,6 +37,7 @@ import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -44,6 +46,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -55,6 +58,7 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuratio
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
+
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -69,30 +73,19 @@ class AppConfigTest {
private static final String CHANGE_IDENTIFIER = "PM_MEAS_FILES";
-
private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = //
- new ImmutableDmaapConsumerConfiguration.Builder() //
- .timeoutMs(-1) //
- .dmaapHostName("message-router.onap.svc.cluster.local") //
- .dmaapUserName("admin") //
- .dmaapUserPassword("admin") //
- .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
- .dmaapPortNumber(2222) //
- .dmaapContentType("application/json") //
- .messageLimit(-1) //
- .dmaapProtocol("http") //
- .consumerId("C12") //
- .consumerGroup("OpenDcae-c12") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
-
- private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() //
- .topicUrl(
- "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
+ new ImmutableDmaapConsumerConfiguration.Builder() //
+ .timeoutMs(-1) //
+ .dmaapHostName("message-router.onap.svc.cluster.local") //
+ .dmaapUserName("admin") //
+ .dmaapUserPassword("admin") //
+ .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
+ .dmaapPortNumber(2222) //
+ .dmaapContentType("application/json") //
+ .messageLimit(-1) //
+ .dmaapProtocol("http") //
+ .consumerId("C12") //
+ .consumerGroup("OpenDcae-c12") //
.trustStorePath("trustStorePath") //
.trustStorePasswordPath("trustStorePasswordPath") //
.keyStorePath("keyStorePath") //
@@ -100,57 +93,66 @@ class AppConfigTest {
.enableDmaapCertAuth(true) //
.build();
+ private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() //
+ .topicUrl(
+ "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
+
private static final PublisherConfiguration CORRECT_PUBLISHER_CONFIG = //
- ImmutablePublisherConfiguration.builder() //
- .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") //
- .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier("PM_MEAS_FILES") //
- .userName("user") //
- .passWord("password") //
- .build();
+ ImmutablePublisherConfiguration.builder() //
+ .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") //
+ .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier("PM_MEAS_FILES") //
+ .userName("user") //
+ .passWord("password") //
+ .build();
private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION = //
- new ImmutableFtpesConfig.Builder() //
- .keyCert("/config/dfc.jks") //
- .keyPassword("secret") //
- .trustedCa("config/ftp.jks") //
- .trustedCaPassword("secret") //
- .build();
+ new ImmutableFtpesConfig.Builder() //
+ .keyCert("/config/dfc.jks") //
+ .keyPassword("secret") //
+ .trustedCa("config/ftp.jks") //
+ .trustedCaPassword("secret") //
+ .build();
private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG = //
- new ImmutableDmaapPublisherConfiguration.Builder() //
- .dmaapTopicName("/publish/1") //
- .dmaapUserPassword("password") //
- .dmaapPortNumber(3907) //
- .dmaapProtocol("https") //
- .dmaapContentType("application/octet-stream") //
- .dmaapHostName("message-router.onap.svc.cluster.local") //
- .dmaapUserName("user") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ new ImmutableDmaapPublisherConfiguration.Builder() //
+ .dmaapTopicName("/publish/1") //
+ .dmaapUserPassword("password") //
+ .dmaapPortNumber(3907) //
+ .dmaapProtocol("https") //
+ .dmaapContentType("application/octet-stream") //
+ .dmaapHostName("message-router.onap.svc.cluster.local") //
+ .dmaapUserName("user") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
private static EnvProperties properties() {
return ImmutableEnvProperties.builder() //
- .consulHost("host") //
- .consulPort(123) //
- .cbsName("cbsName") //
- .appName("appName") //
- .build();
+ .consulHost("host") //
+ .consulPort(123) //
+ .cbsName("cbsName") //
+ .appName("appName") //
+ .build();
}
private AppConfig appConfigUnderTest;
private CloudConfigurationProvider cloudConfigurationProvider = mock(CloudConfigurationProvider.class);
private final Map<String, String> context = MappedDiagnosticContext.initializeTraceContext();
-
@BeforeEach
public void setUp() {
appConfigUnderTest = spy(AppConfig.class);
@@ -196,9 +198,9 @@ class AppConfigTest {
Assertions.assertNotNull(appConfigUnderTest.getPublisherConfiguration("YY_FILES"));
assertThat(appConfigUnderTest.getPublisherConfiguration("XX_FILES").publishUrl())
- .isEqualTo("feed01::publish_url");
+ .isEqualTo("feed01::publish_url");
assertThat(appConfigUnderTest.getPublisherConfiguration("YY_FILES").publishUrl())
- .isEqualTo("feed01::publish_url");
+ .isEqualTo("feed01::publish_url");
}
@Test
@@ -213,12 +215,12 @@ class AppConfigTest {
// Then
assertTrue("Error message missing in log.",
- logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json"));
+ logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json"));
logAppender.stop();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES");
+ .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES");
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
@@ -233,7 +235,7 @@ class AppConfigTest {
verify(appConfigUnderTest, times(1)).loadConfigurationFromFile();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining(CHANGE_IDENTIFIER);
+ .hasMessageContaining(CHANGE_IDENTIFIER);
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
@@ -251,7 +253,7 @@ class AppConfigTest {
verify(appConfigUnderTest, times(1)).loadConfigurationFromFile();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining(CHANGE_IDENTIFIER);
+ .hasMessageContaining(CHANGE_IDENTIFIER);
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
@@ -262,10 +264,10 @@ class AppConfigTest {
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNextCount(0) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .verifyComplete();
assertTrue(logAppender.list.toString().contains("$CONSUL_HOST environment has not been defined"));
}
@@ -281,13 +283,13 @@ class AppConfigTest {
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNextCount(0) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .verifyComplete();
- assertTrue(logAppender.list.toString()
- .contains("Could not refresh application configuration java.io.IOException"));
+ assertTrue(
+ logAppender.list.toString().contains("Could not refresh application configuration java.io.IOException"));
}
@Test
@@ -301,10 +303,10 @@ class AppConfigTest {
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNext(appConfigUnderTest) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNext(appConfigUnderTest) //
+ .verifyComplete();
Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
}
@@ -321,10 +323,10 @@ class AppConfigTest {
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNext(appConfigUnderTest) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNext(appConfigUnderTest) //
+ .verifyComplete();
Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
}
@@ -348,8 +350,8 @@ class AppConfigTest {
private static InputStream getIncorrectJson() {
String string = "{" + //
- " \"configs\": {" + //
- " \"dmaap\": {"; //
+ " \"configs\": {" + //
+ " \"dmaap\": {"; //
return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8)));
}
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java
index eba88c33..7b03e00e 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java
@@ -44,7 +44,6 @@ import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
-
import reactor.test.StepVerifier;
public class SchedulerConfigTest {
@@ -53,7 +52,7 @@ public class SchedulerConfigTest {
private final TaskScheduler taskSchedulerMock = mock(TaskScheduler.class);
private final ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class);
private final SchedulerConfig schedulerUnderTest =
- spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
+ spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
@BeforeEach
public void setUp() {
@@ -72,8 +71,8 @@ public class SchedulerConfigTest {
String msg = "Datafile Service has already been stopped!";
StepVerifier.create(schedulerUnderTest.getResponseFromCancellationOfTasks())
- .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) //
- .verifyComplete();
+ .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) //
+ .verifyComplete();
verify(scheduledFutureMock).cancel(false);
verifyNoMoreInteractions(scheduledFutureMock);
@@ -88,7 +87,7 @@ public class SchedulerConfigTest {
SchedulerConfig.setScheduledFutureList(scheduledFutureList);
SchedulerConfig schedulerUnderTestSpy =
- spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
+ spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
boolean actualResult = schedulerUnderTestSpy.tryToStartTask();
@@ -96,10 +95,10 @@ public class SchedulerConfigTest {
ArgumentCaptor<Runnable> scheduleMainDatafileEventTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(taskSchedulerMock).scheduleWithFixedDelay(scheduleMainDatafileEventTaskCaptor.capture(),
- eq(Duration.ofSeconds(15)));
+ eq(Duration.ofSeconds(15)));
ArgumentCaptor<Runnable> purgeCachedInformationCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(taskSchedulerMock).scheduleWithFixedDelay(purgeCachedInformationCaptor.capture(),
- eq(Duration.ofHours(1)));
+ eq(Duration.ofHours(1)));
verifyNoMoreInteractions(taskSchedulerMock);
scheduleMainDatafileEventTaskCaptor.getValue().run();
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java
index 51097f52..a80999ed 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java
@@ -26,10 +26,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.controllers.StatusController;
@@ -63,7 +63,6 @@ public class StatusControllerTest {
assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID)));
}
-
@Test
public void status() {
ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class);
@@ -83,7 +82,6 @@ public class StatusControllerTest {
assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID)));
}
-
private void validateLogging(ListAppender<ILoggingEvent> logAppender) {
assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY");
assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("InvocationID"));
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
index f4e814f4..a747701a 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java
@@ -32,8 +32,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
+
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
+
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPSClient;
import org.junit.jupiter.api.BeforeEach;
@@ -205,8 +207,7 @@ public class FtpsClientTest {
doReturn(false).when(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, outputStreamMock);
assertThatThrownBy(() -> clientUnderTestSpy.collectFile(REMOTE_FILE_PATH, LOCAL_FILE_PATH))
- .hasMessageContaining(REMOTE_FILE_PATH)
- .hasMessageContaining("No retry");
+ .hasMessageContaining(REMOTE_FILE_PATH).hasMessageContaining("No retry");
verifyFtpsClientMock_openOk();
verify(ftpsClientMock, times(1)).retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH), any());
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java
index 693806c2..74d9ecd1 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java
@@ -31,9 +31,11 @@ import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
+
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Optional;
+
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -58,13 +60,13 @@ public class SftpClientTest {
@Test
public void openWithPort_success()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@@ -87,13 +89,13 @@ public class SftpClientTest {
@Test
public void openWithoutPort_success()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(Optional.empty()) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(Optional.empty()) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@@ -108,13 +110,13 @@ public class SftpClientTest {
@Test
public void open_throwsException()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@@ -128,11 +130,11 @@ public class SftpClientTest {
@Test
public void collectFile_succes() throws DatafileTaskException, SftpException {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClient = new SftpClient(expectedFileServerData);
sftpClient.sftpChannel = channelMock;
@@ -145,24 +147,24 @@ public class SftpClientTest {
@Test
public void collectFile_throwsExceptionWithoutRetry()
- throws IOException, JSchException, SftpException, DatafileTaskException {
+ throws IOException, JSchException, SftpException, DatafileTaskException {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) {
sftpClient.sftpChannel = channelMock;
doThrow(new SftpException(ChannelSftp.SSH_FX_NO_SUCH_FILE, "Failed")).when(channelMock).get(anyString(),
- anyString());
+ anyString());
assertThatThrownBy(() -> sftpClient.collectFile("remoteFile", Paths.get("localFile")))
- .isInstanceOf(DatafileTaskException.class)
- .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done")
- .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME
- + ", password=####, port=" + SFTP_PORT);
+ .isInstanceOf(DatafileTaskException.class)
+ .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done")
+ .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME
+ + ", password=####, port=" + SFTP_PORT);
}
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java
index 79666f72..35894f9c 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java
@@ -36,56 +36,55 @@ public class FileDataTest {
private static final String SERVER_ADDRESS = "192.168.0.101";
private static final int PORT_22 = 22;
private static final String LOCATION_WITH_USER =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String LOCATION_WITHOUT_USER =
- FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
-
+ FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private MessageMetaData messageMetaData() {
return ImmutableMessageMetaData.builder() //
- .productName("PRODUCT_NAME") //
- .vendorName("VENDOR_NAME") //
- .lastEpochMicrosec("LAST_EPOCH_MICROSEC") //
- .sourceName("SOURCE_NAME") //
- .startEpochMicrosec("START_EPOCH_MICROSEC") //
- .timeZoneOffset("TIME_ZONE_OFFSET") //
- .changeIdentifier("PM_MEAS_CHANGE_IDENTIFIER") //
- .changeType("FILE_READY_CHANGE_TYPE") //
- .build();
+ .productName("PRODUCT_NAME") //
+ .vendorName("VENDOR_NAME") //
+ .lastEpochMicrosec("LAST_EPOCH_MICROSEC") //
+ .sourceName("SOURCE_NAME") //
+ .startEpochMicrosec("START_EPOCH_MICROSEC") //
+ .timeZoneOffset("TIME_ZONE_OFFSET") //
+ .changeIdentifier("PM_MEAS_CHANGE_IDENTIFIER") //
+ .changeType("FILE_READY_CHANGE_TYPE") //
+ .build();
}
private FileData properFileDataWithUser() {
return ImmutableFileData.builder() //
- .name("name") //
- .location(LOCATION_WITH_USER) //
- .compression("comp") //
- .fileFormatType("type") //
- .fileFormatVersion("version") //
- .scheme(Scheme.FTPS) //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name("name") //
+ .location(LOCATION_WITH_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
private FileData properFileDataWithoutUser() {
return ImmutableFileData.builder() //
- .name("name") //
- .location(LOCATION_WITHOUT_USER) //
- .compression("comp") //
- .fileFormatType("type") //
- .fileFormatVersion("version") //
- .scheme(Scheme.FTPS) //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name("name") //
+ .location(LOCATION_WITHOUT_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
@Test
public void fileServerData_properLocationWithUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .port(PORT_22) //
- .userId(USER) //
- .password(PWD) //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId(USER) //
+ .password(PWD) //
+ .build();
FileServerData actualFileServerData = properFileDataWithUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@@ -94,11 +93,11 @@ public class FileDataTest {
@Test
public void fileServerData_properLocationWithoutUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .port(PORT_22) //
- .userId("") //
- .password("") //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId("") //
+ .password("") //
+ .build();
FileServerData actualFileServerData = properFileDataWithoutUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@@ -114,12 +113,11 @@ public class FileDataTest {
@Test
public void fileServerData_properLocationWithoutPort() {
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .userId("") //
- .password("") //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .userId("") //
+ .password("") //
+ .build();
assertFalse(fileServerData.port().isPresent());
}
}
-
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java
index b7eddaa7..2e3245a4 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java
@@ -23,12 +23,15 @@ import static org.mockito.Mockito.spy;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
@@ -41,6 +44,7 @@ import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -73,468 +77,468 @@ class JsonMessageParserTest {
@Test
void whenPassingCorrectJson_oneFileReadyMessage() throws URISyntaxException {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithTwoEvents_twoMessages() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String parsedString = message.getParsed();
String messageString = "[" + parsedString + "," + parsedString + "]";
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithoutLocation_noMessage() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue(logAppender.list.toString()
- .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location."));
+ .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location."));
assertTrue(logAppender.list.get(0).toString().contains("sourceName=5GRAN_DU"));
}
@Test
void whenPassingCorrectJsonWrongScheme_noMessage() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location("http://location.xml") //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location("http://location.xml") //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http"
- + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE + ". Location: http://location.xml"));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http" + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE
+ + ". Location: http://location.xml"));
assertTrue("Missing sourceName in log", logAppender.list.toString().contains("sourceName=5GRAN_DU"));
}
@Test
void whenPassingCorrectJsonWithTwoEventsFirstNoHeader_oneFileDatan() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String parsedString = message.getParsed();
String messageString = "[{\"event\":{}}," + parsedString + "]";
JsonMessageParser jsonMessageParserUnderTest = new JsonMessageParser();
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithFaultyEventName_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName("Faulty event name") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName("Faulty event name") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectComplete().verify();
+ .expectSubscription().expectComplete().verify();
- assertTrue("Error missing in log", logAppender.list.toString().contains(ERROR_LOG_TAG
- + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ assertTrue("Error missing in log",
+ logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ "Can not get PRODUCT_NAME from eventName, eventName is not in correct format: Faulty event name"));
}
@Test
void whenPassingCorrectJsonWithoutName_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [name] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [name] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingCorrectJsonWithoutAdditionalFields_noFileData() {
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "Missing arrayOfNamedHashMap in message. " + message.getParsed()));
+ logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "Missing arrayOfNamedHashMap in message. " + message.getParsed()));
}
@Test
void whenPassingCorrectJsonWithoutCompression_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [compression] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [compression] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingCorrectJsonWithoutFileFormatType_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [fileFormatType] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [fileFormatType] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingOneCorrectJsonWithoutFileFormatVersionAndOneCorrect_oneFileData() {
AdditionalField additionalFaultyField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .build();
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalFaultyField) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalFaultyField) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingJsonWithoutMandatoryHeaderInformation_noFileData() {
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .build();
String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(incorrectMessageString)))
- .expectSubscription().expectComplete().verify();
+ .expectSubscription().expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. "
- + "Change type is wrong: Expected: FileReady Message: " + message.getParsed()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. "
+ + "Change type is wrong: Expected: FileReady Message: " + message.getParsed()));
}
@Test
@@ -543,47 +547,46 @@ class JsonMessageParserTest {
JsonElement jsonElement = new JsonParser().parse("{}");
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just("[{}]"))).expectSubscription()
- .expectComplete().verify();
+ .expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. "));
+ logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. "));
}
@Test
void whenPassingCorrectJsonWithIncorrectChangeType_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(INCORRECT_CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(INCORRECT_CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).expectComplete().verify();
+ .expectSubscription().expectNextCount(0).expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + " Change type is wrong: " + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: "
- + message.getParsed()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + " Change type is wrong: "
+ + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: " + message.getParsed()));
}
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java
index 64cfb38f..9960dfdd 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java
@@ -19,6 +19,7 @@ package org.onap.dcaegen2.collectors.datafile.service;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
index a71521cd..d4541efb 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
@@ -71,7 +71,6 @@ class DmaapProducerHttpClientTest {
private static final Map<String, String> CONTEXT_MAP = new HashMap<>();
-
private DmaapProducerHttpClient producerClientUnderTestSpy;
private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
@@ -167,7 +166,7 @@ class DmaapProducerHttpClientTest {
when(futureMock.get()).thenThrow(new InterruptedException("Interrupted"));
producerClientUnderTestSpy.getDmaapProducerResponseWithCustomTimeout(request, TWO_SECOND_TIMEOUT,
- CONTEXT_MAP);
+ CONTEXT_MAP);
fail("Should have got an exception.");
} catch (DatafileTaskException e) {
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java
index 574ad18e..1bea290f 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java
@@ -96,94 +96,94 @@ public class DMaaPMessageConsumerTest {
@BeforeAll
public static void setUp() {
AdditionalField ftpesAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(FTPES_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(FTPES_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .notificationFieldsVersion("1.0") //
- .addAdditionalField(ftpesAdditionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .notificationFieldsVersion("1.0") //
+ .addAdditionalField(ftpesAdditionalField) //
+ .build();
ftpesMessageString = ftpesJsonMessage.toString();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .build();
ftpesFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(FTPES_LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(FTPES_LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(ftpesFileData);
expectedFtpesMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
AdditionalField sftpAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(SFTP_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(SFTP_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .notificationFieldsVersion("1.0") //
- .addAdditionalField(sftpAdditionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .notificationFieldsVersion("1.0") //
+ .addAdditionalField(sftpAdditionalField) //
+ .build();
sftpMessageString = sftpJsonMessage.toString();
sftpFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(SFTP_LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(SFTP_LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
ImmutableFilePublishInformation filePublishInformation = ImmutableFilePublishInformation.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .name(PM_FILE_NAME) //
- .location(FTPES_LOCATION) //
- .internalLocation(LOCAL_FILE_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .context(new HashMap<String,String>()) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .name(PM_FILE_NAME) //
+ .location(FTPES_LOCATION) //
+ .internalLocation(LOCAL_FILE_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .context(new HashMap<String, String>()) //
+ .build();
listOfFilePublishInformation.add(filePublishInformation);
files = new ArrayList<>();
files.add(sftpFileData);
expectedSftpMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
}
@Test
@@ -191,9 +191,9 @@ public class DMaaPMessageConsumerTest {
prepareMocksForDmaapConsumer("", null);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectSubscription() //
- .expectError(DatafileTaskException.class) //
- .verify();
+ .expectSubscription() //
+ .expectError(DatafileTaskException.class) //
+ .verify();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
}
@@ -203,8 +203,8 @@ public class DMaaPMessageConsumerTest {
prepareMocksForDmaapConsumer(ftpesMessageString, expectedFtpesMessage);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectNext(expectedFtpesMessage) //
- .verifyComplete();
+ .expectNext(expectedFtpesMessage) //
+ .verifyComplete();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
verifyNoMoreInteractions(httpClientMock);
@@ -215,8 +215,8 @@ public class DMaaPMessageConsumerTest {
prepareMocksForDmaapConsumer(sftpMessageString, expectedSftpMessage);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectNext(expectedSftpMessage) //
- .verifyComplete();
+ .expectNext(expectedSftpMessage) //
+ .verifyComplete();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
verifyNoMoreInteractions(httpClientMock);
@@ -230,10 +230,10 @@ public class DMaaPMessageConsumerTest {
if (!message.isEmpty()) {
when(jsonMessageParserMock.getMessagesFromJson(messageAsMono))
- .thenReturn(Flux.just(fileReadyMessageAfterConsume));
+ .thenReturn(Flux.just(fileReadyMessageAfterConsume));
} else {
when(jsonMessageParserMock.getMessagesFromJson(messageAsMono))
- .thenReturn(Flux.error(new DatafileTaskException("problemas")));
+ .thenReturn(Flux.error(new DatafileTaskException("problemas")));
}
messageConsumer = spy(new DMaaPMessageConsumer(httpClientMock, jsonMessageParserMock));
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java
index 6a9dccda..a585bf9c 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java
@@ -27,10 +27,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import java.io.File;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
+import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
@@ -97,28 +98,28 @@ class DataRouterPublisherTest {
// "https://54.45.333.2:1234/publish/1";
private static final String PUBLISH_URL =
- HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID;
+ HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID;
@BeforeAll
public static void setUp() {
when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL);
filePublishInformation = ImmutableFilePublishInformation.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .name(PM_FILE_NAME) //
- .location(FTPES_ADDRESS) //
- .internalLocation(Paths.get("target/" + PM_FILE_NAME)) //
- .compression("gzip") //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .context(context) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build(); //
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .name(PM_FILE_NAME) //
+ .location(FTPES_ADDRESS) //
+ .internalLocation(Paths.get("target/" + PM_FILE_NAME)) //
+ .compression("gzip") //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .context(context) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build(); //
appConfig = mock(AppConfig.class);
publisherTaskUnderTestSpy = spy(new DataRouterPublisher(appConfig, new Counters()));
}
@@ -127,9 +128,9 @@ class DataRouterPublisherTest {
public void whenPassedObjectFits_ReturnsCorrectStatus() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.OK.value()));
StepVerifier //
- .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
ArgumentCaptor<HttpUriRequest> requestCaptor = ArgumentCaptor.forClass(HttpUriRequest.class);
verify(httpClientMock).addUserCredentialsToHead(any(HttpUriRequest.class));
@@ -176,22 +177,22 @@ class DataRouterPublisherTest {
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class);
StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 2, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
- assertTrue("Warning missing in log", logAppender.list.toString()
- .contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful."));
+ assertTrue("Warning missing in log",
+ logAppender.list.toString().contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful."));
}
@Test
public void whenPassedObjectFits_firstFailsThenSucceeds() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()),
- Integer.valueOf(HttpStatus.OK.value()));
+ Integer.valueOf(HttpStatus.OK.value()));
StepVerifier //
- .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class));
verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any());
@@ -201,15 +202,15 @@ class DataRouterPublisherTest {
@Test
public void whenPassedObjectFits_firstFailsThenFails() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()),
- Integer.valueOf((HttpStatus.BAD_GATEWAY.value())));
+ Integer.valueOf((HttpStatus.BAD_GATEWAY.value())));
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class);
StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectErrorMessage("Retries exhausted: 1/1") //
- .verify();
+ .expectErrorMessage("Retries exhausted: 1/1") //
+ .verify();
assertTrue("Warning missing in log", logAppender.list.toString().contains("[WARN] Publishing file "
- + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY));
+ + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY));
verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class));
verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any());
@@ -218,7 +219,7 @@ class DataRouterPublisherTest {
@SafeVarargs
final void prepareMocksForTests(Exception exception, Integer firstResponse, Integer... nextHttpResponses)
- throws Exception {
+ throws Exception {
httpClientMock = mock(DmaapProducerHttpClient.class);
when(appConfig.getPublisherConfiguration(CHANGE_IDENTIFIER)).thenReturn(publisherConfigurationMock);
doReturn(publisherConfigurationMock).when(publisherTaskUnderTestSpy).resolveConfiguration(CHANGE_IDENTIFIER);
@@ -227,10 +228,10 @@ class DataRouterPublisherTest {
HttpResponse httpResponseMock = mock(HttpResponse.class);
if (exception == null) {
when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()))
- .thenReturn(httpResponseMock);
+ .thenReturn(httpResponseMock);
} else {
when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()))
- .thenThrow(exception).thenReturn(httpResponseMock);
+ .thenThrow(exception).thenReturn(httpResponseMock);
}
StatusLine statusLineMock = mock(StatusLine.class);
when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java
index 99e92bd2..1a3b2055 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java
@@ -48,7 +48,6 @@ import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
-
import reactor.test.StepVerifier;
public class FileCollectorTest {
@@ -70,10 +69,10 @@ public class FileCollectorTest {
private static final String USER = "usr";
private static final String PWD = "pwd";
private static final String FTPES_LOCATION =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String FTPES_LOCATION_NO_PORT =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
private static final String SFTP_LOCATION = SFTP_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String SFTP_LOCATION_NO_PORT = SFTP_SCHEME + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
@@ -99,46 +98,46 @@ public class FileCollectorTest {
private MessageMetaData createMessageMetaData() {
return ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .build();
}
private FileData createFileData(String location, Scheme scheme) {
return ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(location) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .scheme(scheme) //
- .messageMetaData(createMessageMetaData()) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(location) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .scheme(scheme) //
+ .messageMetaData(createMessageMetaData()) //
+ .build();
}
private FilePublishInformation createExpectedFilePublishInformation(String location) {
return ImmutableFilePublishInformation.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .name(PM_FILE_NAME) //
- .location(location) //
- .internalLocation(LOCAL_FILE_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .context(new HashMap<String, String>()) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .name(PM_FILE_NAME) //
+ .location(location) //
+ .internalLocation(LOCAL_FILE_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .context(new HashMap<String, String>()) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build();
}
/**
@@ -161,11 +160,11 @@ public class FileCollectorTest {
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(1)).open();
verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
@@ -179,22 +178,21 @@ public class FileCollectorTest {
FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters));
doReturn(sftpClientMock).when(collectorUndetTest).createSftpClient(any());
-
FileData fileData = createFileData(SFTP_LOCATION_NO_PORT, Scheme.SFTP);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
// The same again, but with port
fileData = createFileData(SFTP_LOCATION, Scheme.SFTP);
expectedfilePublishInformation = createExpectedFilePublishInformation(SFTP_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(sftpClientMock, times(2)).open();
verify(sftpClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
@@ -209,11 +207,11 @@ public class FileCollectorTest {
FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS);
doThrow(new DatafileTaskException("Unable to collect file.")).when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectErrorMessage("Retries exhausted: 3/3") //
- .verify();
+ .expectErrorMessage("Retries exhausted: 3/3") //
+ .verify();
verify(ftpsClientMock, times(4)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
@@ -225,11 +223,11 @@ public class FileCollectorTest {
FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS);
doThrow(new NonRetryableDatafileTaskException("Unable to collect file.")).when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectErrorMessage("Non retryable file transfer failure") //
- .verify();
+ .expectErrorMessage("Non retryable file transfer failure") //
+ .verify();
verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
@@ -239,16 +237,16 @@ public class FileCollectorTest {
FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters));
doReturn(ftpsClientMock).when(collectorUndetTest).createFtpsClient(any());
doThrow(new DatafileTaskException("Unable to collect file.")).doNothing().when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java
index 52640140..3a387e28 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java
@@ -36,6 +36,7 @@ import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
@@ -67,7 +68,6 @@ public class PublishedCheckerTest {
private PublishedChecker publishedCheckerUnderTestSpy;
-
@BeforeAll
private static void setUp() throws DatafileTaskException {
when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL);
@@ -81,7 +81,7 @@ public class PublishedCheckerTest {
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
@@ -103,7 +103,7 @@ public class PublishedCheckerTest {
prepareMocksForTests(HttpUtils.SC_BAD_REQUEST, EMPTY_CONTENT, null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
}
@@ -113,7 +113,7 @@ public class PublishedCheckerTest {
prepareMocksForTests(HttpUtils.SC_OK, "[" + LOCAL_FILE_NAME + "]", null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertTrue(isPublished);
}
@@ -123,7 +123,7 @@ public class PublishedCheckerTest {
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, new DatafileTaskException(""));
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
}
@@ -138,10 +138,10 @@ public class PublishedCheckerTest {
HttpResponse httpResponseMock = mock(HttpResponse.class);
if (exception == null) {
when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any()))
- .thenReturn(httpResponseMock);
+ .thenReturn(httpResponseMock);
} else {
when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any()))
- .thenThrow(exception);
+ .thenThrow(exception);
}
HttpEntity httpEntityMock = mock(HttpEntity.class);
StatusLine statusLineMock = mock(StatusLine.class);
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java
index 3df2edae..edbf5880 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java
@@ -37,6 +37,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
@@ -44,6 +45,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -65,6 +67,7 @@ import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables;
import org.slf4j.MDC;
+
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -103,24 +106,24 @@ public class ScheduledTasksTest {
private void setUpConfiguration() throws DatafileTaskException {
final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() //
- .publishUrl(publishUrl) //
- .logUrl("") //
- .userName("userName") //
- .passWord("passWord") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build(); //
+ .publishUrl(publishUrl) //
+ .logUrl("") //
+ .userName("userName") //
+ .passWord("passWord") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build(); //
final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() //
- .topicUrl("topicUrl").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ .topicUrl("topicUrl").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER);
doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration();
@@ -129,27 +132,27 @@ public class ScheduledTasksTest {
private MessageMetaData messageMetaData() {
return ImmutableMessageMetaData.builder() //
- .productName("productName") //
- .vendorName("") //
- .lastEpochMicrosec("") //
- .sourceName("") //
- .startEpochMicrosec("") //
- .timeZoneOffset("") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType("") //
- .build();
+ .productName("productName") //
+ .vendorName("") //
+ .lastEpochMicrosec("") //
+ .sourceName("") //
+ .startEpochMicrosec("") //
+ .timeZoneOffset("") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType("") //
+ .build();
}
private FileData fileData(int instanceNumber) {
return ImmutableFileData.builder() //
- .name(PM_FILE_NAME + instanceNumber) //
- .fileFormatType("") //
- .fileFormatVersion("") //
- .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) //
- .scheme(Scheme.FTPS) //
- .compression("") //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name(PM_FILE_NAME + instanceNumber) //
+ .fileFormatType("") //
+ .fileFormatVersion("") //
+ .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) //
+ .scheme(Scheme.FTPS) //
+ .compression("") //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
private List<FileData> files(int size, boolean uniqueNames) {
@@ -177,21 +180,21 @@ public class ScheduledTasksTest {
private FilePublishInformation filePublishInformation() {
return ImmutableFilePublishInformation //
- .builder() //
- .productName("") //
- .vendorName("") //
- .lastEpochMicrosec("") //
- .sourceName("") //
- .startEpochMicrosec("") //
- .timeZoneOffset("") //
- .name("") //
- .location("") //
- .internalLocation(Paths.get("internalLocation")) //
- .compression("") //
- .fileFormatType("") //
- .fileFormatVersion("") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .context(new HashMap<String, String>()).build();
+ .builder() //
+ .productName("") //
+ .vendorName("") //
+ .lastEpochMicrosec("") //
+ .sourceName("") //
+ .startEpochMicrosec("") //
+ .timeZoneOffset("") //
+ .name("") //
+ .location("") //
+ .internalLocation(Paths.get("internalLocation")) //
+ .compression("") //
+ .fileFormatType("") //
+ .fileFormatVersion("") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .context(new HashMap<String, String>()).build();
}
@Test
@@ -256,24 +259,24 @@ public class ScheduledTasksTest {
@Test
public void executeDatafileMainTask_unconfiguredChangeIdentifier() throws DatafileTaskException {
final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() //
- .publishUrl(publishUrl) //
- .logUrl("") //
- .userName("userName") //
- .passWord("passWord") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier("Different changeIdentifier") //
- .build(); //
+ .publishUrl(publishUrl) //
+ .logUrl("") //
+ .userName("userName") //
+ .passWord("passWord") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier("Different changeIdentifier") //
+ .build(); //
final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() //
- .topicUrl("topicUrl").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ .topicUrl("topicUrl").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER);
doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration();
@@ -290,7 +293,7 @@ public class ScheduledTasksTest {
await().untilAsserted(() -> assertEquals(0, testedObject.getCurrentNumberOfSubscriptions()));
assertTrue("Error missing in log", logAppender.list.toString().contains(
- "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1"));
+ "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1"));
}
@Test
@@ -300,14 +303,14 @@ public class ScheduledTasksTest {
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class);
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(0) //
- .expectComplete() //
- .verify(); //
-
- assertTrue("Error missing in log", logAppender.list.toString().contains(
- "[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed"));
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .expectComplete() //
+ .verify(); //
+
+ assertTrue("Error missing in log", logAppender.list.toString()
+ .contains("[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed"));
}
@Test
@@ -328,11 +331,11 @@ public class ScheduledTasksTest {
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(noOfFiles) //
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(noOfFiles) //
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
assertEquals(0, testedObject.getThreadPoolQueueSize());
@@ -358,18 +361,18 @@ public class ScheduledTasksTest {
// First file collect will fail, 3 will succeed
doReturn(error, collectedFile, collectedFile, collectedFile) //
- .when(fileCollectorMock) //
- .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull());
+ .when(fileCollectorMock) //
+ .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull());
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(3) //
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(3) //
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
verify(consumerMock, times(1)).getMessageRouterResponse();
@@ -395,16 +398,16 @@ public class ScheduledTasksTest {
Mono<Object> error = Mono.error(new Exception("problem"));
// One publish will fail, the rest will succeed
doReturn(collectedFile, error, collectedFile, collectedFile) //
- .when(dataRouterMock) //
- .publishFile(notNull(), anyLong(), notNull());
+ .when(dataRouterMock) //
+ .publishFile(notNull(), anyLong(), notNull());
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class);
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(3) // 3 completed files
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(3) // 3 completed files
+ .expectComplete() //
+ .verify(); //
assertTrue("Error missing in log", logAppender.list.toString().contains("[ERROR] File publishing failed: "));
@@ -435,10 +438,10 @@ public class ScheduledTasksTest {
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)).expectSubscription() //
- .expectNextCount(1) // 99 is skipped
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)).expectSubscription() //
+ .expectNextCount(1) // 99 is skipped
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
verify(consumerMock, times(1)).getMessageRouterResponse();
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
index 2402e8bf..7c2706d0 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
@@ -65,39 +65,39 @@ public class JsonMessage {
additionalFieldsString.append("]");
}
return "{" //
- + "\"event\":" //
- + "{" //
- + "\"commonEventHeader\":" //
- + "{" //
- + "\"domain\":\"notification\"," //
- + "\"eventId\":\"<<SerialNumber>>-reg\"," //
- + "\"eventName\":\"" + eventName + "\"," //
- + "\"eventType\":\"fileReady\"," //
- + "\"internalHeaderFields\":{}," //
- + "\"lastEpochMicrosec\":1519837825682," //
- + "\"nfNamingCode\":\"5GRAN\"," //
- + "\"nfcNamingCode\":\"5DU\"," //
- + "\"priority\":\"Normal\"," //
- + "\"reportingEntityName\":\"5GRAN_DU\"," //
- + "\"sequence\":0," //
- + "\"sourceId\":\"<<SerialNumber>>\"," //
- + "\"sourceName\":\"5GRAN_DU\"," //
- + "\"timeZoneOffset\":\"UTC+05:00\"," //
- + "\"startEpochMicrosec\":\"1519837825682\"," //
- + "\"version\":3" //
- + "}," //
- + "\"notificationFields\":" //
- + "{" //
- + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier,
- changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
- + getAsStringIfParameterIsSet("changeType", changeType,
- notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
- + getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion,
- arrayOfAdditionalFields.size() > 0)
- + additionalFieldsString.toString() //
- + "}" //
- + "}" //
- + "}";
+ + "\"event\":" //
+ + "{" //
+ + "\"commonEventHeader\":" //
+ + "{" //
+ + "\"domain\":\"notification\"," //
+ + "\"eventId\":\"<<SerialNumber>>-reg\"," //
+ + "\"eventName\":\"" + eventName + "\"," //
+ + "\"eventType\":\"fileReady\"," //
+ + "\"internalHeaderFields\":{}," //
+ + "\"lastEpochMicrosec\":1519837825682," //
+ + "\"nfNamingCode\":\"5GRAN\"," //
+ + "\"nfcNamingCode\":\"5DU\"," //
+ + "\"priority\":\"Normal\"," //
+ + "\"reportingEntityName\":\"5GRAN_DU\"," //
+ + "\"sequence\":0," //
+ + "\"sourceId\":\"<<SerialNumber>>\"," //
+ + "\"sourceName\":\"5GRAN_DU\"," //
+ + "\"timeZoneOffset\":\"UTC+05:00\"," //
+ + "\"startEpochMicrosec\":\"1519837825682\"," //
+ + "\"version\":3" //
+ + "}," //
+ + "\"notificationFields\":" //
+ + "{" //
+ + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier,
+ changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ + getAsStringIfParameterIsSet("changeType", changeType,
+ notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ + getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion,
+ arrayOfAdditionalFields.size() > 0)
+ + additionalFieldsString.toString() //
+ + "}" //
+ + "}" //
+ + "}";
}
private JsonMessage(final JsonMessageBuilder builder) {
@@ -118,17 +118,17 @@ public class JsonMessage {
@Override
public String toString() {
return "{" //
- + getAsStringIfParameterIsSet("name", name, true) //
- + "\"hashMap\":" //
- + "{"
- + getAsStringIfParameterIsSet("location", location,
- compression != null || fileFormatType != null || fileFormatVersion != null)
- + getAsStringIfParameterIsSet("compression", compression,
- fileFormatType != null || fileFormatVersion != null)
- + getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null)
- + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) //
- + "}" //
- + "}";
+ + getAsStringIfParameterIsSet("name", name, true) //
+ + "\"hashMap\":" //
+ + "{"
+ + getAsStringIfParameterIsSet("location", location,
+ compression != null || fileFormatType != null || fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("compression", compression,
+ fileFormatType != null || fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null)
+ + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) //
+ + "}" //
+ + "}";
}
private AdditionalField(AdditionalFieldBuilder builder) {
@@ -216,7 +216,7 @@ public class JsonMessage {
}
private static String getAsStringIfParameterIsSet(String parameterName, String parameterValue,
- boolean withSeparator) {
+ boolean withSeparator) {
String result = "";
if (parameterValue != null) {
result = "\"" + parameterName + "\":\"" + parameterValue + "\"";
@@ -236,27 +236,27 @@ public class JsonMessage {
*/
public static void main(String[] args) {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name("A20161224.1030-1045.bin.gz") //
- .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
- .compression("gzip") //
- .fileFormatType("org.3GPP.32.435#measCollec") //
- .fileFormatVersion("V10") //
- .build();
+ .name("A20161224.1030-1045.bin.gz") //
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
+ .compression("gzip") //
+ .fileFormatType("org.3GPP.32.435#measCollec") //
+ .fileFormatVersion("V10") //
+ .build();
AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name("A20161224.1030-1045.bin.gz") //
- .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
- .compression("gzip") //
- .fileFormatType("org.3GPP.32.435#measCollec") //
- .fileFormatVersion("V10") //
- .build();
+ .name("A20161224.1030-1045.bin.gz") //
+ .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
+ .compression("gzip") //
+ .fileFormatType("org.3GPP.32.435#measCollec") //
+ .fileFormatVersion("V10") //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName("Noti_NrRadio-Ericsson_FileReady") //
- .changeIdentifier("PM_MEAS_FILES") //
- .changeType("FileReady") //
- .notificationFieldsVersion("2.0") //
- .addAdditionalField(additionalField) //
- .addAdditionalField(secondAdditionalField) //
- .build();
+ .eventName("Noti_NrRadio-Ericsson_FileReady") //
+ .changeIdentifier("PM_MEAS_FILES") //
+ .changeType("FileReady") //
+ .notificationFieldsVersion("2.0") //
+ .addAdditionalField(additionalField) //
+ .addAdditionalField(secondAdditionalField) //
+ .build();
System.out.println(message.toString());
}
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java
index 45edac79..604bba3e 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java
@@ -23,13 +23,14 @@ package org.onap.dcaegen2.collectors.datafile.utils;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import org.slf4j.LoggerFactory;
public class LoggingUtils {
/**
* Returns a ListAppender that contains all logging events. Call this method at the very beginning of the test
- * */
+ */
public static ListAppender<ILoggingEvent> getLogListAppender(Class<?> logClass) {
Logger logger = (Logger) LoggerFactory.getLogger(logClass);
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
index 6d3a98b7..d496aebc 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;