NcCompliantAdapterDeviceInterface implements DeviceInterface { @Override public Pair<AbstractNetconfRequest, Future<NetConfResponse>> forceAlign(Device device, NetConfResponse getConfigResponse) throws NetconfMessageBuilderException, ExecutionException { if (m_ncm.isConnected(device)) { CopyConfigRequest ccRequest = new CopyConfigRequest(); EditConfigElement config = new EditConfigElement(); config.setConfigElementContents(getConfigResponse.getDataContent()); ccRequest.setSourceConfigElement(config.getXmlElement()); ccRequest.setTargetRunning(); Future<NetConfResponse> responseFuture = m_ncm.executeNetconf(device.getDeviceName(), ccRequest); return new Pair<>(ccRequest, responseFuture); } else { throw new IllegalStateException(String.format("Device not connected %s", device.getDeviceName())); } } NcCompliantAdapterDeviceInterface(NetconfConnectionManager ncm); @Override Future<NetConfResponse> align(Device device, EditConfigRequest request, NetConfResponse getConfigResponse); @Override Pair<AbstractNetconfRequest, Future<NetConfResponse>> forceAlign(Device device, NetConfResponse getConfigResponse); @Override Future<NetConfResponse> get(Device device, GetRequest getRequest); @Override void veto(Device device, EditConfigRequest request, Document oldDataStore, Document updatedDataStore); @Override Future<NetConfResponse> getConfig(Device device, GetConfigRequest getConfigRequest); @Override ConnectionState getConnectionState(Device device); @Override Notification normalizeNotification(Notification notification);  }
@Test public void testCopyConfig() throws NetconfMessageBuilderException, ExecutionException { NetConfResponse getResponse = new NetConfResponse(); getResponse.addDataContent(DocumentUtils.stringToDocument("<if:interfaces\n" + " 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>").getDocumentElement()); String expected = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <copy-config>\n" + " <target>\n" + " <running/>\n" + " </target>\n" + " <source>\n" + " <config>\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" + " </config>\n" + " </source>\n" + " </copy-config>\n" + "</rpc>"; if (System.getProperty("os.name").startsWith("Windows")) { expected = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\r\n" + " <copy-config>\r\n" + " <target>\r\n" + " <running/>\r\n" + " </target>\r\n" + " <source>\r\n" + " <config>\r\n" + " <if:interfaces xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">\r\n" + " <if:interface>\r\n" + " <if:name>xdsl-line:1/1/1/new</if:name>\r\n" + " <if:type xmlns:bbfift=\"urn:broadband-forum-org:yang:bbf-if-type\">bbfift:xdsl</if:type>\r\n" + " </if:interface>\r\n" + "</if:interfaces>\r\n" + " </config>\r\n" + " </source>\r\n" + " </copy-config>\r\n" + "</rpc>"; } Pair<AbstractNetconfRequest, Future<NetConfResponse>> copyConfigResponse = m_deviceInterface.forceAlign(m_device, getResponse); verify(m_ncm).executeNetconf(anyString(), any(CopyConfigRequest.class)); assertEquals(expected, copyConfigResponse.getFirst().requestToString().trim()); }
@Test public void testForceALignWhenDeviceNotConnected() throws ExecutionException, NetconfMessageBuilderException { NetConfResponse getResponse = new NetConfResponse(); when(m_ncm.isConnected(m_device)).thenReturn(false); getResponse.addDataContent(DocumentUtils.stringToDocument("<if:interfaces\n" + " 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>").getDocumentElement()); String expected = "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <copy-config>\n" + " <target>\n" + " <running/>\n" + " </target>\n" + " <source>\n" + " <config>\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" + " </config>\n" + " </source>\n" + " </copy-config>\n" + "</rpc>"; try { Pair<AbstractNetconfRequest, Future<NetConfResponse>> copyConfigResponse = m_deviceInterface.forceAlign(m_device, getResponse); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains(DEVICE_NOT_CONNECTED_TEST_DEVICE)); } }