summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorHenrik Andersson <henrik.b.andersson@est.tech>2019-04-02 12:21:37 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-02 12:21:37 +0000
commit03e519407ccc47e51efbbfb26cca339f90cbff1b (patch)
tree5e680b42c3e945b1af147c02eef9afb5795a8917 /src/test
parent36605ed860a6eb7fca09156c6e8ae6ebf5259ea3 (diff)
parent988fa778eb2415a7ae8f1b30df67ebc38eee4665 (diff)
Merge "Fix mapping issue with type C files"
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java6
-rw-r--r--src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java17
-rw-r--r--src/test/java/utils/EventUtils.java5
3 files changed, 21 insertions, 7 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java
index e82d90f..b4dc178 100644
--- a/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/AppTest.java
@@ -132,7 +132,8 @@ class AppTest {
public void testSplit_empty_success() {
Event mockEvent = Mockito.mock(Event.class);
MapperConfig mockConfig = Mockito.mock(MapperConfig.class);
- Flux<List<Event>> splitResult = App.split(new MeasSplitter(new MeasConverter()), mockEvent, mockConfig);
+ MeasConverter mockMeasConverter = Mockito.mock(MeasConverter.class);
+ Flux<List<Event>> splitResult = App.split(new MeasSplitter(mockMeasConverter), mockEvent, mockConfig);
splitResult.equals(Flux.<List<Event>>empty());
}
@@ -152,10 +153,11 @@ class AppTest {
@Test
public void testMapping_empty_success() {
Event mockEvent = Mockito.mock(Event.class);
+ MeasConverter mockMeasConverter = Mockito.mock(MeasConverter.class);
List<Event> mockEvents = Arrays.asList(mockEvent);
MapperConfig mockConfig = Mockito.mock(MapperConfig.class);
Path mappingTemplate = Paths.get("src/main/resources/mapping.ftl");
- Flux<List<Event>> mappingResult = App.map(new Mapper(mappingTemplate), mockEvents, mockConfig);
+ Flux<List<Event>> mappingResult = App.map(new Mapper(mappingTemplate,mockMeasConverter), mockEvents, mockConfig);
mappingResult.equals(Flux.<List<Event>>empty());
}
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java
index e7c8f3a..8670bed 100644
--- a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java
@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import com.google.gson.Gson;
import freemarker.core.Environment;
@@ -54,6 +55,8 @@ import org.onap.dcaegen2.services.pmmapper.exceptions.MappingException;
import org.onap.dcaegen2.services.pmmapper.exceptions.XMLParseException;
import org.onap.dcaegen2.services.pmmapper.model.Event;
import org.onap.dcaegen2.services.pmmapper.model.EventMetadata;
+import org.onap.dcaegen2.services.pmmapper.model.MeasCollecFile;
+import org.onap.dcaegen2.services.pmmapper.utils.MeasConverter;
import org.onap.logging.ref.slf4j.ONAPLogAdapter;
import org.powermock.reflect.Whitebox;
import utils.EventUtils;
@@ -64,6 +67,7 @@ class MapperTest {
private static EventMetadata eventMetadata;
private static Schema vesSchema;
+ private static MeasConverter converter;
private Mapper objUnderTest;
private static final Path schema = Paths.get("src/test/resources/mapper_test/CommonEventFormat_30.1-ONAP.json");
@@ -79,22 +83,25 @@ class MapperTest {
String metadataFileContents = new String(Files.readAllBytes(metadata));
eventMetadata = new Gson().fromJson(metadataFileContents, EventMetadata.class);
+ converter = mock(MeasConverter.class);
}
@BeforeEach
void setup() {
- objUnderTest = new Mapper(mapping);
+ objUnderTest = new Mapper(mapping,converter);
}
@ParameterizedTest
@MethodSource("getValidEvents")
void testValidEvent(Event testEvent) {
+ when(converter.convert(any(MeasCollecFile.class))).thenReturn(testEvent.getBody());
vesSchema.validate(new JSONObject(objUnderTest.map(testEvent)));
}
@ParameterizedTest
@MethodSource("getInvalidEvents")
void testInvalidEvent(Event testEvent) {
+ when(converter.convert(any(MeasCollecFile.class))).thenReturn(testEvent.getBody());
assertThrows(MappingException.class, () -> objUnderTest.map(testEvent));
}
@@ -112,18 +119,19 @@ class MapperTest {
@Test
void testFailureToParse() {
- assertThrows(XMLParseException.class, () ->
+ when(converter.convert(any(MeasCollecFile.class))).thenCallRealMethod();
+ assertThrows(MappingException.class, () ->
objUnderTest.map(EventUtils.makeMockEvent("not xml", eventMetadata)));
}
@Test
void testInvalidPath() {
- assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("not a path")));
+ assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("not a path"),converter));
}
@Test
void testNullPath() {
- assertThrows(NullPointerException.class, () -> new Mapper(null));
+ assertThrows(NullPointerException.class, () -> new Mapper(null,converter));
}
@Test
@@ -141,6 +149,7 @@ class MapperTest {
List<Event> events = getValidEvents();
List<Event> expectedEvents = objUnderTest.mapEvents(events);
expectedEvents.forEach(event->{
+ when(converter.convert(any(MeasCollecFile.class))).thenReturn(event.getBody());
assertTrue(event.getVes() != null);
});
}
diff --git a/src/test/java/utils/EventUtils.java b/src/test/java/utils/EventUtils.java
index a6b131c..eae050d 100644
--- a/src/test/java/utils/EventUtils.java
+++ b/src/test/java/utils/EventUtils.java
@@ -36,6 +36,7 @@ import java.util.stream.Stream;
import org.onap.dcaegen2.services.pmmapper.model.Event;
import org.onap.dcaegen2.services.pmmapper.model.EventMetadata;
+import org.onap.dcaegen2.services.pmmapper.model.MeasCollecFile;
public class EventUtils {
@@ -81,7 +82,9 @@ public class EventUtils {
* @return event with mock HttpServerExchange
*/
public static Event makeMockEvent(String body, EventMetadata eventMetadata) {
- return new Event(mock(HttpServerExchange.class, RETURNS_DEEP_STUBS), body, eventMetadata, new HashMap<>(), "");
+ Event event = new Event(mock(HttpServerExchange.class, RETURNS_DEEP_STUBS), body, eventMetadata, new HashMap<>(), "");
+ event.setMeasCollecFile(new MeasCollecFile());
+ return event;
}