2 * Copyright (c) 2015 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.controller.netconf.monitoring;
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;
18 import com.google.common.base.Optional;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
22 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
23 import org.opendaylight.controller.netconf.util.xml.XmlElement;
24 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
25 import org.w3c.dom.Document;
27 public class GetSchemaTest {
30 private NetconfMonitoringService cap;
32 private String getSchema;
35 public void setUp() throws Exception {
36 cap = mock(NetconfMonitoringService.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" +
42 " xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">ncm:yang\n" +
47 @Test(expected = NetconfDocumentedException.class)
48 public void testDefaultGetSchema() throws Exception {
49 GetSchema schema = new GetSchema(cap);
50 doThrow(IllegalStateException.class).when(cap).getSchemaForCapability(anyString(), any(Optional.class));
51 schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema)));
55 public void handleWithNoSubsequentOperations() throws Exception {
56 GetSchema schema = new GetSchema(cap);
57 doReturn("").when(cap).getSchemaForCapability(anyString(), any(Optional.class));
58 assertNotNull(schema.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement(getSchema))));