Search in sources :

Example 36 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class CreateSubscriptionTest method testHandleWithNoSubsequentOperations.

@Test
public void testHandleWithNoSubsequentOperations() throws Exception {
    final CreateSubscription createSubscription = new CreateSubscription("id", notificationRegistry);
    createSubscription.setSession(mock(NetconfSession.class));
    final Element e = XmlUtil.readXmlToElement(CREATE_SUBSCRIPTION_XML);
    final XmlElement operationElement = XmlElement.fromDomElement(e);
    final Element element = createSubscription.handleWithNoSubsequentOperations(XmlUtil.newDocument(), operationElement);
    assertThat(XmlUtil.toString(element), containsString("ok"));
}
Also used : NetconfSession(org.opendaylight.netconf.api.NetconfSession) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Test(org.junit.Test)

Example 37 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class Bug8084 method testValidateTypes.

@Test
public void testValidateTypes() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResources(Bug8084.class, "/yang/filter-validator-test-mod-0.yang", "/yang/filter-validator-test-augment.yang", "/yang/mdsal-netconf-mapping-test.yang");
    final CurrentSchemaContext currentContext = mock(CurrentSchemaContext.class);
    doReturn(context).when(currentContext).getCurrentContext();
    final FilterContentValidator validator = new FilterContentValidator(currentContext);
    final Document document = XmlUtil.readXmlToDocument(FilterContentValidatorTest.class.getResourceAsStream("/filter/bug8084.xml"));
    final XmlElement xmlElement = XmlElement.fromDomDocument(document);
    final YangInstanceIdentifier actual = validator.validate(xmlElement);
    final Map<QName, Object> inputs = new HashMap<>();
    inputs.put(QName.create(BASE, "id1"), "aaa");
    inputs.put(QName.create(BASE, "id2"), Byte.valueOf("-9"));
    inputs.put(QName.create(BASE, "id3"), Short.valueOf("-30000"));
    inputs.put(QName.create(BASE, "id4"), Integer.valueOf("-2000000000"));
    inputs.put(QName.create(BASE, "id5"), Long.valueOf("-2000000000000000"));
    inputs.put(QName.create(BASE, "id6"), Short.valueOf("9"));
    inputs.put(QName.create(BASE, "id7"), Integer.valueOf("30000"));
    inputs.put(QName.create(BASE, "id8"), Long.valueOf("2000000000"));
    inputs.put(QName.create(BASE, "id9"), BigInteger.valueOf(Long.valueOf("2000000000000000")));
    inputs.put(QName.create(BASE, "id10"), true);
    inputs.put(QName.create(BASE, "id11"), BigDecimal.valueOf(128.55));
    inputs.put(QName.create(BASE, "id12"), QName.create(BASE, "foo"));
    inputs.put(QName.create(BASE, "id13"), QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "foo"));
    final QName idActual = (QName) ((NodeIdentifierWithPredicates) actual.getLastPathArgument()).getValue(QName.create(BASE, "id12"));
    final YangInstanceIdentifier expected = YangInstanceIdentifier.builder().node(BASE).node(QName.create(BASE, "multi-key-list2")).nodeWithKey(QName.create(BASE, "multi-key-list2"), inputs).build();
    final QName idExpected = (QName) ((NodeIdentifierWithPredicates) expected.getLastPathArgument()).getValue(QName.create(BASE, "id12"));
    assertEquals(idExpected, idActual);
    assertEquals(expected, actual);
}
Also used : HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) CurrentSchemaContext(org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext) Document(org.w3c.dom.Document) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 38 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class GetSchema method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws DocumentedException {
    final GetSchemaEntry entry;
    entry = new GetSchemaEntry(xml);
    final String schema;
    try {
        schema = cap.getSchemaForCapability(entry.identifier, entry.version);
    } catch (final IllegalStateException e) {
        final Map<String, String> errorInfo = new HashMap<>();
        // FIXME: so we have an <operation-failed>e.getMessage()</operation-failed> ??? In which namespace? Why?
        errorInfo.put(ErrorTag.OPERATION_FAILED.elementBody(), e.getMessage());
        LOG.warn("Rpc error: {}", ErrorTag.OPERATION_FAILED, e);
        throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
    }
    final Element getSchemaResult;
    getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING));
    LOG.trace("{} operation successful", GET_SCHEMA);
    return getSchemaResult;
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class SimulatedEditConfig method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY);
    containsDelete(configElementData);
    if (containsDelete(configElementData)) {
        storage.resetConfigList();
    } else {
        storage.setConfigList(configElementData.getChildElements());
    }
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Example 40 with XmlElement

use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.

the class SimulatedGet method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
    final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
    for (final XmlElement e : storage.getConfigList()) {
        final Element domElement = e.getDomElement();
        element.appendChild(element.getOwnerDocument().importNode(domElement, true));
    }
    return element;
}
Also used : XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Aggregations

XmlElement (org.opendaylight.netconf.api.xml.XmlElement)50 Element (org.w3c.dom.Element)21 Document (org.w3c.dom.Document)16 DocumentedException (org.opendaylight.netconf.api.DocumentedException)13 Test (org.junit.Test)8 QName (org.opendaylight.yangtools.yang.common.QName)7 NodeList (org.w3c.dom.NodeList)6 DOMSource (javax.xml.transform.dom.DOMSource)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 URISyntaxException (java.net.URISyntaxException)3 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)3 NormalizedNodeResult (org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult)3 SAXException (org.xml.sax.SAXException)3 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)2 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)2 Response (io.lighty.netconf.device.response.Response)2 ResponseData (io.lighty.netconf.device.response.ResponseData)2