@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)); } }
@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 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 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); }
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); }
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);  }