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"));
}
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);
}
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;
}
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);
}
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;
}
Aggregations