import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
@Test
public void moduleDataTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
-
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml"));
- checkPatchContext(returnValue);
+ mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml")));
}
/**
*/
@Test
public void moduleDataValueMissingNegativeTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
+ mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
() -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+ assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
/**
*/
@Test
public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
+ mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
() -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
+ assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
-
/**
* Test of Yang Patch with absolute target path.
*/
@Test
public void moduleDataAbsoluteTargetPathTest() throws Exception {
- final String uri = "";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
-
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml"));
- checkPatchContext(returnValue);
+ mockBodyReader("", xmlToPatchBodyReader, false);
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
}
/**
*/
@Test
public void modulePatchCompleteTargetInURITest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
-
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml"));
- checkPatchContext(returnValue);
+ mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
}
/**
*/
@Test
public void moduleDataMergeOperationOnListTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
-
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml"));
- checkPatchContext(returnValue);
+ mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
}
/**
*/
@Test
public void moduleDataMergeOperationOnContainerTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont";
- mockBodyReader(uri, xmlToPatchBodyReader, false);
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml"));
- checkPatchContext(returnValue);
+ mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
}
}