2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import static org.junit.Assert.assertEquals;
12 import org.apache.commons.lang.SerializationUtils;
13 import org.junit.Test;
14 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
16 import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
22 * Unit tests for DataChanged.
24 * @author Thomas Pantelis
26 public class DataChangedTest {
29 public void testSerialization() {
30 DOMImmutableDataChangeEvent change = DOMImmutableDataChangeEvent.builder(DataChangeScope.SUBTREE)
31 .addCreated(TestModel.TEST_PATH,
32 ImmutableContainerNodeBuilder.create()
33 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
34 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build())
35 .addUpdated(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME),
36 ImmutableContainerNodeBuilder.create()
37 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
38 .withChild(ImmutableNodes.leafNode(TestModel.NAME_QNAME, "bar")).build())
39 .addRemoved(TestModel.OUTER_LIST_PATH,
40 ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build())
41 .setBefore(ImmutableNodes.containerNode(TestModel.TEST_QNAME))
42 .setAfter(ImmutableContainerNodeBuilder.create()
43 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
44 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo"))
45 .withChild(ImmutableNodes.leafNode(TestModel.NAME_QNAME, "bar")).build())
48 DataChanged expected = new DataChanged(change);
50 DataChanged actual = (DataChanged) SerializationUtils.clone(expected);
52 assertEquals("getCreatedData", change.getCreatedData(), actual.getChange().getCreatedData());
53 assertEquals("getOriginalData", change.getOriginalData(), actual.getChange().getOriginalData());
54 assertEquals("getOriginalSubtree", change.getOriginalSubtree(), actual.getChange().getOriginalSubtree());
55 assertEquals("getRemovedPaths", change.getRemovedPaths(), actual.getChange().getRemovedPaths());
56 assertEquals("getUpdatedData", change.getUpdatedData(), actual.getChange().getUpdatedData());
57 assertEquals("getUpdatedSubtree", change.getUpdatedSubtree(), actual.getChange().getUpdatedSubtree());