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 java.io.File;
import java.io.InputStream;
-import java.net.URI;
import java.util.Collection;
import java.util.Optional;
import javax.ws.rs.core.MediaType;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
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.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
- private final XmlNormalizedNodeBodyReader xmlBodyReader;
+ private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
+ XMLNamespace.of("instance:identifier:module"), Revision.of("2014-01-17"));
+
private static EffectiveModelContext schemaContext;
- private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
- URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
+ private final XmlNormalizedNodeBodyReader xmlBodyReader;
public XmlBodyReaderMountPointTest() throws Exception {
super(schemaContext);
- this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
}
@Override
null, null, this.mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "cont"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNodePotential = contNode
- .getChild(yangCont.getLastPathArgument());
+ final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(
+ QName.create(contNode.getIdentifier().getNodeType(), "cont"));
+ final Optional<DataContainerChild> contDataNodePotential =
+ contNode.findChildByArg(yangCont.getLastPathArgument());
assertTrue(contDataNodePotential.isPresent());
final ContainerNode contDataNode = (ContainerNode) contDataNodePotential.get();
- final YangInstanceIdentifier yangLeaf =
- YangInstanceIdentifier.of(QName.create(contDataNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contDataNode.getChild(
+ final YangInstanceIdentifier yangLeaf = YangInstanceIdentifier.of(
+ QName.create(contDataNode.getIdentifier().getNodeType(), "lf"));
+ final Optional<DataContainerChild> leafDataNode = contDataNode.findChildByArg(
yangLeaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().body().toString()));
}
private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
if (qualifiedName != null && dataSchemaNode instanceof DataNodeContainer) {
final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(qualifiedName);
dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
+ assertEquals(nnContext.getInstanceIdentifierContext().getSchemaNode(), child);
} else {
- assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
+ assertEquals(mountDataSchemaNode, dataSchemaNode);
}
assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
checkMountPointNormalizedNodeContext(returnValue);
// check if container was found both according to its name and namespace
assertEquals("Not correct container found, name was ignored",
- "foo-bar-container", returnValue.getData().getNodeType().getLocalName());
+ "foo-bar-container", returnValue.getData().getIdentifier().getNodeType().getLocalName());
assertEquals("Not correct container found, namespace was ignored",
- "foo:module", returnValue.getData().getNodeType().getNamespace().toString());
+ "foo:module", returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
}
/**
*/
@Test
public void findBarContainerUsingNamespaceTest() throws Exception {
- mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, true);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
- final NormalizedNodeContext returnValue = this.xmlBodyReader
- .readFrom(null, null, null, this.mediaType, null, inputStream);
+ mockBodyReader("instance-identifier-module:cont/yang-ext:mount", xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlDataFindBarContainer.xml");
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
// check return value
checkMountPointNormalizedNodeContext(returnValue);
// check if container was found both according to its name and namespace
assertEquals("Not correct container found, name was ignored",
- "foo-bar-container", returnValue.getData().getNodeType().getLocalName());
+ "foo-bar-container", returnValue.getData().getIdentifier().getNodeType().getLocalName());
assertEquals("Not correct container found, namespace was ignored",
- "bar:module", returnValue.getData().getNodeType().getNamespace().toString());
+ "bar:module", returnValue.getData().getIdentifier().getNodeType().getNamespace().toString());
}
/**
@Test
public void wrongRootElementTest() throws Exception {
mockBodyReader("instance-identifier-module:cont/yang-ext:mount", this.xmlBodyReader, false);
- final InputStream inputStream =
- XmlBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/xml/bug7933.xml");
- try {
- this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
- Assert.fail("Test should fail due to malformed PUT operation message");
- } catch (final RestconfDocumentedException exception) {
- final RestconfError restconfError = exception.getErrors().get(0);
- Assert.assertEquals(RestconfError.ErrorType.PROTOCOL, restconfError.getErrorType());
- Assert.assertEquals(RestconfError.ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
- }
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/bug7933.xml");
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+ final RestconfError restconfError = ex.getErrors().get(0);
+ assertEquals(ErrorType.PROTOCOL, restconfError.getErrorType());
+ assertEquals(ErrorTag.MALFORMED_MESSAGE, restconfError.getErrorTag());
}
}