Bump versions to 4.0.0-SNAPSHOT
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / rest / impl / test / providers / TestXmlPatchBodyReaderMountPoint.java
index e4e7a10ed55285171aa88cd14510772df901d75f..614f36ed026c29a98586a3918854d0d89ff1d7c6 100644 (file)
@@ -5,67 +5,51 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.sal.rest.impl.test.providers;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.netconf.sal.rest.impl.XmlToPatchBodyReader;
-import org.opendaylight.netconf.sal.restconf.impl.PatchContext;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 
 public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
 
     private final XmlToPatchBodyReader xmlToPatchBodyReader;
-    private static SchemaContext schemaContext;
+    private static EffectiveModelContext schemaContext;
     private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount";
 
-    public TestXmlPatchBodyReaderMountPoint() throws NoSuchFieldException, SecurityException {
-        super();
-        xmlToPatchBodyReader = new XmlToPatchBodyReader();
-    }
-
-    @Override
-    protected MediaType getMediaType() {
-        return new MediaType(MediaType.APPLICATION_XML, null);
+    public TestXmlPatchBodyReaderMountPoint() {
+        super(schemaContext, mock(DOMMountPoint.class));
+        xmlToPatchBodyReader = new XmlToPatchBodyReader(controllerContext);
     }
 
     @BeforeClass
     public static void initialization() throws NoSuchFieldException, SecurityException {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+    }
 
-        final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
-        when(mockMountPoint.getSchemaContext()).thenReturn(schemaContext);
-        final DOMMountPointService mockMountPointService = mock(DOMMountPointService.class);
-        when(mockMountPointService.getMountPoint(any(YangInstanceIdentifier.class)))
-                .thenReturn(Optional.of(mockMountPoint));
-
-        CONTROLLER_CONTEXT.setMountService(mockMountPointService);
-        CONTROLLER_CONTEXT.setSchemas(schemaContext);
+    @Override
+    protected MediaType getMediaType() {
+        return new MediaType(MediaType.APPLICATION_XML, null);
     }
 
     @Test
     public void moduleDataTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdata.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     /**
@@ -75,14 +59,11 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataValueMissingNegativeTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -95,12 +76,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
         mockBodyReader(uri, xmlToPatchBodyReader, false);
         final InputStream inputStream = TestXmlBodyReader.class
                 .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-        try {
-            xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
-            fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
-        } catch (final RestconfDocumentedException e) {
-            assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
-        }
+        final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+            () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+        assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
     }
 
     /**
@@ -110,10 +88,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataAbsoluteTargetPathTest() throws Exception {
         final String uri = MOUNT_POINT;
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContextMountPoint(returnValue);
     }
 
@@ -124,10 +101,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void modulePatchCompleteTargetInURITest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
+        final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
         checkPatchContextMountPoint(returnValue);
     }
 
@@ -138,11 +114,9 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataMergeOperationOnListTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont/my-list1/leaf1";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 
     /**
@@ -152,10 +126,8 @@ public class TestXmlPatchBodyReaderMountPoint extends AbstractBodyReaderTest {
     public void moduleDataMergeOperationOnContainerTest() throws Exception {
         final String uri = MOUNT_POINT + "/instance-identifier-patch-module:patch-cont";
         mockBodyReader(uri, xmlToPatchBodyReader, false);
-        final InputStream inputStream = TestXmlBodyReader.class
-                .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
-        final PatchContext returnValue = xmlToPatchBodyReader
-                .readFrom(null, null, null, mediaType, null, inputStream);
-        checkPatchContextMountPoint(returnValue);
+        final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream(
+            "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
+        checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
     }
 }