aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-app-server/src/test')
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java117
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java43
2 files changed, 99 insertions, 61 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
index dc51343d..4aad5f45 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
@@ -16,21 +16,22 @@
package org.onap.dcaegen2.collectors.datafile.service;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-
import java.util.List;
import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -42,122 +43,150 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJson_validationNotThrowingAnException() throws DmaapNotFoundException {
- // given
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ 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();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
- String messageString = message.toString();
-
- String parsedString = message.getParsed();
-
FileData expectedFileData = ImmutableFileData.builder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").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();
- // when
+
+ String messageString = message.toString();
+ String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- List<FileData> listOfFileData = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
- // then
- Assertions.assertNotNull(listOfFileData);
- Assertions.assertEquals(expectedFileData, listOfFileData.get(0));
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(expectedFileData, fileDataResult.get(0));
}
@Test
- void whenPassingCorrectJsonWihoutLocation_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().compression("gzip")
+ void whenPassingCorrectJsonWihoutName_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .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();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
+ }
+
+ @Test
+ void whenPassingCorrectJsonWihoutLocation_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+ String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutCompression_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutCompression_noFileData() {
+ 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")
.fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatType_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutFileFormatType_noFileData() {
+ 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")
.fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatVersion_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingOneCorrectJsonWihoutFileFormatVersionAndOneCorrect_oneFileData() {
+ AdditionalField additionalFaultyField =
+ 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").build();
+ 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").build();
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
- .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalFaultyField)
+ .addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(1, fileDataResult.size());
}
- // Fixed temprarily
@Test
void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() {
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES_INVALID")
.changeType("FileReady_INVALID").notificationFieldsVersion("1.0_INVALID").build();
- String incorrectMessageString = message.toString();
+ String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
+
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
@@ -165,15 +194,15 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingJsonWithNullJsonElement_validationThrowingAnException() {
JsonMessage message = new JsonMessage.JsonMessageBuilder().build();
- String incorrectMessageString = message.toString();
+ String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
+
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
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 264a9945..14251406 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
@@ -2,17 +2,15 @@
* ============LICENSE_START======================================================================
* Copyright (C) 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
* ============LICENSE_END========================================================================
*/
@@ -42,12 +40,13 @@ public class JsonMessage {
/**
* Gets the message in parsed format.
+ *
* @return the massage in parsed format.
*/
public String getParsed() {
StringBuffer additionalFieldsString = new StringBuffer();
if (arrayOfAdditionalFields.size() > 0) {
- additionalFieldsString.append("\"arrayOfAdditionalFields\": [");
+ additionalFieldsString.append("\"arrayOfNamedHashMap\": [");
for (Iterator<AdditionalField> iterator = arrayOfAdditionalFields.iterator(); iterator.hasNext();) {
AdditionalField additionalField = iterator.next();
additionalFieldsString.append(additionalField.toString());
@@ -82,6 +81,7 @@ public class JsonMessage {
}
public static class AdditionalField {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
@@ -89,17 +89,19 @@ public class JsonMessage {
@Override
public String toString() {
- return "{"
+ 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("fileFormatVersion", fileFormatVersion, false) + "}}";
}
private AdditionalField(AdditionalFieldBuilder builder) {
+ this.name = builder.name;
this.location = builder.location;
this.compression = builder.compression;
this.fileFormatType = builder.fileFormatType;
@@ -109,11 +111,17 @@ public class JsonMessage {
}
public static class AdditionalFieldBuilder {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
private String fileFormatVersion;
+ public AdditionalFieldBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
public AdditionalFieldBuilder location(String location) {
this.location = location;
return this;
@@ -190,14 +198,15 @@ public class JsonMessage {
* @param args Not used
*/
public static void main(String[] args) {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ 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();
- AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder()
- .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();
+ 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();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
- .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField)
+ .changeType("FileReady").notificationFieldsVersion("2.0").addAdditionalField(additionalField)
.addAdditionalField(secondAdditionalField).build();
System.out.println(message.toString());
}