*/
package org.opendaylight.transportpce.nbinotifications.serialization;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.transportpce.common.converter.JsonStringConverter;
import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.NotificationService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
public class NotificationServiceSerializerTest extends AbstractTest {
@Test
- public void serializeTest() throws IOException {
- JsonStringConverter<NotificationService> converter =
+ void serializeTest() throws IOException {
+ JsonStringConverter<NotificationProcessService> converter =
new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
String json = Files.readString(Paths.get("src/test/resources/event.json"));
- NotificationService notificationService = converter
- .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationService.QNAME),
+ NotificationProcessService notificationService = converter
+ .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationProcessService.QNAME),
json, JSONCodecFactorySupplier.RFC7951);
NotificationServiceSerializer serializer = new NotificationServiceSerializer();
Map<String, Object> configs = Map.of(ConfigConstants.CONVERTER, converter);
serializer.configure(configs, false);
byte[] data = serializer.serialize("test", notificationService);
serializer.close();
- assertNotNull("Serialized data should not be null", data);
+ assertNotNull(data, "Serialized data should not be null");
String expectedJson = Files.readString(Paths.get("src/test/resources/expected_event.json"));
- assertEquals("The event should be equals", expectedJson, new String(data, StandardCharsets.UTF_8));
+ // Minify the json string
+ expectedJson = new ObjectMapper().readValue(expectedJson, JsonNode.class).toString();
+ assertEquals(expectedJson, new String(data, StandardCharsets.UTF_8), "The event should be equals");
}
}