示例#1
0
 @Test
 public void testValidation() throws Exception {
   final XmlElement xml =
       XmlElement.fromString(
           "<validate xmlns=\""
               + XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0
               + "\"><source><candidate/></source></validate>");
   final Element okElement = XmlUtil.readXmlToElement("<ok/>");
   final ConfigSubsystemFacade facade = mock(ConfigSubsystemFacade.class);
   doNothing().when(facade).validateConfiguration();
   final Validate validate = new Validate(facade, NETCONF_SESSION_ID_FOR_REPORTING);
   Element ok = validate.handleWithNoSubsequentOperations(XmlUtil.newDocument(), xml);
   assertEquals(XmlUtil.toString(okElement), XmlUtil.toString(ok));
 }
 static {
   try {
     RPC_REPLY_OK = XmlFileLoader.xmlFileToDocument("messages/mapping/rpc-reply_ok.xml");
   } catch (Exception e) {
     LOG.debug("unable to load rpc reply ok.", e);
     RPC_REPLY_OK = XmlUtil.newDocument();
   }
 }
示例#3
0
  @Override
  protected Element handleWithNoSubsequentOperations(
      final Document document, final XmlElement operationElement) throws DocumentedException {

    boolean commitStatus = transactionProvider.commitTransaction();
    LOG.trace("Transaction commited succesfuly {}", commitStatus);

    return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
  }
 private DOMResult prepareDomResultForRpcRequest(final QName rpcQName) {
   final Document document = XmlUtil.newDocument();
   final Element rpcNS =
       document.createElementNS(
           NETCONF_RPC_QNAME.getNamespace().toString(), NETCONF_RPC_QNAME.getLocalName());
   // set msg id
   rpcNS.setAttribute(
       NetconfMessageTransformUtil.MESSAGE_ID_ATTR, counter.getNewMessageId(MESSAGE_ID_PREFIX));
   final Element elementNS =
       document.createElementNS(rpcQName.getNamespace().toString(), rpcQName.getLocalName());
   rpcNS.appendChild(elementNS);
   document.appendChild(rpcNS);
   return new DOMResult(elementNS);
 }
示例#5
0
  @VisibleForTesting
  Element getResponseInternal(final Document document, final ConfigExecution configExecution)
      throws DocumentedException {

    try {
      getConfigSubsystemFacade().executeConfigExecution(configExecution);
    } catch (final ValidationException e) {
      LOG.warn("Test phase for {} failed", EditConfigXmlParser.EDIT_CONFIG, e);
      final Map<String, String> errorInfo = new HashMap<>();
      errorInfo.put(ErrorTag.OPERATION_FAILED.name(), e.getMessage());
      throw new DocumentedException(
          "Test phase: " + e.getMessage(),
          e,
          ErrorType.APPLICATION,
          ErrorTag.OPERATION_FAILED,
          ErrorSeverity.ERROR,
          errorInfo);
    }

    LOG.trace("Operation {} successful", EditConfigXmlParser.EDIT_CONFIG);

    return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
  }
  @Test
  public void testKeyOrder() throws Exception {
    verifyResponse(
        edit("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml"), RPC_REPLY_OK);
    verifyResponse(commit(), RPC_REPLY_OK);
    final Document configRunning = getConfigRunning();
    final String responseAsString = XmlUtil.toString(configRunning);
    verifyResponse(
        configRunning,
        XmlFileLoader.xmlFileToDocument(
            "messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml"));

    final int key3 = responseAsString.indexOf("key3");
    final int key1 = responseAsString.indexOf("key1");
    final int key2 = responseAsString.indexOf("key2");

    assertTrue(
        String.format(
            "Key ordering invalid, should be key3(%d) < key1(%d) < key2(%d)", key3, key1, key2),
        key3 < key1 && key1 < key2);

    deleteDatastore();
  }
 public CapabilityStrippingConfigSnapshotHolder(Element snapshot, Set<String> capabilities) {
   final XmlElement configElement = XmlElement.fromDomElement(snapshot);
   configSnapshot = XmlUtil.toString(configElement.getDomElement());
   stripCapabilitiesResult = stripCapabilities(configElement, capabilities);
 }