X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=inline;f=ves-nf-oam-adopter%2Fves-nf-oam-adopter-snmp-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fo%2Fran%2Foam%2Fnf%2Foam%2Fadopter%2Fsnmp%2Fmanager%2FJsonUtils.java;fp=ves-nf-oam-adopter%2Fves-nf-oam-adopter-snmp-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fo%2Fran%2Foam%2Fnf%2Foam%2Fadopter%2Fsnmp%2Fmanager%2FJsonUtils.java;h=245c383b7c1a253f238cfc8be047e206f5bfec7e;hb=ac6434712cc8c877ec2cb61aa306e33dd89f482e;hp=0000000000000000000000000000000000000000;hpb=204d666f85db71b0cff4f8508350524dde492f08;p=oam%2Fnf-oam-adopter.git diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/JsonUtils.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/JsonUtils.java new file mode 100644 index 0000000..245c383 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-snmp-manager/src/test/java/org/o/ran/oam/nf/oam/adopter/snmp/manager/JsonUtils.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 AT&T Intellectual Property. 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 + * 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. + * ============LICENSE_END========================================================= + */ + +package org.o.ran.oam.nf.oam.adopter.snmp.manager; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import lombok.experimental.UtilityClass; +import org.apache.commons.io.IOUtils; + +@UtilityClass +final class JsonUtils { + private static final List WHITE_LIST = + Arrays.asList("eventId", "actualJO"); + private static final List WHITE_LIST_EPOCH = + Arrays.asList("eventId", "actualJO", "startEpochMicrosec", "lastEpochMicrosec"); + private static final String COMMON_EVENT_HEADER = "commonEventHeader"; + private static final String EVENT = "event"; + + static String readJson(final String url) throws IOException { + return IOUtils.toString(JsonUtils.class.getResourceAsStream(url), StandardCharsets.UTF_8); + } + + public static void compareResult(final String expected, final String actual) { + final JsonObject expectedJO = JsonParser.parseString(expected).getAsJsonObject(); + final JsonObject actualJO = JsonParser.parseString(actual).getAsJsonObject(); + removeCommonEventHeaderFields(expectedJO, actualJO, WHITE_LIST); + assertEquals(expectedJO, actualJO); + } + + private static void removeCommonEventHeaderFields(final JsonObject expectedJO, final JsonObject actualJO, + final List asList) { + asList.forEach(wipe -> { + expectedJO.get(EVENT).getAsJsonObject().getAsJsonObject(COMMON_EVENT_HEADER).remove(wipe); + actualJO.get(EVENT).getAsJsonObject().getAsJsonObject(COMMON_EVENT_HEADER).remove(wipe); + }); + } + + public static void compareResultSkipEpoch(final String expected, final String actual) { + final JsonObject expectedJO = JsonParser.parseString(expected).getAsJsonObject(); + final JsonObject actualJO = JsonParser.parseString(actual).getAsJsonObject(); + removeCommonEventHeaderFields(expectedJO, actualJO, WHITE_LIST_EPOCH); + assertEquals(expectedJO, actualJO); + } +}