X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-bierman02%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frest%2Fimpl%2Ftest%2Fproviders%2FTestXmlPatchBodyReaderMountPoint.java;h=614f36ed026c29a98586a3918854d0d89ff1d7c6;hb=09c1d18add7cfc310f3d190a1a02a523159162ce;hp=64184e0a655b5a8b609e5f8cac3f078fa2733199;hpb=297030dc32e29a3ac0c76aa3d6279e7e047532b3;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java index 64184e0a65..614f36ed02 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/rest/impl/test/providers/TestXmlPatchBodyReaderMountPoint.java @@ -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.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; +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)); } }