diff options
author | emartin <ephraim.martin@est.tech> | 2019-03-13 18:09:21 +0000 |
---|---|---|
committer | emartin <ephraim.martin@est.tech> | 2019-03-13 18:09:21 +0000 |
commit | e8a1f80f07a618cb842d00b5263dde53d1f541c9 (patch) | |
tree | 99a69b1c523554c5a95ebed549324023cbeccfe0 /src/test/java/org/onap | |
parent | 88adbc830c24f309c19fc5874654cc1cfaebc600 (diff) |
Split typeC XML to multiple Type A
*Split TypeC MeasFile to multiple TypeA by MeasData
*Create new Event for each TypeA
Change-Id: I22eb22c663c8491f3cae5e39e583ee2660647743
Issue-ID: DCAEGEN2-1281
Signed-off-by: emartin <ephraim.martin@est.tech>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r-- | src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasSplitterTest.java | 96 |
1 files changed, 96 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)));
+ }
+ }
+}
|