2 * Copyright (c) 2014 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.impl.mapping.operations;
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;
26 public class DefaultGetSchemaTest {
28 private CapabilityProvider cap;
30 private String getSchema;
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" +
40 " xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">ncm:yang\n" +
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)));
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))));