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.json.schema.cnsn.serializer;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import java.net.URISyntaxException;
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;
27 public class SerializeNormalizedStructToCnSnStructTest {
29 private static DataSchemaNode resolvedDataSchemaNode;
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);
39 public void testCnSnToNormalizedNode() throws URISyntaxException {
40 ContainerNode containerNode = TestUtils.prepareNormalizedNodeStruct();
42 Iterable<Node<?>> serialized = CnSnFromNormalizedNodeSerializerFactory.getInstance()
43 .getContainerNodeSerializer().serialize((ContainerSchemaNode) resolvedDataSchemaNode, containerNode);
45 assertNotNull(serialized);
46 assertNotNull(serialized.iterator());
47 assertNotNull(serialized.iterator().hasNext());
49 CompositeNode compNode = TestUtils.prepareCompositeNodeStruct();
51 assertEquals(serialized.iterator().next().getNodeType(), compNode.getNodeType());
53 Set<Node<?>> value = Sets.newHashSet(((CompositeNode)serialized.iterator().next()).getValue());
54 assertEquals(value, Sets.newHashSet(compNode.getValue()));