2 * Copyright (c) 2014 Cisco 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.yangtools.yang.data.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.apache.commons.lang.SerializationUtils;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
21 import org.opendaylight.yangtools.yang.data.api.Node;
24 public class CompositeNodeTOImplTest {
26 public void testSerialization() throws Exception{
27 CompositeNodeTOImpl child1 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child1"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
28 CompositeNodeTOImpl child2 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
29 SimpleNodeTOImpl child3 = new SimpleNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, "foo");
31 List<Node<?>> children = new ArrayList<Node<?>>();
36 CompositeNodeTOImpl parent = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "parent"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
38 CompositeNodeTOImpl object = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "root"), parent, children , ModifyAction.MERGE);
40 CompositeNodeTOImpl clone = (CompositeNodeTOImpl) SerializationUtils.clone(object);
42 assertNotNull(clone.getNodeType());
43 assertEquals(ModifyAction.MERGE, clone.getModificationAction());
44 assertNotNull(clone.getParent());
45 assertNotNull(clone.getParent().getNodeType());
46 assertNotNull(clone.getValue());
47 assertEquals(3, clone.getValue().size());
48 assertNotNull(clone.getValue().get(0).getNodeType());
49 assertNotNull(clone.getValue().get(1).getNodeType());
51 SimpleNodeTOImpl child3Clone = (SimpleNodeTOImpl) clone.getValue().get(2);
53 assertNotNull(child3Clone.getNodeType());
54 assertTrue(child3Clone instanceof SimpleNodeTOImpl);
55 assertEquals("foo", child3Clone.getValue());