2 * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.serializer;
11 import java.io.IOException;
12 import java.text.ParseException;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.w3c.dom.Element;
23 public class LeafSetDomSerializerTest {
24 private LeafSetEntryNodeDomSerializer temp;
25 private LeafListSchemaNode currentLeafList;
26 private LeafSetEntryNode tempLeafList;
29 public void leafSetDomSerializerTest() throws IOException, YangSyntaxErrorException, ParseException, ReactorException {
30 leafSetEntryNodeDomSerializerTest();
31 leafSetNodeDomSerializerTest();
34 private void leafSetEntryNodeDomSerializerTest() throws ReactorException, IOException, YangSyntaxErrorException,
36 final ContainerSchemaNode currentContainer = (ContainerSchemaNode) DomSerializerTestUtils.getSchemaContext()
37 .findModuleByName("serializer-test", null)
38 .getDataChildByName(DomSerializerTestUtils.generateQname("root"));
39 currentLeafList = (LeafListSchemaNode) currentContainer.getDataChildByName(DomSerializerTestUtils
40 .generateQname("first-leaf-list"));
42 final YangInstanceIdentifier.NodeWithValue barPath = new YangInstanceIdentifier.NodeWithValue
43 (DomSerializerTestUtils.generateQname("first-leaf-list"), "bar");
44 tempLeafList = ImmutableLeafSetEntryNodeBuilder.create()
45 .withNodeIdentifier(barPath)
49 temp = new LeafSetEntryNodeDomSerializer(DomSerializerTestUtils.DOC, DomSerializerTestUtils.CODEC_PROVIDER);
50 final Element element = temp.serializeLeaf(currentLeafList, tempLeafList);
52 DomSerializerTestUtils.testResults("<first-leaf-list xmlns=\"dom-serializer-test\">bar</first-leaf-list>",
56 private void leafSetNodeDomSerializerTest() {
57 final LeafSetNodeDomSerializer nodeDomSerializer = new LeafSetNodeDomSerializer(temp);
58 final LeafSetEntryNodeDomSerializer leafSetEntryNodeSerializer = (LeafSetEntryNodeDomSerializer)
59 nodeDomSerializer.getLeafSetEntryNodeSerializer();
60 final Element element = temp.serializeLeaf(currentLeafList, tempLeafList);
62 leafSetEntryNodeSerializer.serializeLeaf(currentLeafList, tempLeafList);
63 DomSerializerTestUtils.testResults("<first-leaf-list xmlns=\"dom-serializer-test\">bar</first-leaf-list>",