- private static void verifyResponse(final Document response, final Document template) throws Exception {
- final DetailedDiff dd = new DetailedDiff(new Diff(response, template));
- dd.overrideElementQualifier(new NetconfXmlUnitRecursiveQualifier());
-
- printDocument(response);
- printDocument(template);
-
- assertTrue(dd.toString(), dd.similar());
- }
-
- private static void assertEmptyDatastore(final Document response) {
- final NodeList nodes = response.getChildNodes();
- assertTrue(nodes.getLength() == 1);
-
- assertEquals(nodes.item(0).getLocalName(), RPC_REPLY_ELEMENT);
-
- final NodeList replyNodes = nodes.item(0).getChildNodes();
- assertTrue(replyNodes.getLength() == 1);
-
- final Node dataNode = replyNodes.item(0);
- assertEquals(dataNode.getLocalName(), DATA_ELEMENT);
- assertFalse(dataNode.hasChildNodes());
- }
-
- private Document commit() throws Exception {
- final Commit commit = new Commit(SESSION_ID_FOR_REPORTING, transactionProvider);
- return executeOperation(commit, "messages/mapping/commit.xml");
- }
-
- private Document discardChanges() throws Exception {
- final DiscardChanges discardOp = new DiscardChanges(SESSION_ID_FOR_REPORTING, transactionProvider);
- return executeOperation(discardOp, "messages/mapping/discardChanges.xml");
- }
-
- private Document edit(final String resource) throws Exception {
- final EditConfig editConfig = new EditConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext,
- transactionProvider);
- return executeOperation(editConfig, resource);
- }
-
- private Document get() throws Exception {
- final Get get = new Get(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
- return executeOperation(get, "messages/mapping/get.xml");
- }
-
- private Document getWithFilter(final String resource) throws Exception {
- final Get get = new Get(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
- return executeOperation(get, resource);
- }
-
- private Document getConfigRunning() throws Exception {
- final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
- return executeOperation(getConfig, "messages/mapping/getConfig.xml");
- }
-
- private Document getConfigCandidate() throws Exception {
- final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
- return executeOperation(getConfig, "messages/mapping/getConfig_candidate.xml");
- }
-
- private Document getConfigWithFilter(final String resource) throws Exception {
- final GetConfig getConfig = new GetConfig(SESSION_ID_FOR_REPORTING, currentSchemaContext, transactionProvider);
- return executeOperation(getConfig, resource);
- }
-
- private static Document lock() throws Exception {
- final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
- return executeOperation(lock, "messages/mapping/lock.xml");
- }
-
- private static Document unlock() throws Exception {
- final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
- return executeOperation(unlock, "messages/mapping/unlock.xml");
- }
-
- private static Document lockWithoutTarget() throws Exception {
- final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
- return executeOperation(lock, "messages/mapping/lock_notarget.xml");
- }
-
- private static Document unlockWithoutTarget() throws Exception {
- final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
- return executeOperation(unlock, "messages/mapping/unlock_notarget.xml");
- }
-
- private static Document lockCandidate() throws Exception {
- final Lock lock = new Lock(SESSION_ID_FOR_REPORTING);
- return executeOperation(lock, "messages/mapping/lock_candidate.xml");
- }
-
- private static Document unlockCandidate() throws Exception {
- final Unlock unlock = new Unlock(SESSION_ID_FOR_REPORTING);
- return executeOperation(unlock, "messages/mapping/unlock_candidate.xml");
- }
-
- private static Document executeOperation(final NetconfOperation op, final String filename) throws Exception {
- final Document request = XmlFileLoader.xmlFileToDocument(filename);
- final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
-
- LOG.debug("Got response {}", response);
- return response;
- }
-
- private List<InputStream> getYangSchemas() {
- final List<String> schemaPaths = Arrays.asList("/META-INF/yang/config.yang",
- "/yang/mdsal-netconf-mapping-test.yang");
- final List<InputStream> schemas = new ArrayList<>();
-
- for (final String schemaPath : schemaPaths) {
- final InputStream resourceAsStream = getClass().getResourceAsStream(schemaPath);
- schemas.add(resourceAsStream);
- }
-
- return schemas;
- }
-
- private SchemaService createSchemaService() {
- return new SchemaService() {
-
- @Override
- public void addModule(final Module module) {
- }
-
- @Override
- public void removeModule(final Module module) {
-
- }
-
- @Override
- public SchemaContext getSessionContext() {
- return schemaContext;
- }
-
- @Override
- public SchemaContext getGlobalContext() {
- return schemaContext;
- }
-
- @Override
- public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
- final SchemaContextListener listener) {
- listener.onGlobalContextUpdated(getGlobalContext());
- return new ListenerRegistration<SchemaContextListener>() {
- @Override
- public void close() {
-
- }
-
- @Override
- public SchemaContextListener getInstance() {
- return listener;
- }
- };
- }
- };