Bug-915: Adding static document generation.
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultGetSchemaTest.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
9 package org.opendaylight.controller.netconf.impl.mapping.operations;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.doThrow;
16 import static org.mockito.Mockito.mock;
17 import com.google.common.base.Optional;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
21 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
22 import org.opendaylight.controller.netconf.util.xml.XmlElement;
23 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
24 import org.w3c.dom.Document;
25
26 public class DefaultGetSchemaTest {
27
28     private CapabilityProvider cap;
29     private Document doc;
30     private String getSchema;
31
32     @Before
33     public void setUp() throws Exception {
34         cap = mock(CapabilityProvider.class);
35         doc = XmlUtil.newDocument();
36         getSchema = "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
37                 "        <identifier>threadpool-api</identifier>\n" +
38                 "        <version>2010-09-24</version>\n" +
39                 "        <format\n" +
40                 "                xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">ncm:yang\n" +
41                 "        </format>\n" +
42                 "    </get-schema>";
43     }
44
45     @Test(expected = NetconfDocumentedException.class)
46     public void testDefaultGetSchema() throws Exception {
47         DefaultGetSchema schema = new DefaultGetSchema(cap, "");
48         doThrow(IllegalStateException.class).when(cap).getSchemaForCapability(anyString(), any(Optional.class));
49         schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema)));
50     }
51
52     @Test
53     public void handleWithNoSubsequentOperations() throws Exception {
54         DefaultGetSchema schema = new DefaultGetSchema(cap, "");
55         doReturn("").when(cap).getSchemaForCapability(anyString(), any(Optional.class));
56         assertNotNull(schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema))));
57     }
58 }