* 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.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
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.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.netconf.sal.rest.impl.XmlToPatchBodyReader;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+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() {
xmlToPatchBodyReader = new XmlToPatchBodyReader(controllerContext);
}
- @Override
- protected MediaType getMediaType() {
- return new MediaType(MediaType.APPLICATION_XML, null);
- }
-
@BeforeClass
public static void initialization() throws NoSuchFieldException, SecurityException {
schemaContext = schemaContextLoader("/instanceidentifier/yang", 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));
}
/**
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());
}
/**
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());
}
/**
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);
}
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);
}
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));
}
/**
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));
}
}