summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoremartin <ephraim.martin@est.tech>2019-04-02 09:17:33 +0000
committeremartin <ephraim.martin@est.tech>2019-04-02 09:17:33 +0000
commit988fa778eb2415a7ae8f1b30df67ebc38eee4665 (patch)
tree51c562886d34e7f6ede400e4c538e597984c94e3 /src
parenta7da4421da0595dfadf6853f96b2d5f04ff35ec2 (diff)
Fix mapping issue with type C files
Change-Id: I698b84989dc928a09ff5e1c54adf236edd40b622 Issue-ID: DCAEGEN2-1038 Signed-off-by: emartin <ephraim.martin@est.tech>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/App.java2
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/mapping/Mapper.java8
-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
5 files changed, 28 insertions, 10 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
index 03d42d5..b411fd7 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/App.java
@@ -71,7 +71,7 @@ public class App {
MetadataFilter metadataFilter = new MetadataFilter(mapperConfig);
MeasConverter measConverter = new MeasConverter();
MeasFilterHandler filterHandler = new MeasFilterHandler(measConverter);
- Mapper mapper = new Mapper(mappingTemplate);
+ Mapper mapper = new Mapper(mappingTemplate, measConverter);
MeasSplitter splitter = new MeasSplitter(measConverter);
XMLValidator validator = new XMLValidator(xmlSchema);
VESPublisher vesPublisher = new VESPublisher(mapperConfig);
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/mapping/Mapper.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/mapping/Mapper.java
index 44bbc27..a9b7e86 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/mapping/Mapper.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/mapping/Mapper.java
@@ -28,6 +28,7 @@ import lombok.NonNull;
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.utils.MeasConverter;
import org.onap.logging.ref.slf4j.ONAPLogAdapter;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
@@ -49,9 +50,11 @@ import java.util.UUID;
public class Mapper {
private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(Mapper.class));
private Template mappingTemplate;
+ private MeasConverter converter;
- public Mapper(@NonNull Path pathToTemplate) {
+ public Mapper(@NonNull Path pathToTemplate, MeasConverter converter) {
logger.unwrap().trace("Constructing Mapper from {}", pathToTemplate);
+ this.converter = converter;
Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
configuration.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX);
try {
@@ -72,7 +75,8 @@ public class Mapper {
logger.unwrap().info("Mapping event");
NodeModel pmNodeModel;
try {
- pmNodeModel = NodeModel.parse(new InputSource(new StringReader(event.getBody())));
+ String measCollecFile = converter.convert(event.getMeasCollecFile());
+ pmNodeModel = NodeModel.parse(new InputSource(new StringReader(measCollecFile)));
} catch (IOException | SAXException | ParserConfigurationException exception) {
logger.unwrap().error("Failed to parse input as XML", exception);
throw new XMLParseException("Failed to parse input as XML", exception);
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;
}