ec7b74bedfdc04c7653bad66702094674c36b45c
[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.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20
21 /**
22  * Unit tests for ShardSnapshotState.
23  *
24  * @author Thomas Pantelis
25  */
26 public class ShardSnapshotStateTest {
27     @Test
28     public void testSerialization() {
29         ContainerNode expectedNode = Builders.containerBuilder()
30             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
31             .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo"))
32             .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 }