import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
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.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
}
- @Test
- public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
- final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
- mockPutBodyReader(uri, xmlBodyReader);
- final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
- XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xmldata.xml"));
- checkMountPointNormalizedNodePayload(payload);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, payload);
- }
-
- @Test
- public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
- final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
- mockPutBodyReader(uri, xmlBodyReader);
- final NormalizedNodePayload payload = xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null,
- XmlBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml"));
- checkMountPointNormalizedNodePayload(payload);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, payload,
- QName.create(dataSchemaNode.getQName(), "cont1"));
- }
-
@Test
public void moduleSubContainerDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext
assertEquals("foo-bar-container", dataNodeType.getLocalName());
assertEquals("bar:module", dataNodeType.getNamespace().toString());
}
-
- /**
- * Test PUT operation when message root element is not the same as the last element in request URI.
- * PUT operation message should always start with schema node from URI otherwise exception should be
- * thrown.
- */
- @Test
- public void wrongRootElementTest() throws Exception {
- mockPutBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader);
- final var inputStream = XmlBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/xml/bug7933.xml");
-
- final var ex = assertThrows(RestconfDocumentedException.class,
- () -> xmlBodyReader.readFrom(null, null, null, MEDIA_TYPE, null, inputStream));
- final var error = ex.getErrors().get(0);
- assertEquals(ErrorType.PROTOCOL, error.getErrorType());
- assertEquals(ErrorTag.MALFORMED_MESSAGE, error.getErrorTag());
- assertEquals("Error parsing input: Not correct message root element \"cont1\", should be "
- + "\"(urn:ietf:params:xml:ns:netconf:base:1.0)data\"", error.getErrorMessage());
- }
}