import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
final JsonReader reader = new JsonReader(new InputStreamReader(entityStream));
jsonParser.parse(reader);
- NormalizedNode<?, ?> partialResult = resultHolder.getResult();
- final NormalizedNode<?, ?> result;
+ NormalizedNode<?, ?> result = resultHolder.getResult();
+ List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
+ InstanceIdentifierContext<SchemaNode> newIIContext;
- // FIXME: Also II should be updated unwrap result from augmentation and choice nodes on PUT
- if (!isPost()) {
- while (partialResult instanceof AugmentationNode || partialResult instanceof ChoiceNode) {
- final Object childNode = ((DataContainerNode) partialResult).getValue().iterator().next();
- partialResult = (NormalizedNode<?, ?>) childNode;
+ if (isPost()) {
+ while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+ final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
+ iiToDataList.add(result.getIdentifier());
+ result = (NormalizedNode<?, ?>) childNode;
+ }
+ if (result instanceof MapEntryNode) {
+ iiToDataList.add(new YangInstanceIdentifier.NodeIdentifier(result.getNodeType()));
+ iiToDataList.add(result.getIdentifier());
+ } else {
+ iiToDataList.add(result.getIdentifier());
}
- }
-
- if (partialResult instanceof MapNode && !isPost()) {
- result = Iterables.getOnlyElement(((MapNode) partialResult).getValue());
} else {
- result = partialResult;
+ if (result instanceof MapNode) {
+ result = Iterables.getOnlyElement(((MapNode) result).getValue());
+ }
}
- return new NormalizedNodeContext(path,result);
+
+ YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
+ path.getInstanceIdentifier().getPathArguments(), iiToDataList));
+
+ newIIContext = new InstanceIdentifierContext<>(fullIIToData, path.getSchemaNode(), path.getMountPoint(),
+ path.getSchemaContext());
+
+ return new NormalizedNodeContext(newIIContext, result);
} catch (final RestconfDocumentedException e) {
throw e;
} catch (final ResultAlreadySetException e) {
*/
package org.opendaylight.controller.sal.rest.impl;
+import com.google.common.collect.Iterables;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Deque;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
}
final Document doc = dBuilder.parse(entityStream);
- final NormalizedNode<?, ?> result = parse(path,doc);
- return new NormalizedNodeContext(path,result);
+ return parse(path,doc);
} catch (final RestconfDocumentedException e){
throw e;
} catch (final Exception e) {
}
}
- private static NormalizedNode<?,?> parse(final InstanceIdentifierContext<?> pathContext,final Document doc) {
+ private NormalizedNodeContext parse(final InstanceIdentifierContext<?> pathContext,final Document doc) {
final List<Element> elements = Collections.singletonList(doc.getDocumentElement());
final SchemaNode schemaNodeContext = pathContext.getSchemaNode();
}
final String docRootElm = doc.getDocumentElement().getLocalName();
- final String schemaNodeName = pathContext.getSchemaNode().getQName().getLocalName();
+ List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
+ InstanceIdentifierContext<SchemaNode> outIIContext;
+
// FIXME the factory instance should be cached if the schema context is the same
final DomToNormalizedNodeParserFactory parserFactory =
DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext());
- if (!schemaNodeName.equalsIgnoreCase(docRootElm)) {
- final DataSchemaNode foundSchemaNode = findSchemaNodeOrParentChoiceByName(schemaNode, docRootElm);
- if (foundSchemaNode != null) {
- if (schemaNode instanceof AugmentationTarget) {
- final AugmentationSchema augmentSchemaNode = findCorrespondingAugment(schemaNode, foundSchemaNode);
- if (augmentSchemaNode != null) {
- return parserFactory.getAugmentationNodeParser().parse(elements, augmentSchemaNode);
- }
+ if (isPost()) {
+ final Deque<Object> foundSchemaNodes = findPathToSchemaNodeByName(schemaNode, docRootElm);
+ while (!foundSchemaNodes.isEmpty()) {
+ Object child = foundSchemaNodes.pop();
+ if (child instanceof AugmentationSchema) {
+ final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child;
+ iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode));
+ } else if (child instanceof DataSchemaNode) {
+ schemaNode = (DataSchemaNode) child;
+ iiToDataList.add(new YangInstanceIdentifier.NodeIdentifier(schemaNode.getQName()));
}
- schemaNode = foundSchemaNode;
}
}
+ YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
+ pathContext.getInstanceIdentifier().getPathArguments(), iiToDataList));
+
+ outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(), pathContext.getMountPoint(),
+ pathContext.getSchemaContext());
+
NormalizedNode<?, ?> parsed = null;
if(schemaNode instanceof ContainerSchemaNode) {
- return parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode);
+ parsed = parserFactory.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode);
} else if(schemaNode instanceof ListSchemaNode) {
final ListSchemaNode casted = (ListSchemaNode) schemaNode;
- return parserFactory.getMapEntryNodeParser().parse(elements, casted);
- } else if (schemaNode instanceof ChoiceSchemaNode) {
- final ChoiceSchemaNode casted = (ChoiceSchemaNode) schemaNode;
- return parserFactory.getChoiceNodeParser().parse(elements, casted);
+ parsed = parserFactory.getMapEntryNodeParser().parse(elements, casted);
}
// FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode
- return parsed;
+ return new NormalizedNodeContext(outIIContext, parsed);
}
- private static DataSchemaNode findSchemaNodeOrParentChoiceByName(DataSchemaNode schemaNode, String elementName) {
+ private static Deque<Object> findPathToSchemaNodeByName(DataSchemaNode schemaNode, String elementName) {
+ final Deque<Object> result = new ArrayDeque<>();
final ArrayList<ChoiceSchemaNode> choiceSchemaNodes = new ArrayList<>();
final Collection<DataSchemaNode> children = ((DataNodeContainer) schemaNode).getChildNodes();
for (final DataSchemaNode child : children) {
if (child instanceof ChoiceSchemaNode) {
choiceSchemaNodes.add((ChoiceSchemaNode) child);
} else if (child.getQName().getLocalName().equalsIgnoreCase(elementName)) {
- return child;
+ result.push(child);
+ if (child.isAugmenting()) {
+ final AugmentationSchema augment = findCorrespondingAugment(schemaNode, child);
+ if (augment != null) {
+ result.push(augment);
+ }
+ }
+ return result;
}
}
for (final ChoiceSchemaNode choiceNode : choiceSchemaNodes) {
for (final ChoiceCaseNode caseNode : choiceNode.getCases()) {
- final DataSchemaNode resultFromRecursion = findSchemaNodeOrParentChoiceByName(caseNode, elementName);
- if (resultFromRecursion != null) {
- // this returns top choice node in which child element is found
- return choiceNode;
+ final Deque<Object> resultFromRecursion = findPathToSchemaNodeByName(caseNode, elementName);
+ if (!resultFromRecursion.isEmpty()) {
+ resultFromRecursion.push(choiceNode);
+ if (choiceNode.isAugmenting()) {
+ final AugmentationSchema augment = findCorrespondingAugment(schemaNode, choiceNode);
+ if (augment != null) {
+ resultFromRecursion.push(augment);
+ }
+ }
+ return resultFromRecursion;
}
}
}
- return null;
+ return result;
}
private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
- if (parent instanceof AugmentationTarget && !((parent instanceof ChoiceCaseNode) || (parent instanceof ChoiceSchemaNode))) {
+ if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
if (childInAugmentation != null) {
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
-
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
private CheckedFuture<Void, TransactionCommitFailedException> postDataViaTransaction(
final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
- final YangInstanceIdentifier parentPath, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
// FIXME: This is doing correct post for container and list children
// not sure if this will work for choice case
if(payload instanceof MapNode) {
- final YangInstanceIdentifier mapPath = parentPath.node(payload.getIdentifier());
- final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, mapPath);
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
- ensureParentsByMerge(datastore, mapPath, rWTransaction, schemaContext);
+ ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
for(final MapEntryNode child : ((MapNode) payload).getValue()) {
- final YangInstanceIdentifier childPath = mapPath.node(child.getIdentifier());
+ final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
checkItemDoesNotExists(rWTransaction, datastore, childPath);
rWTransaction.put(datastore, childPath, child);
}
} else {
- final YangInstanceIdentifier path;
- if(payload instanceof MapEntryNode) {
- path = parentPath.node(payload.getNodeType()).node(payload.getIdentifier());
- } else {
- path = parentPath.node(payload.getIdentifier());
- }
checkItemDoesNotExists(rWTransaction,datastore, path);
ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
rWTransaction.put(datastore, path, payload);
package org.opendaylight.controller.sal.rest.impl.test.providers;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
import java.io.InputStream;
-
+import java.net.URI;
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import com.google.common.base.Optional;
-
/**
- * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector
+ * org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 11, 2015
+ * Created: Mar 11, 2015
*/
public class TestJsonBodyReader extends AbstractBodyReaderTest {
private final JsonNormalizedNodeBodyReader jsonBodyReader;
private static SchemaContext schemaContext;
- public TestJsonBodyReader() throws NoSuchFieldException, SecurityException {
+ public TestJsonBodyReader () throws NoSuchFieldException, SecurityException {
super();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
+ public static void initialization() throws NoSuchFieldException, SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
- "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
+ YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(contAugmentQName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
+ .node(augII).node(contAugmentQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, jsonBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/json_augment_container.json");
+ final NormalizedNodeContext returnValue = jsonBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ //FIXME: Uncomment this when JsonParserStream works correctly with case augmentation with choice
+ //@Test
+ public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
+ QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+ final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
+ YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice1QName));
+ YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice2QName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
+ .node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName)
+ .node(containerQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, jsonBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json");
+ final NormalizedNodeContext returnValue = jsonBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- private void checkExpectValueNormalizeNodeContext(
- final DataSchemaNode dataSchemaNode,
- final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
- .of(dataSchemaNode.getQName());
-
- if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
- .getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
- .node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
- .equals(child));
- } else {
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
- .equals(dataSchemaNode));
- }
- assertTrue(nnContext.getInstanceIdentifierContext()
- .getInstanceIdentifier().equals(dataNodeIdent));
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
- dataNodeIdent));
+ private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ final NormalizedNodeContext nnContext,
+ final YangInstanceIdentifier dataNodeIdent) {
+ assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
+ assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
}
package org.opendaylight.controller.sal.rest.impl.test.providers;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
import java.io.InputStream;
-
+import java.net.URI;
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.XmlNormalizedNodeBodyReader;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import com.google.common.base.Optional;
-
/**
- * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector
+ * org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 7, 2015
+ * Created: Mar 7, 2015
*/
public class TestXmlBodyReader extends AbstractBodyReaderTest {
private final XmlNormalizedNodeBodyReader xmlBodyReader;
private static SchemaContext schemaContext;
- public TestXmlBodyReader() throws NoSuchFieldException, SecurityException {
+ public TestXmlBodyReader () throws NoSuchFieldException, SecurityException {
super();
xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException,
- SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang",
- schemaContext);
+ public static void initialization() throws NoSuchFieldException, SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
- "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext
- .getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
+ YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(contAugmentQName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
+ .node(augII).node(contAugmentQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, xmlBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml");
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
+ QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+ final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
+ YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice1QName));
+ YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice2QName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName())
+ .node(augChoice1II).node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName)
+ .node(containerQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, xmlBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml");
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
@Test
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
- null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
- .create(contNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode
- .getChild(yangleaf.getLastPathArgument());
+ final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "lf"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode.getChild(yangleaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
- .toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
}
- private void checkExpectValueNormalizeNodeContext(
- final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- private void checkExpectValueNormalizeNodeContext(
- final DataSchemaNode dataSchemaNode,
- final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
- .of(dataSchemaNode.getQName());
-
- if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
- .getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
- .node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
- .equals(child));
- } else {
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
- .equals(dataSchemaNode));
- }
- assertTrue(nnContext.getInstanceIdentifierContext()
- .getInstanceIdentifier().equals(dataNodeIdent));
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
- dataNodeIdent));
+ private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ final NormalizedNodeContext nnContext,
+ final YangInstanceIdentifier dataNodeIdent) {
+ assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
+ assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
}
when(rwTransaction.submit()).thenReturn(expFuture);
final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = brokerFacade.commitConfigurationDataPost(
- (SchemaContext)null, YangInstanceIdentifier.builder().build(), dummyNode);
+ (SchemaContext)null, instanceID, dummyNode);
assertSame("commitConfigurationDataPost", expFuture, actualFuture);
--- /dev/null
+{
+ "augment-module:case-choice-case-container1": {
+ "augment-module:case-choice-case-leaf1": "stryng"
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "augment-module:cont-augment": {
+ "augment-module:leaf1": "stryng"
+ }
+}
\ No newline at end of file
--- /dev/null
+<case-choice-case-container1 xmlns="augment:module">
+ <case-choice-case-leaf1>stryng</case-choice-case-leaf1>
+</case-choice-case-container1>
\ No newline at end of file
--- /dev/null
+<cont-augment xmlns="augment:module">
+ <leaf1>stryng</leaf1>
+</cont-augment>
\ No newline at end of file
module augment-module {
- namespace "augment:module";
+ namespace "augment:module";
prefix "amodule";
-
+
import instance-identifier-module {prefix imodule; revision-date 2014-01-17;}
-
- revision 2014-01-17 {
+
+ revision 2014-01-17 {
}
-
+
augment "/imodule:cont/imodule:cont1" {
list lst11 {
key "keyvalue111 keyvalue112";
leaf keyvalue112 {
type string;
}
- }
+ }
+ }
+
+ augment "/imodule:cont" {
+ container cont-augment {
+ leaf leaf1 {
+ type string;
+ }
+ }
}
-
-}
\ No newline at end of file
+
+ augment "/imodule:cont" {
+ choice augment-choice1 {
+ case case1 {
+ container case-container1 {
+ leaf case-leaf1 {
+ type string;
+ }
+ }
+ }
+
+ case case2 {
+ container case-container2 {
+ leaf case-leaf2 {
+ type string;
+ }
+ }
+ }
+ }
+ }
+
+ augment "/imodule:cont/augment-choice1/case1" {
+ choice augment-choice2 {
+ case case11 {
+ container case-choice-case-container1 {
+ leaf case-choice-case-leaf1 {
+ type string;
+ }
+ }
+ }
+ }
+ }
+
+}