Fix YANG patch request for augmented element
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / test / AbstractBodyReaderTest.java
index 7d2fee7327d37da690763e6169fa0698eb2c0aba..f0c3889d714bf688872809aef0189f4462a89c6e 100644 (file)
@@ -15,7 +15,6 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import javax.ws.rs.core.MediaType;
@@ -29,21 +28,24 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public abstract class AbstractBodyReaderTest {
+    protected static final QName CONT_AUG_QNAME = QName.create("test-ns-aug", "container-aug").intern();
+    protected static final QName LEAF_AUG_QNAME = QName.create("test-ns-aug", "leaf-aug").intern();
+
     protected final MediaType mediaType;
     protected final SchemaContextHandler schemaContextHandler;
     protected final DOMMountPointService mountPointService;
@@ -55,7 +57,7 @@ public abstract class AbstractBodyReaderTest {
         schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
 
         mountPointService = mock(DOMMountPointService.class);
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+        final var mountPoint = mock(DOMMountPoint.class);
         doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
         doReturn(Optional.of(FixedDOMSchemaService.of(schemaContext))).when(mountPoint)
             .getService(DOMSchemaService.class);
@@ -69,14 +71,12 @@ public abstract class AbstractBodyReaderTest {
     }
 
     protected static <T extends AbstractIdentifierAwareJaxRsProvider<?>> void mockBodyReader(
-            final String identifier, final T normalizedNodeProvider,
-            final boolean isPost) throws NoSuchFieldException,
-            SecurityException, IllegalArgumentException, IllegalAccessException {
+            final String identifier, final T normalizedNodeProvider, final boolean isPost) {
         final UriInfo uriInfoMock = mock(UriInfo.class);
         final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
 
         if (!identifier.isEmpty()) {
-            pathParm.put(RestconfConstants.IDENTIFIER, Collections.singletonList(identifier));
+            pathParm.put("identifier", List.of(identifier));
         }
 
         when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
@@ -94,14 +94,12 @@ public abstract class AbstractBodyReaderTest {
         normalizedNodeProvider.setRequest(request);
     }
 
-    protected static void checkMountPointNormalizedNodeContext(
-            final NormalizedNodeContext nnContext) {
-        checkNormalizedNodeContext(nnContext);
+    protected static void checkMountPointNormalizedNodePayload(final NormalizedNodePayload nnContext) {
+        checkNormalizedNodePayload(nnContext);
         assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
     }
 
-    protected static void checkNormalizedNodeContext(
-            final NormalizedNodeContext nnContext) {
+    protected static void checkNormalizedNodePayload(final NormalizedNodePayload nnContext) {
         assertNotNull(nnContext.getData());
         assertNotNull(nnContext.getInstanceIdentifierContext()
                 .getInstanceIdentifier());
@@ -136,7 +134,7 @@ public abstract class AbstractBodyReaderTest {
         assertEquals(1, errors.size());
 
         final RestconfError error = errors.get(0);
-        assertEquals(ErrorType.PROTOCOL, error.getErrorType());
+        assertEquals(ErrorType.APPLICATION, error.getErrorType());
         assertEquals(ErrorTag.INVALID_VALUE, error.getErrorTag());
         assertEquals("bar error app tag", error.getErrorAppTag());
         assertEquals("bar error message", error.getErrorMessage());