Merge "BUG-582: use shared thread-safe SimpleDateFormat"
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / CompositeNodeTOImplTest.java
1 /*
2  * Copyright (c) 2014 Cisco 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.yangtools.yang.data.impl;
9
10 import org.apache.commons.lang.SerializationUtils;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
14 import org.opendaylight.yangtools.yang.data.api.Node;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import static junit.framework.Assert.assertEquals;
20 import static junit.framework.Assert.assertNotNull;
21 import static junit.framework.Assert.assertTrue;
22
23 public class CompositeNodeTOImplTest {
24     @Test
25     public void testSerialization() throws Exception{
26         CompositeNodeTOImpl child1 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child1"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
27         CompositeNodeTOImpl child2 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
28         SimpleNodeTOImpl child3 = new SimpleNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, "foo");
29
30         List<Node<?>> children = new ArrayList<Node<?>>();
31         children.add(child1);
32         children.add(child2);
33         children.add(child3);
34
35         CompositeNodeTOImpl parent = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "parent"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
36
37         CompositeNodeTOImpl object = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "root"), parent, children , ModifyAction.MERGE);
38
39         CompositeNodeTOImpl clone = (CompositeNodeTOImpl) SerializationUtils.clone(object);
40
41         assertNotNull(clone.getNodeType());
42         assertEquals(ModifyAction.MERGE, clone.getModificationAction());
43         assertNotNull(clone.getParent());
44         assertNotNull(clone.getParent().getNodeType());
45         assertNotNull(clone.getValue());
46         assertEquals(3, clone.getValue().size());
47         assertNotNull(clone.getValue().get(0).getNodeType());
48         assertNotNull(clone.getValue().get(1).getNodeType());
49
50         SimpleNodeTOImpl child3Clone = (SimpleNodeTOImpl) clone.getValue().get(2);
51
52         assertNotNull(child3Clone.getNodeType());
53         assertTrue(child3Clone instanceof SimpleNodeTOImpl);
54         assertEquals("foo", child3Clone.getValue());
55
56     }
57 }