2 * Copyright © 2021 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.nbinotifications.serialization;
10 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import com.fasterxml.jackson.databind.JsonNode;
13 import com.fasterxml.jackson.databind.ObjectMapper;
14 import java.io.IOException;
15 import java.nio.charset.StandardCharsets;
16 import java.nio.file.Files;
17 import java.nio.file.Paths;
19 import org.json.JSONException;
20 import org.junit.jupiter.api.Test;
21 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationAlarmService;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
26 import org.skyscreamer.jsonassert.JSONAssert;
28 public class NotificationAlarmServiceSerializerTest extends AbstractTest {
31 void serializeTest() throws IOException, JSONException {
32 JsonStringConverter<NotificationAlarmService> converter =
33 new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
34 String json = Files.readString(Paths.get("src/test/resources/event_alarm_service.json"));
35 NotificationAlarmService notificationAlarmService = converter
36 .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationAlarmService.QNAME),
37 json, JSONCodecFactorySupplier.RFC7951);
38 NotificationAlarmServiceSerializer serializer = new NotificationAlarmServiceSerializer();
39 Map<String, Object> configs = Map.of(ConfigConstants.CONVERTER, converter);
40 serializer.configure(configs, false);
41 byte[] data = serializer.serialize("test", notificationAlarmService);
43 assertNotNull(data, "Serialized data should not be null");
44 String expectedJson = Files.readString(Paths.get("src/test/resources/expected_event_alarm_service.json"));
45 // Minify the json string
46 expectedJson = new ObjectMapper().readValue(expectedJson, JsonNode.class).toString();
47 JSONAssert.assertEquals(expectedJson, new String(data, StandardCharsets.UTF_8), true);