Merge "Remove unused isMaster variable in ClusteredNetconfDevice"
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NetconfStateSchemasTest.java
1 /*
2  * Copyright (c) 2014, 2015 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
9 package org.opendaylight.netconf.sal.connect.netconf;
10
11 import static org.hamcrest.CoreMatchers.hasItem;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertThat;
14
15 import java.net.InetSocketAddress;
16 import java.util.Collections;
17 import java.util.Set;
18 import org.junit.Test;
19 import org.opendaylight.controller.config.util.xml.XmlUtil;
20 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
21 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
24 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
25 import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
26 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
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.SchemaContext;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32
33 public class NetconfStateSchemasTest {
34
35     @Test
36     public void testCreate() throws Exception {
37         final SchemaContext schemaContext = BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext();
38         final DataSchemaNode schemasNode = ((ContainerSchemaNode) schemaContext.getDataChildByName("netconf-state")).getDataChildByName("schemas");
39
40         final Document schemasXml = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/netconf-state.schemas.payload.xml"));
41         final ToNormalizedNodeParser<Element, ContainerNode, ContainerSchemaNode> containerNodeParser = DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, schemaContext, false).getContainerNodeParser();
42         final ContainerNode compositeNodeSchemas = containerNodeParser.parse(Collections.singleton(schemasXml.getDocumentElement()), (ContainerSchemaNode) schemasNode);
43         final NetconfStateSchemas schemas = NetconfStateSchemas.create(new RemoteDeviceId("device", new InetSocketAddress(99)), compositeNodeSchemas);
44
45         final Set<QName> availableYangSchemasQNames = schemas.getAvailableYangSchemasQNames();
46         assertEquals(73, availableYangSchemasQNames.size());
47
48         assertThat(availableYangSchemasQNames,
49                 hasItem(QName.create("urn:TBD:params:xml:ns:yang:network-topology", "2013-07-12", "network-topology")));
50     }
51 }