Bug 4564: Implement datastore restore from backup file
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / CarsModel.java
index 93b552a6dabad014d698146981d83ce27a644117..6ad88e568ad479de489219cd53f0529ab7f456f5 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.md.cluster.datastore.model;
 import java.math.BigInteger;
 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.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -23,13 +24,13 @@ public class CarsModel {
     public static final QName BASE_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13",
         "cars");
 
-    public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
-
     public static final QName CARS_QNAME = QName.create(BASE_QNAME, "cars");
     public static final QName CAR_QNAME = QName.create(CARS_QNAME, "car");
     public static final QName CAR_NAME_QNAME = QName.create(CAR_QNAME, "name");
     public static final QName CAR_PRICE_QNAME = QName.create(CAR_QNAME, "price");
 
+    public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
+    public static final YangInstanceIdentifier CAR_LIST_PATH = BASE_PATH.node(CAR_QNAME);
 
     public static NormalizedNode<?, ?> create(){
 
@@ -63,10 +64,42 @@ public class CarsModel {
 
     }
 
+    public static NormalizedNode<?, ?> createEmptyCarsList(){
+        return newCarsNode(newCarsMapNode());
+    }
+
+    public static ContainerNode newCarsNode(MapNode carsList) {
+        return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(
+                BASE_QNAME)).withChild(carsList).build();
+    }
+
+    public static MapNode newCarsMapNode(MapEntryNode... carEntries) {
+        CollectionNodeBuilder<MapEntryNode, MapNode> builder = ImmutableMapNodeBuilder.create().
+                withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CAR_QNAME));
+        for(MapEntryNode e: carEntries) {
+            builder.withChild(e);
+        }
+
+        return builder.build();
+    }
+
     public static NormalizedNode<?, ?> emptyContainer(){
         return ImmutableContainerNodeBuilder.create()
             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(BASE_QNAME))
             .build();
     }
 
+    public static NormalizedNode<?, ?> newCarMapNode() {
+        return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
+    }
+
+    public static MapEntryNode newCarEntry(String name, BigInteger price) {
+        return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
+                .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
+                .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
+    }
+
+    public static YangInstanceIdentifier newCarPath(String name) {
+        return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();
+    }
 }