95b0ec81d2eae07b0fa0f9adfb4b4adc885831d5
[yangtools.git] / yang / yang-data-composite-node / src / test / java / org / opendaylight / yangtools / yang / data / composite / node / schema / serializer / SerializeNormalizedStructToCnSnStructTest.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.composite.node.schema.serializer;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.serializer.CnSnFromNormalizedNodeSerializerFactory;
14
15
16 import org.opendaylight.yangtools.yang.data.composite.node.schema.TestUtils;
17
18 import java.net.URISyntaxException;
19 import java.util.Set;
20
21 import com.google.common.collect.Sets;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
25 import org.opendaylight.yangtools.yang.data.api.Node;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.Module;
30
31 public class SerializeNormalizedStructToCnSnStructTest {
32
33     private static DataSchemaNode resolvedDataSchemaNode;
34
35     @BeforeClass
36     public static void loadData() throws URISyntaxException {
37         Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
38         Module resolvedModule = TestUtils.resolveModule("simple-container-yang", modules);
39         resolvedDataSchemaNode = TestUtils.resolveDataSchemaNode("cont", resolvedModule);
40     }
41
42     @Test
43     public void testCnSnToNormalizedNode() throws URISyntaxException {
44         ContainerNode containerNode = TestUtils.prepareNormalizedNodeStruct();
45
46         Iterable<Node<?>> serialized = CnSnFromNormalizedNodeSerializerFactory.getInstance()
47                 .getContainerNodeSerializer().serialize((ContainerSchemaNode) resolvedDataSchemaNode, containerNode);
48
49         assertNotNull(serialized);
50         assertNotNull(serialized.iterator());
51         assertNotNull(serialized.iterator().hasNext());
52
53         CompositeNode compNode = TestUtils.prepareCompositeNodeStruct();
54
55         assertEquals(serialized.iterator().next().getNodeType(), compNode.getNodeType());
56
57         Set<Node<?>> value = Sets.newHashSet(((CompositeNode)serialized.iterator().next()).getValue());
58         assertEquals(value, Sets.newHashSet(compNode.getValue()));
59     }
60 }