PmaAdapter implements DeviceConfigProcessor, GlobalRequestProcessor { @Override public String processRequest(String deviceName, String netconfRequest) throws DispatchException { try { NetconfRpcMessage netconfRpcMessage = NetconfRpcMessage.getInstance(netconfRequest); if (netconfRpcMessage.getOnlyOneTopXmlns().equals(PmaDeviceConfigRpc.NAMESPACE)) { return processPmaDeviceConfigRequest(deviceName, netconfRpcMessage); } Map<NetConfResponse, List<Notification>> netConfResponseListMap = getPmaRegistry().executeNC(deviceName, netconfRequest); Map.Entry<NetConfResponse, List<Notification>> entry = netConfResponseListMap.entrySet().iterator().next(); List<Notification> notificationList = entry.getValue(); if ((notificationList != null) && (!notificationList.isEmpty())) { for (Notification notification : notificationList) { m_aggregator.publishNotification(deviceName, notification); } } return entry.getKey().responseToString(); } catch (IllegalArgumentException | IllegalStateException | ExecutionException ex) { throw new DispatchException(ex); } } PmaAdapter(Aggregator aggregator, PmaRegistry pmaRegistry,
                      AdapterDeployer actionHandler); void init(); void destroy(); @Override String processRequest(String deviceName, String netconfRequest); @Override String processRequest(NetconfClientInfo clientInfo, String netconfRequest); Aggregator getAggregator(); PmaRegistry getPmaRegistry();  }
@Test public void processRequest() throws Exception { Map<NetConfResponse, List<Notification>> map = new HashMap<>(); NetConfResponse netConfResponse = DocumentToPojoTransformer.getNetconfResponse(DocumentUtils.stringToDocument(RESPONSE_OK_XML)); map.put(netConfResponse, Collections.emptyList()); when(m_pmaRegistry.executeNC(DEVICE_NAME_A, REQUEST_DEVICE_CONFIG_GET)).thenReturn(map); String response = m_pmaAdapter.processRequest(DEVICE_NAME_A, REQUEST_DEVICE_CONFIG_GET); TestUtil.assertXMLEquals(DocumentUtils.stringToDocument(RESPONSE_OK_XML).getDocumentElement(), DocumentUtils.stringToDocument(response).getDocumentElement()); }
@Test public void processRequestAlign() throws Exception { String response = m_pmaAdapter.processRequest(DEVICE_NAME_A, REQUEST_ALIGN); verify(m_pmaRegistry).align(DEVICE_NAME_A); assertTrue(response.contains(RESPONSE_OK)); }
@Test public void processRequestAlignForce() throws Exception { String response = m_pmaAdapter.processRequest(DEVICE_NAME_A, REQUEST_ALIGN_FORCE); verify(m_pmaRegistry).forceAlign(DEVICE_NAME_A); assertTrue(response.contains(RESPONSE_OK)); }
@Test public void processRequestAlignGet() throws Exception { String response = m_pmaAdapter.processRequest(DEVICE_NAME_A, REQUEST_ALIGN_STATE_GET); assertTrue(response.contains("alignment-state")); }