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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import com.fasterxml.jackson.databind.JsonNode;
14 import com.fasterxml.jackson.databind.ObjectMapper;
15 import java.io.IOException;
16 import java.nio.charset.StandardCharsets;
17 import java.nio.file.Files;
18 import java.nio.file.Paths;
20 import org.junit.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.rev211013.NotificationAlarmService;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
27 public class NotificationAlarmServiceSerializerTest extends AbstractTest {
30 public void serializeTest() throws IOException {
31 JsonStringConverter<NotificationAlarmService> converter =
32 new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
33 String json = Files.readString(Paths.get("src/test/resources/event_alarm_service.json"));
34 NotificationAlarmService notificationAlarmService = converter
35 .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationAlarmService.QNAME),
36 json, JSONCodecFactorySupplier.RFC7951);
37 NotificationAlarmServiceSerializer serializer = new NotificationAlarmServiceSerializer();
38 Map<String, Object> configs = Map.of(ConfigConstants.CONVERTER, converter);
39 serializer.configure(configs, false);
40 byte[] data = serializer.serialize("test", notificationAlarmService);
42 assertNotNull("Serialized data should not be null", data);
43 String expectedJson = Files.readString(Paths.get("src/test/resources/expected_event_alarm_service.json"));
44 // Minify the json string
45 expectedJson = new ObjectMapper().readValue(expectedJson, JsonNode.class).toString();
46 assertEquals("The event should be equals", expectedJson, new String(data, StandardCharsets.UTF_8));