TransparentPmaSession implements PmaSession { @Override public Map<NetConfResponse, List<Notification>> executeNC(String netconfRequest) { try { Document document = null; document = DocumentUtils.stringToDocument(netconfRequest); AbstractNetconfRequest request = DocumentToPojoTransformer.getRequest(document); Future<NetConfResponse> responseFuture = m_connectionManager.executeNetconf(m_device, request); Map<NetConfResponse, List<Notification>> map = new HashMap<>(); map.put(responseFuture.get(), Collections.emptyList()); return map; } catch (NetconfMessageBuilderException e) { throw new IllegalArgumentException(String.format("Invalid netconf request received : %s", netconfRequest), e); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(String.format("Could not execute request %s on device %s", netconfRequest, m_device), e); } } TransparentPmaSession(Device device, NetconfConnectionManager connectionManager); @Override Map<NetConfResponse, List<Notification>> executeNC(String netconfRequest); @Override void forceAlign(); @Override void align(); @Override NetConfResponse getAllPersistCfg();  }
@Test public void testExceptionIsThrownWhenInvalidReqIsSent(){ try{ m_pmaSession.executeNC("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" > <blah xmlns=\"\" /> </rpc>"); fail("Expected an exception here"); }catch (IllegalArgumentException e){ assertEquals("Invalid netconf request received : <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" > <blah xmlns=\"\" /> </rpc>", e.getMessage()); } }
@Test public void testPmaContactsDMAndCMToExecuteNC() throws ExecutionException, NetconfMessageBuilderException, IOException, SAXException { Map<NetConfResponse , List<Notification>> netConfResponseListMap = m_pmaSession.executeNC(REQ_STR); Map.Entry<NetConfResponse , List<Notification>> entry = netConfResponseListMap.entrySet().iterator().next(); String response = entry.getKey().responseToString(); ArgumentCaptor<AbstractNetconfRequest> reqCaptor = ArgumentCaptor.forClass(AbstractNetconfRequest.class); verify(m_cm).executeNetconf(eq(m_device1Meta), reqCaptor.capture()); TestUtil.assertXMLEquals(DocumentUtils.stringToDocument(REQ_STR).getDocumentElement(), DocumentUtils.stringToDocument(reqCaptor.getValue().requestToString()).getDocumentElement()); TestUtil.assertXMLEquals(DocumentUtils.stringToDocument(OK_RESPONSE).getDocumentElement(), DocumentUtils.stringToDocument(response).getDocumentElement()); }