Remove ObjectMapper from OpenApiServiceImplTest 28/106428/2
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Thu, 8 Jun 2023 13:12:01 +0000 (15:12 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 12 Jun 2023 08:09:14 +0000 (08:09 +0000)
There is no need to simulate JSON serialization. We can just
assert that fields have desired values.

Change-Id: I40109512feff449c1c9b64e7e9e9ec6ddad830cc
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/restconf-openapi/src/test/java/org/opendaylight/restconf/openapi/impl/OpenApiServiceImplTest.java

index 4e1eff7cbd7b6cf571039a7e52e899702325af83..75e8dc4b849c5aacfdb7b5568426b4d219fa5b39 100644 (file)
@@ -11,9 +11,8 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.List;
 import java.util.Optional;
-import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -22,6 +21,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.openapi.DocGenTestHelper;
 import org.opendaylight.restconf.openapi.api.OpenApiService;
+import org.opendaylight.restconf.openapi.model.MountPointInstance;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -33,7 +33,6 @@ public final class OpenApiServiceImplTest {
             .node(QName.create("", "nodes"))
             .node(QName.create("", "node"))
             .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
-    private static final ObjectMapper MAPPER = new ObjectMapper();
 
     private static EffectiveModelContext context;
     private static DOMSchemaService schemaService;
@@ -63,9 +62,10 @@ public final class OpenApiServiceImplTest {
 
     @Test
     public void getListOfMounts() throws Exception {
-        final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
-        // simulate the behavior of JacksonJaxbJsonProvider
-        final String result = MAPPER.writer().writeValueAsString(openApiService.getListOfMounts(mockInfo).getEntity());
-        assertEquals("[{\"instance\":\"/nodes/node=123/\",\"id\":1}]", result);
+        final var mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
+        final var entity = ((List<MountPointInstance>) openApiService.getListOfMounts(mockInfo).getEntity());
+        final var instance = entity.get(0);
+        assertEquals("/nodes/node=123/", instance.instance());
+        assertEquals(Long.valueOf(1), instance.id());
     }
 }