/**
   * This method stores the pushUpdate Notification data to MD-SAL
   *
   * @param sub_id
   * @param timeofeventupdate
   * @param domSource
   * @param data
   */
  private void storeToMdSal(
      String sub_id, String timeofeventupdate, DOMSource domSource, String data) {
    NodeIdentifier subscriptionid =
        NodeIdentifier.create(QName.create(PushUpdates.QNAME, "subscription-id"));
    NodeIdentifier timeofupdate =
        NodeIdentifier.create(QName.create(PushUpdates.QNAME, "time-of-update"));
    NodeIdentifier datanode = NodeIdentifier.create(QName.create(PushUpdates.QNAME, "data"));
    YangInstanceIdentifier pid =
        YangInstanceIdentifier.builder()
            .node(PushUpdates.QNAME)
            .node(
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangpush.rev150105
                    .push.updates.PushUpdate.QNAME)
            .build();

    NodeIdentifierWithPredicates p =
        new NodeIdentifierWithPredicates(
            QName.create(PushUpdates.QNAME, "push-update"),
            QName.create(PushUpdates.QNAME, "subscription-id"),
            sub_id);

    MapEntryNode men =
        ImmutableNodes.mapEntryBuilder()
            .withNodeIdentifier(p)
            .withChild(ImmutableNodes.leafNode(subscriptionid, sub_id))
            .withChild(ImmutableNodes.leafNode(timeofupdate, timeofeventupdate))
            .withChild(ImmutableNodes.leafNode(datanode, data))
            .build();

    DOMDataWriteTransaction tx = this.globalDomDataBroker.newWriteOnlyTransaction();
    YangInstanceIdentifier yid =
        pid.node(
            new NodeIdentifierWithPredicates(
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangpush.rev150105
                    .push.updates.PushUpdate.QNAME,
                men.getIdentifier().getKeyValues()));
    tx.merge(LogicalDatastoreType.CONFIGURATION, yid, men);
    LOG.info("--DATA PATh: {}\n--DATA\n{}", yid, men);
    try {
      tx.submit().checkedGet();
    } catch (TransactionCommitFailedException e) {
      e.printStackTrace();
    }
  }
  @Override
  public MapEntryNode build() {
    for (final Entry<QName, Object> key : getNodeIdentifier().getKeyValues().entrySet()) {
      final DataContainerChild<?, ?> childNode = getChild(childrenQNamesToPaths.get(key.getKey()));

      // We have enough information to fill-in missing leaf nodes, so let's do that
      if (childNode == null) {
        LeafNode<Object> leaf = ImmutableNodes.leafNode(key.getKey(), key.getValue());
        LOG.debug("Adding leaf {} implied by key {}", leaf, key);
        withChild(leaf);
      } else {
        DataValidationException.checkListKey(
            getNodeIdentifier(), key.getKey(), key.getValue(), childNode.getValue());
      }
    }

    return new ImmutableMapEntryNode(getNodeIdentifier(), buildValue(), getAttributes());
  }
  /**
   * Tests backwards compatible serialization/deserialization of a MergeData message with the base
   * and R1 Helium versions, which used the protobuff MergeData message.
   */
  @Test
  public void testSerializationWithHeliumR1Version() throws Exception {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data =
        ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo"))
            .build();

    MergeData expected = new MergeData(path, data, DataStoreVersions.HELIUM_1_VERSION);

    Object serialized = expected.toSerializable();
    assertEquals(
        "Serialized type", ShardTransactionMessages.MergeData.class, serialized.getClass());

    MergeData actual =
        MergeData.fromSerializable(SerializationUtils.clone((Serializable) serialized));
    assertEquals("getPath", expected.getPath(), actual.getPath());
    assertEquals("getData", expected.getData(), actual.getData());
  }
  @Test
  public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data =
        ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo"))
            .build();

    MergeData expected = new MergeData(path, data, DataStoreVersions.CURRENT_VERSION);

    Object serialized = expected.toSerializable();
    assertEquals("Serialized type", MergeData.class, serialized.getClass());
    assertEquals(
        "Version", DataStoreVersions.CURRENT_VERSION, ((MergeData) serialized).getVersion());

    Object clone = SerializationUtils.clone((Serializable) serialized);
    MergeData actual = MergeData.fromSerializable(clone);
    assertEquals("Version", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
    assertEquals("getPath", expected.getPath(), actual.getPath());
    assertEquals("getData", expected.getData(), actual.getData());
  }
  /** Test case: TerminationPoint translation */
  @Test
  public void testTerminationPoint() {
    String logicalName = "node:1";

    final String tpId1 = "tpId:1";
    String tpRef1 = "tpRef:1";
    String tpId2 = "tpId:2";
    String tpRef2 = "tpRef:2";
    String tpId3 = "tpId:3";
    String tpRef3 = "tpRef:3";
    String tpId4 = "tpId:4";
    String tpRef4 = "tpRef:4";

    final String physicalName1 = "node:1";
    MapNode terminationPoints1 =
        ImmutableNodes.mapNodeBuilder(TerminationPoint.QNAME)
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId1)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId1))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef1))
                    .build())
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId2)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId2))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef2))
                    .build())
            .build();
    final MapEntryNode node1 =
        ImmutableNodes.mapEntryBuilder(
                Node.QNAME, TopologyQNames.NETWORK_NODE_ID_QNAME, physicalName1)
            .withChild(terminationPoints1)
            .build();

    final String physicalName2 = "node:2";
    MapNode terminationPoints2 =
        ImmutableNodes.mapNodeBuilder(TerminationPoint.QNAME)
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId1)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId1))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef1))
                    .build())
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId3)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId3))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef3))
                    .build())
            .build();
    final MapEntryNode node2 =
        ImmutableNodes.mapEntryBuilder(
                Node.QNAME, TopologyQNames.NETWORK_NODE_ID_QNAME, physicalName2)
            .withChild(terminationPoints2)
            .build();

    final String physicalName3 = "node:3";
    MapNode terminationPoints3 =
        ImmutableNodes.mapNodeBuilder(TerminationPoint.QNAME)
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId2)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId2))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef2))
                    .build())
            .withChild(
                ImmutableNodes.mapEntryBuilder(
                        TerminationPoint.QNAME, TopologyQNames.NETWORK_TP_ID_QNAME, tpId4)
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.NETWORK_TP_ID_QNAME, tpId4))
                    .withChild(ImmutableNodes.leafNode(TopologyQNames.TP_REF, tpRef4))
                    .build())
            .build();
    final MapEntryNode node3 =
        ImmutableNodes.mapEntryBuilder(
                Node.QNAME, TopologyQNames.NETWORK_NODE_ID_QNAME, physicalName3)
            .withChild(terminationPoints3)
            .build();

    final Map<Integer, NormalizedNode<?, ?>> targetFields = new HashMap<>(1);
    targetFields.put(0, mockNormalizedNode);
    OverlayItem logicalNode1 =
        new OverlayItem(
            new ArrayList<UnderlayItem>() {
              {
                add(
                    new UnderlayItem(
                        node1,
                        targetFields,
                        TOPOLOGY_NAME,
                        physicalName1,
                        CorrelationItemEnum.Node));
                add(
                    new UnderlayItem(
                        node2,
                        targetFields,
                        TOPOLOGY_NAME,
                        physicalName2,
                        CorrelationItemEnum.Node));
              }
            },
            CorrelationItemEnum.Node);
    OverlayItem logicalNode2 =
        new OverlayItem(
            Collections.singletonList(
                new UnderlayItem(
                    node3, targetFields, TOPOLOGY_NAME, physicalName3, CorrelationItemEnum.Node)),
            CorrelationItemEnum.Node);
    OverlayItemWrapper wrapper = new OverlayItemWrapper(logicalName, logicalNode1);
    wrapper.addOverlayItem(logicalNode2);
    NormalizedNode<?, ?> normalizedNode = translator.translate(wrapper);

    Collection value =
        (Collection)
            ((MapEntryNode) normalizedNode)
                .getChild(new NodeIdentifier(TerminationPoint.QNAME))
                .get()
                .getValue();
    Assert.assertEquals("OverlayNode contains wrong amount of TerminationPoints", 6, value.size());
  }