summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorTony Hansen <tony@att.com>2019-03-13 20:40:21 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-13 20:40:21 +0000
commitf4e3a4319568de5bcadaaa2e9f5ed668ae80db80 (patch)
treeea82180e3ba7d73a4a662079c0926c9514156947 /src/test
parentccd0dc11d7ff162b14dfedd94d22efd86960e407 (diff)
parente8a1f80f07a618cb842d00b5263dde53d1f541c9 (diff)
Merge "Split typeC XML to multiple Type A"
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java96
-rw-r--r--src/test/resources/split_test/meas_results_typeA.xml23
-rw-r--r--src/test/resources/split_test/meas_results_typeC.xml49
3 files changed, 168 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java
new file mode 100644
index 0000000..962303c
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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
+ *
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcaegen2.services.pmmapper.utils;
+import static org.junit.Assert.assertEquals;
+
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+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 io.undertow.server.HttpServerExchange;
+import utils.EventUtils;
+
+@ExtendWith(MockitoExtension.class)
+public class MeasSplitterTest {
+ private static final String baseDir = "src/test/resources/split_test/";
+ private MeasSplitter objUnderTest;
+ private MeasConverter converter;
+ @Mock
+ HttpServerExchange exchange;
+ @Mock
+ EventMetadata meta;
+ @Mock
+ Event event;
+
+ @BeforeEach
+ public void setup() {
+ converter = new MeasConverter();
+ objUnderTest = new MeasSplitter(converter);
+ Mockito.when(event.getHttpServerExchange()).thenReturn(exchange);
+ Mockito.when(event.getMetadata()).thenReturn(meta);
+ Mockito.when(event.getMdc()).thenReturn(new HashMap<String, String>());
+ Mockito.when(event.getMetadata()).thenReturn(meta);
+ Mockito.when(event.getPublishIdentity()).thenReturn("");
+ }
+
+ @Test
+ public void typeA_returns_only_one_event() throws JAXBException {
+ String inputPath = baseDir + "meas_results_typeA";
+ String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml"));
+ MeasCollecFile measToBeSplit = converter.convert(inputXml);
+ Mockito.when(event.getBody()).thenReturn(inputXml);
+ Mockito.when(event.getMeasCollecFile()).thenReturn(measToBeSplit);
+
+ List<Event> splitEvents = objUnderTest.split(event);
+
+ assertEquals(1,splitEvents.size());
+ }
+
+ @Test
+ public void typeC_returns_multiple_events() throws JAXBException {
+ String inputPath = baseDir + "meas_results_typeC";
+ String inputXml = EventUtils.fileContentsToString(Paths.get(inputPath + ".xml"));
+ Mockito.when(event.getBody()).thenReturn(inputXml);
+ MeasCollecFile measToBeSplit = converter.convert(inputXml);
+ Mockito.when(event.getMeasCollecFile()).thenReturn(measToBeSplit);
+
+ List<Event> splitEvents = objUnderTest.split(event);
+
+ assertEquals(3,splitEvents.size());
+ for (int i = 0; i < splitEvents.size(); i++) {
+ String measInfoId = splitEvents.get(i).getMeasCollecFile()
+ .getMeasData().get(0).getMeasInfo().get(0).getMeasInfoId();
+ Assertions.assertTrue(measInfoId.equals("measInfoId"+(i+1)));
+ }
+ }
+}
diff --git a/src/test/resources/split_test/meas_results_typeA.xml b/src/test/resources/split_test/meas_results_typeA.xml
new file mode 100644
index 0000000..bc87b79
--- /dev/null
+++ b/src/test/resources/split_test/meas_results_typeA.xml
@@ -0,0 +1,23 @@
+<measCollecFile xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec">
+ <fileHeader dnPrefix="some dnPrefix" vendorName="FooBar Ltd"
+ fileFormatVersion="32.435 V10.0">
+ <fileSender localDn="Dublin"/>
+ <measCollec beginTime="2018-10-02T12:00:00+01:00"/>
+ </fileHeader>
+ <measData>
+ <managedElement swVersion="r0.1" localDn="Dublin"/>
+ <measInfo measInfoId="some measInfoId">
+ <job jobId="jobId"/>
+ <granPeriod endTime="2018-10-02T12:15:00Z" duration="PT900S"/>
+ <repPeriod duration="PT900S"/>
+ <measTypes>z a zz b</measTypes>
+ <measValue measObjLdn="objLdn">
+ <measResults>99 1 27 2</measResults>
+ <suspect>false</suspect>
+ </measValue>
+ </measInfo>
+ </measData>
+ <fileFooter>
+ <measCollec endTime="2018-10-02T12:15:00+01:00"/>
+ </fileFooter>
+</measCollecFile>
diff --git a/src/test/resources/split_test/meas_results_typeC.xml b/src/test/resources/split_test/meas_results_typeC.xml
new file mode 100644
index 0000000..b6a3b43
--- /dev/null
+++ b/src/test/resources/split_test/meas_results_typeC.xml
@@ -0,0 +1,49 @@
+<measCollecFile xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.435#measCollec">
+ <fileHeader dnPrefix="some dnPrefix" vendorName="FooBar Ltd"
+ fileFormatVersion="32.435 V10.0">
+ <fileSender localDn="Dublin"/>
+ <measCollec beginTime="2018-10-02T12:00:00+01:00"/>
+ </fileHeader>
+ <measData>
+ <managedElement swVersion="r0.1" localDn="Dublin1"/>
+ <measInfo measInfoId="measInfoId1">
+ <job jobId="jobId1"/>
+ <granPeriod endTime="2001-10-02T12:15:00Z" duration="PT100S"/>
+ <repPeriod duration="PT100S"/>
+ <measTypes>z1 a1 zz1 b1</measTypes>
+ <measValue measObjLdn="objLdn">
+ <measResults>1 11 111 1111</measResults>
+ <suspect>false</suspect>
+ </measValue>
+ </measInfo>
+ </measData>
+ <measData>
+ <managedElement swVersion="r0.2" localDn="Dublin2"/>
+ <measInfo measInfoId="measInfoId2">
+ <job jobId="jobId"/>
+ <granPeriod endTime="2002-10-02T12:15:00Z" duration="PT200S"/>
+ <repPeriod duration="PT200S"/>
+ <measTypes>z2 a2 zz2 b2</measTypes>
+ <measValue measObjLdn="objLdn">
+ <measResults>2 22 222 2222</measResults>
+ <suspect>false</suspect>
+ </measValue>
+ </measInfo>
+ </measData>
+ <measData>
+ <managedElement swVersion="r0.3" localDn="Dublin3"/>
+ <measInfo measInfoId="measInfoId3">
+ <job jobId="jobId"/>
+ <granPeriod endTime="2003-10-02T12:15:00Z" duration="PT300S"/>
+ <repPeriod duration="PT300S"/>
+ <measTypes>z3 a3 zz3 b3</measTypes>
+ <measValue measObjLdn="objLdn">
+ <measResults>3 33 333 3333</measResults>
+ <suspect>false</suspect>
+ </measValue>
+ </measInfo>
+ </measData>
+ <fileFooter>
+ <measCollec endTime="2018-10-02T12:15:00+01:00"/>
+ </fileFooter>
+</measCollecFile>