@Test public void testMultipleEditsWithMerge() throws Exception { verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml")); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); assertEmptyDatastore(getConfigRunning()); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); deleteDatastore(); }
private void verifyFilterIdentifier(String resource, YangInstanceIdentifier identifier) throws Exception { TestingGetConfig getConfig = new TestingGetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); Document request = XmlFileLoader.xmlFileToDocument(resource); YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request); assertTrue(iid.equals(identifier)); }
@Test public void testEditWithCommit() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); deleteDatastore(); }
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(); } }
private Document executeOperation(NetconfOperation op, String filename) throws ParserConfigurationException, SAXException, IOException, DocumentedException { final Document request = XmlFileLoader.xmlFileToDocument(filename); final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT); LOG.debug("Got response {}", response); return response; }
@Test public void testEditMissingDefaultOperation() throws Exception { verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"), RPC_REPLY_OK); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); deleteDatastore(); }
@Test public void testCandidateTransaction() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); assertEmptyDatastore(getConfigRunning()); verifyResponse(discardChanges(), RPC_REPLY_OK); assertEmptyDatastore(getConfigCandidate()); }
@Test public void testEditWithCreate() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfig_create_n1_control.xml")); try { edit("messages/mapping/editConfigs/editConfig_create.xml"); fail("Create should have failed - data already exists"); } catch (DocumentedException e) { assertTrue(e.getErrorSeverity() == ErrorSeverity.error); assertTrue(e.getErrorTag() == ErrorTag.data_exists); assertTrue(e.getErrorType() == ErrorType.protocol); } verifyResponse(discardChanges(), RPC_REPLY_OK); }
@Test public void testMoreComplexEditConfigs() throws Exception { verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml")); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml")); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); verifyResponse( edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_replace_default_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_replace_default_control.xml")); deleteDatastore(); }
@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(); }
@Test public void testFiltering() throws Exception { assertEmptyDatastore(getConfigCandidate()); assertEmptyDatastore(getConfigRunning()); verifyResponse( getConfigWithFilter("messages/mapping/filters/get-config-empty-filter.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse( getWithFilter("messages/mapping/filters/get-empty-filter.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse( getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse( getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse( edit("messages/mapping/editConfigs/editConfig-filtering-setup.xml"), RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); // TODO uncomment these tests once we can parse KeyedListNode as a selection node, currently you // cannot use a KeyedList as a selection node in filter // verifyFilterIdentifier("messages/mapping/filters/get-filter-alluser.xml", // YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build()); verifyFilterIdentifier( "messages/mapping/filters/get-filter-company-info.xml", YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build()); verifyFilterIdentifier( "messages/mapping/filters/get-filter-modules-and-admin.xml", YangInstanceIdentifier.builder().node(TOP).build()); verifyFilterIdentifier( "messages/mapping/filters/get-filter-only-names-types.xml", YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build()); // // verifyFilterIdentifier("messages/mapping/filters/get-filter-specific-module-type-and-user.xml", // YangInstanceIdentifier.builder().node(TOP).build()); // verifyFilterIdentifier("messages/mapping/filters/get-filter-superuser.xml", // YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build()); verifyFilterIdentifier( "messages/mapping/filters/get-filter-users.xml", YangInstanceIdentifier.builder().node(TOP).node(USERS).build()); YangInstanceIdentifier ident = YangInstanceIdentifier.builder(AUGMENTED_CONTAINER_IN_MODULES) .node(AUGMENTED_CONTAINER) .node(AUGMENTED_STRING_IN_CONT) .build(); verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident); verifyFilterIdentifier( "messages/mapping/filters/get-filter-augmented-case.xml", YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(AUGMENTED_CASE).build()); verifyResponse( getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case.xml")); /* * RFC6020 requires that at most once case inside a choice is present at any time. * Therefore * <augmented-case>augmented case</augmented-case> * from * messages/mapping/editConfigs/editConfig-filtering-setup.xml * cannot exists together with * <text>augmented nested choice text1</text> * from * messages/mapping/editConfigs/editConfig-filtering-setup2.xml */ // verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup2.xml"), // RPC_REPLY_OK); // verifyResponse(commit(), RPC_REPLY_OK); // // verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml", // // YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build()); // // verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml", // // YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE).node(INNER_CHOICE_TEXT).build()); // // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"), // // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml")); // // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml"), // // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml")); // // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-case.xml"), // // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml")); verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-top.xml"), RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); }
@Test public void testEditConfigWithMultipleOperations() throws Exception { deleteDatastore(); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"), RPC_REPLY_OK); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), RPC_REPLY_OK); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml")); verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml")); deleteDatastore(); verifyResponse( edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"), RPC_REPLY_OK); verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"), RPC_REPLY_OK); try { edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml"); fail(); } catch (DocumentedException e) { assertTrue(e.getErrorSeverity() == ErrorSeverity.error); assertTrue(e.getErrorTag() == ErrorTag.data_exists); assertTrue(e.getErrorType() == ErrorType.protocol); } verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_remove-non-existing.xml"), RPC_REPLY_OK); try { edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete-non-existing.xml"); fail(); } catch (DocumentedException e) { assertTrue(e.getErrorSeverity() == ErrorSeverity.error); assertTrue(e.getErrorTag() == ErrorTag.data_missing); assertTrue(e.getErrorType() == ErrorType.protocol); } verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml")); // Test files have been modified. RFC6020 requires that at most once case inside a choice is // present at any time verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml")); verifyResponse( edit( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"), RPC_REPLY_OK); verifyResponse( getConfigCandidate(), XmlFileLoader.xmlFileToDocument( "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); deleteDatastore(); }