Bump odlparent/yangtools/mdsal
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / persisted / ShardSnapshotStateTest.java
1 /*
2  * Copyright (c) 2017 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.persisted;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
20
21 /**
22  * Unit tests for ShardSnapshotState.
23  *
24  * @author Thomas Pantelis
25  */
26 public class ShardSnapshotStateTest {
27
28     @Test
29     public void testSerialization() {
30         NormalizedNode expectedNode = ImmutableContainerNodeBuilder.create()
31                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
32                 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
33
34         ShardSnapshotState expected = new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expectedNode));
35         ShardSnapshotState cloned = (ShardSnapshotState) SerializationUtils.clone(expected);
36
37         assertNotNull("getSnapshot is null", cloned.getSnapshot());
38         assertEquals("getSnapshot type", MetadataShardDataTreeSnapshot.class, cloned.getSnapshot().getClass());
39         assertEquals("getRootNode", expectedNode,
40                 ((MetadataShardDataTreeSnapshot)cloned.getSnapshot()).getRootNode().get());
41     }
42 }