PmaServerImpl implements PmaServer { @Override public Map<NetConfResponse, List<Notification>> executeNetconf(AbstractNetconfRequest request) { PmaServer.setCurrentDevice(m_device); PmaServer.setCurrentDeviceXmlStore(m_deviceStore); ThreadLocalDSMRegistry.setDsm(m_dsm); ThreadLocalSubsystemRegistry.setSubsystemRegistry(m_stdAdapterContext.getSubSystemRegistry()); ThreadLocalSchemaRegistry.setSchemaRegistry(m_stdAdapterContext.getSchemaRegistry()); m_netconfServer.getDataStore(StandardDataStores.RUNNING).setNamespaceContext(ThreadLocalSchemaRegistry.getRegistry()); ThreadLocalModelNodeHelperRegistry.setModelNodeHelperRegistry(m_stdAdapterContext.getModelNodeHelperRegistry()); ThreadLocalRootModelNodeAggregator.setRootAggregator(m_stdAdapterContext.getRootModelNodeAggregator()); if (request instanceof EditConfigRequest) { PmaServer.setBackupDeviceXmlStore(createBackUpStore(getDeviceStoreBackupFilePath(m_device.getDeviceName()))); } try { List<Notification> notifications = m_msgHandler.processRequest(PMA_USER, request, m_responseChannel); Map<NetConfResponse, List<Notification>> replyMap = new HashMap<>(); replyMap.put(m_responseChannel.getLastResponse(), notifications); return replyMap; } finally { ThreadLocalDSMRegistry.clearDsm(); ThreadLocalSchemaRegistry.clearRegistry(); ThreadLocalSubsystemRegistry.clearRegistry(); ThreadLocalModelNodeHelperRegistry.clearRegistry(); ThreadLocalRootModelNodeAggregator.clearRootAggregator(); PmaServer.clearCurrentDevice(); PmaServer.clearCurrentDeviceXmlStore(); if (request instanceof EditConfigRequest) { PmaServer.clearBackupDeviceXmlStore(); deleteBackupFile(m_device.getDeviceName()); } } } PmaServerImpl(Device device, NetconfServer netconfServer, Pair<ModelNodeDataStoreManager, DeviceXmlStore>
            dsmStorePair, AdapterContext adapterContext, AdapterContext stdAdapterContext, String deviceFileBaseDirPath); @Override Map<NetConfResponse, List<Notification>> executeNetconf(AbstractNetconfRequest request); boolean isActive(); Device getDevice();  }
@Test public void testPmaServerContactsServerMessageListener() throws NetconfMessageBuilderException, IOException, SAXException { Map<NetConfResponse, List<Notification>> netConfResponseListMap = m_pmaServer.executeNetconf(m_getRequest); Map.Entry<NetConfResponse, List<Notification>> entry = netConfResponseListMap.entrySet().iterator().next(); NetConfResponse response = entry.getKey(); verify(m_netconfServer).onGet(eq(PMA_USER), eq(m_getRequest), anyObject()); String expect = "<rpc-reply message-id=\"1\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <data>\n" + " <if:interfaces xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\n" + " <if:interface>\n" + " <if:name>xdsl-line:1/1/1/new</if:name>\n" + " <if:type xmlns:bbfift=\"urn:broadband-forum-org:yang:bbf-if-type\">bbfift:xdsl</if:type>\n" + " </if:interface>\n" + "</if:interfaces>\n" + " </data>\n" + "</rpc-reply>\n"; TestUtil.assertXMLEquals(DocumentUtils.stringToDocument(expect).getDocumentElement(), DocumentUtils.stringToDocument(response.responseToString()).getDocumentElement()); verifyZeroInteractions(m_deviceDataStore); }
@Test public void testPmaServerContactsServerMessageListenerOnEdit() throws NetconfMessageBuilderException, IOException, SAXException { Map<NetConfResponse, List<Notification>> netConfResponseListMap = m_pmaServer.executeNetconf(m_editRequest); Map.Entry<NetConfResponse, List<Notification>> entry = netConfResponseListMap.entrySet().iterator().next(); NetConfResponse response = entry.getKey(); verify(m_netconfServer).onEditConfig(eq(PMA_USER), eq(m_editRequest), anyObject()); String expect = "<rpc-reply message-id=\"2\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <data>\n" + " <ok/>\n" + " </data>\n" + "</rpc-reply>"; TestUtil.assertXMLEquals(DocumentUtils.stringToDocument(expect).getDocumentElement(), DocumentUtils.stringToDocument(response.responseToString().trim()).getDocumentElement()); verify(m_deviceDataStore).getDeviceXml(); }