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