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