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.composite.node.schema.serializer;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.serializer.CnSnFromNormalizedNodeSerializerFactory;
16 import org.opendaylight.yangtools.yang.data.composite.node.schema.TestUtils;
18 import java.net.URISyntaxException;
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;
31 public class SerializeNormalizedStructToCnSnStructTest {
33 private static DataSchemaNode resolvedDataSchemaNode;
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);
43 public void testCnSnToNormalizedNode() throws URISyntaxException {
44 ContainerNode containerNode = TestUtils.prepareNormalizedNodeStruct();
46 Iterable<Node<?>> serialized = CnSnFromNormalizedNodeSerializerFactory.getInstance()
47 .getContainerNodeSerializer().serialize((ContainerSchemaNode) resolvedDataSchemaNode, containerNode);
49 assertNotNull(serialized);
50 assertNotNull(serialized.iterator());
51 assertNotNull(serialized.iterator().hasNext());
53 CompositeNode compNode = TestUtils.prepareCompositeNodeStruct();
55 assertEquals(serialized.iterator().next().getNodeType(), compNode.getNodeType());
57 Set<Node<?>> value = Sets.newHashSet(((CompositeNode)serialized.iterator().next()).getValue());
58 assertEquals(value, Sets.newHashSet(compNode.getValue()));