+ @Test
+ public void testFiltering() throws Exception {
+
+ assertEmptyDatastore(getConfigCandidate());
+ assertEmptyDatastore(getConfigRunning());
+
+ 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);
+
+ 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"));
+ 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);
+
+ }
+
+ 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));
+ }
+
+ private class TestingGetConfig extends GetConfig{
+ public TestingGetConfig(String sessionId, CurrentSchemaContext schemaContext, TransactionProvider transactionProvider) {
+ super(sessionId, schemaContext, transactionProvider);
+ }
+
+ public YangInstanceIdentifier getInstanceIdentifierFromDocument(Document request) throws NetconfDocumentedException {
+ XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG).getOnlyChildElement(FILTER_NODE);
+ return getInstanceIdentifierFromFilter(filterElement);
+ }
+ }
+