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.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
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.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
* data node of state data
* @return {@link NormalizedNode}
*/
+ @SuppressWarnings("unchecked")
@Nonnull
private static NormalizedNode<?, ?> prepareData(@Nonnull final NormalizedNode<?, ?> configDataNode,
@Nonnull final NormalizedNode<?, ?> stateDataNode) {
- if (configDataNode instanceof MapNode) {
+ if (configDataNode instanceof OrderedMapNode) {
+ final CollectionNodeBuilder<MapEntryNode, OrderedMapNode> builder = Builders
+ .orderedMapBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(
+ ((OrderedMapNode) configDataNode).getValue(), ((OrderedMapNode) stateDataNode).getValue(), builder);
+
+ return builder.build();
+ } else if (configDataNode instanceof MapNode) {
final CollectionNodeBuilder<MapEntryNode, MapNode> builder = ImmutableNodes
.mapNodeBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
return builder.build();
} else if (configDataNode instanceof LeafNode) {
return ImmutableNodes.leafNode(configDataNode.getNodeType(), configDataNode.getValue());
+ } else if (configDataNode instanceof OrderedLeafSetNode) {
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = Builders
+ .orderedLeafSetBuilder().withNodeIdentifier(((OrderedLeafSetNode<?>) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((OrderedLeafSetNode<Object>) configDataNode).getValue(),
+ ((OrderedLeafSetNode<Object>) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof LeafSetNode) {
+ final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = Builders
+ .leafSetBuilder().withNodeIdentifier(((LeafSetNode<?>) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((LeafSetNode<Object>) configDataNode).getValue(),
+ ((LeafSetNode<Object>) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof UnkeyedListNode) {
+ final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = Builders
+ .unkeyedListBuilder().withNodeIdentifier(((UnkeyedListNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((UnkeyedListNode) configDataNode).getValue(),
+ ((UnkeyedListNode) stateDataNode).getValue(), builder);
+ return builder.build();
+ } else if (configDataNode instanceof UnkeyedListEntryNode) {
+ final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = Builders
+ .unkeyedListEntryBuilder().withNodeIdentifier(((UnkeyedListEntryNode) configDataNode).getIdentifier());
+
+ mapValueToBuilder(((UnkeyedListEntryNode) configDataNode).getValue(),
+ ((UnkeyedListEntryNode) stateDataNode).getValue(), builder);
+ return builder.build();
} else {
- throw new RestconfDocumentedException("Bad type of node.");
+ throw new RestconfDocumentedException("Unexpected node type: " + configDataNode.getClass().getName());
}
}
import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures;
import java.util.Collections;
import javax.ws.rs.core.MultivaluedHashMap;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
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.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
assertEquals(checkingData, normalizedNode);
}
+ @Test
+ public void readOrderedListDataAllTest() {
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.orderedMapNode1))).when(read)
+ .read(LogicalDatastoreType.OPERATIONAL, DATA.path3);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.orderedMapNode2))).when(read)
+ .read(LogicalDatastoreType.CONFIGURATION, DATA.path3);
+ doReturn(DATA.path3).when(context).getInstanceIdentifier();
+
+ final NormalizedNode<?, ?> normalizedNode =
+ ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.ALL, wrapper, schemaContext);
+
+ final MapNode expectedData = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DATA.listQname)).withChild(DATA.checkData)
+ .build();
+ assertEquals(expectedData, normalizedNode);
+ }
+
+ @Test
+ public void readUnkeyedListDataAllTest() {
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.unkeyedListNode1))).when(read)
+ .read(LogicalDatastoreType.OPERATIONAL, DATA.path3);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.unkeyedListNode2))).when(read)
+ .read(LogicalDatastoreType.CONFIGURATION, DATA.path3);
+ doReturn(DATA.path3).when(context).getInstanceIdentifier();
+
+ final NormalizedNode<?, ?> normalizedNode =
+ ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.ALL, wrapper, schemaContext);
+
+ final UnkeyedListNode expectedData = Builders.unkeyedListBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DATA.listQname))
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(DATA.listQname))
+ .withChild(DATA.unkeyedListEntryNode1.getValue().iterator().next())
+ .withChild(DATA.unkeyedListEntryNode2.getValue().iterator().next()).build()).build();
+ assertEquals(expectedData, normalizedNode);
+ }
+
+ @Test
+ public void readLeafListDataAllTest() {
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.leafSetNode1))).when(read)
+ .read(LogicalDatastoreType.OPERATIONAL, DATA.leafSetNodePath);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.leafSetNode2))).when(read)
+ .read(LogicalDatastoreType.CONFIGURATION, DATA.leafSetNodePath);
+ doReturn(DATA.leafSetNodePath).when(context).getInstanceIdentifier();
+
+ final NormalizedNode<?, ?> normalizedNode =
+ ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.ALL, wrapper, schemaContext);
+
+ final LeafSetNode<String> expectedData = Builders.<String>leafSetBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(DATA.leafListQname)).withValue(
+ ImmutableList.<LeafSetEntryNode<String>>builder().addAll(DATA.leafSetNode1.getValue())
+ .addAll(DATA.leafSetNode2.getValue()).build()).build();
+ assertEquals(expectedData, normalizedNode);
+ }
+
+ @Test
+ public void readOrderedLeafListDataAllTest() {
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.orderedLeafSetNode1))).when(read)
+ .read(LogicalDatastoreType.OPERATIONAL, DATA.leafSetNodePath);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(DATA.orderedLeafSetNode2))).when(read)
+ .read(LogicalDatastoreType.CONFIGURATION, DATA.leafSetNodePath);
+ doReturn(DATA.leafSetNodePath).when(context).getInstanceIdentifier();
+
+ final NormalizedNode<?, ?> normalizedNode =
+ ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.ALL, wrapper, schemaContext);
+
+ final LeafSetNode<String> expectedData = Builders.<String>orderedLeafSetBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(DATA.leafListQname)).withValue(
+ ImmutableList.<LeafSetEntryNode<String>>builder().addAll(DATA.orderedLeafSetNode1.getValue())
+ .addAll(DATA.orderedLeafSetNode2.getValue()).build()).build();
+ assertEquals(expectedData, normalizedNode);
+ }
+
@Test
public void readDataWrongPathOrNoContentTest() {
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read)
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.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
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.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
final ContainerNode data4;
final MapNode listData;
final MapNode listData2;
- final UnkeyedListEntryNode unkeyedListEntryNode;
+ final OrderedMapNode orderedMapNode1;
+ final OrderedMapNode orderedMapNode2;
final LeafNode contentLeaf;
final LeafNode contentLeaf2;
final MapEntryNode checkData;
final SchemaPath errorRpc;
final ContainerNode input;
final ContainerNode output;
+ final LeafSetNode<String> leafSetNode1;
+ final LeafSetNode<String> leafSetNode2;
+ final LeafSetNode<String> orderedLeafSetNode1;
+ final LeafSetNode<String> orderedLeafSetNode2;
+ final YangInstanceIdentifier leafSetNodePath;
+ final UnkeyedListNode unkeyedListNode1;
+ final UnkeyedListNode unkeyedListNode2;
+ final UnkeyedListEntryNode unkeyedListEntryNode1;
+ final UnkeyedListEntryNode unkeyedListEntryNode2;
+
+ final QName base = QName.create("ns", "2016-02-28", "base");
+ final QName listKeyQName = QName.create(base, "list-key");
+ final QName leafListQname = QName.create(base, "leaf-list");
+ final QName listQname = QName.create(base, "list");
TestData() {
- final QName base = QName.create("ns", "2016-02-28", "base");
- final QName listQname = QName.create(base, "list");
- final QName listKeyQName = QName.create(base, "list-key");
final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeWithKey =
new YangInstanceIdentifier.NodeIdentifierWithPredicates(listQname, listKeyQName, "keyValue");
final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeWithKey2 =
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(listQname, "identifier")))
.withValue("id")
.build();
- unkeyedListEntryNode = Builders.unkeyedListEntryBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(listQname, "list")))
- .withChild(dataContainer)
- .build();
data = Builders.mapEntryBuilder()
.withNodeIdentifier(nodeWithKey)
.withChild(content)
.withChild(contentLeaf2)
.build();
+ leafSetNodePath = YangInstanceIdentifier.builder().node(QName.create(base, "cont"))
+ .node(leafListQname).build();
+ leafSetNode1 = Builders.<String>leafSetBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(
+ leafListQname)).withChildValue("one").withChildValue("two").build();
+
+ leafSetNode2 = Builders.<String>leafSetBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(
+ leafListQname)).withChildValue("three").build();
+
+ orderedLeafSetNode1 = Builders.<String>orderedLeafSetBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(leafListQname)).withChildValue("one")
+ .withChildValue("two").build();
+ orderedLeafSetNode2 = Builders.<String>orderedLeafSetBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(leafListQname)).withChildValue("three")
+ .withChildValue("four").build();
+
+ orderedMapNode1 = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(data).build();
+
+ orderedMapNode2 = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(data)
+ .withChild(data2).build();
+
+ unkeyedListEntryNode1 = Builders.unkeyedListEntryBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(content).build();
+ unkeyedListNode1 = Builders.unkeyedListBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(unkeyedListEntryNode1).build();
+
+ unkeyedListEntryNode2 = Builders.unkeyedListEntryBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(content2).build();
+ unkeyedListNode2 = Builders.unkeyedListBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(listQname)).withChild(unkeyedListEntryNode2).build();
final QName rpcQname = QName.create("ns", "2015-02-28", "test-rpc");
final QName errorRpcQname = QName.create(rpcQname, "error-rpc");
.withChild(resultLeafNode)
.build();
}
-}
\ No newline at end of file
+}