DeviceSubsystem extends AbstractSubSystem { @Override public void notifyPreCommitChange(List<ChangeNotification> changeNotificationList) throws SubSystemValidationException { Device device = PmaServer.getCurrentDevice(); DeviceXmlStore updatedDeviceStore = PmaServer.getCurrentDeviceXmlStore(); DeviceXmlStore oldDataStore = PmaServer.getBackupDeviceXmlStore(); Document updatedDataStoreDoc = null; Document oldDataStoreDoc = null; try { if (updatedDeviceStore.getDeviceXml() != null && !updatedDeviceStore.getDeviceXml().isEmpty()) { updatedDataStoreDoc = DocumentUtils.stringToDocument(updatedDeviceStore.getDeviceXml()); } if (oldDataStore.getDeviceXml() != null && !oldDataStore.getDeviceXml().isEmpty()) { oldDataStoreDoc = DocumentUtils.stringToDocument(oldDataStore.getDeviceXml()); } } catch (NetconfMessageBuilderException e) { throw new RuntimeException(e.getMessage()); } DeviceInterface deviceInterface = AdapterUtils.getAdapterContext(device, m_adapterManager).getDeviceInterface(); try { deviceInterface.veto(device, (EditConfigRequest) RequestScope.getCurrentScope().getFromCache(CURRENT_REQ), oldDataStoreDoc, updatedDataStoreDoc); } catch (SubSystemValidationException e) { updatedDeviceStore.setDeviceXml(oldDataStore.getDeviceXml()); throw e; } } DeviceSubsystem(NetconfDeviceAlignmentService das, SchemaRegistry schemaRegistry,
                           AdapterManager adapterManager); @Override void notifyChanged(List<ChangeNotification> changeNotificationList); @Override void notifyPreCommitChange(List<ChangeNotification> changeNotificationList);  }
@Test public void testPreCommitChanged() throws SubSystemValidationException, NetconfMessageBuilderException { RequestScope.getCurrentScope().putInCache(RequestTask.CURRENT_REQ, m_request); m_deviceSubsystem.notifyPreCommitChange(m_changeNotifications); verify(m_deviceInterface).veto(eq(m_device), eq(m_request), m_updatedDsCaptor.capture(), m_oldDsCaptor.capture()); assertEquals(OLD_DS, DocumentUtils.documentToPrettyString(m_updatedDsCaptor.getValue()).trim()); assertEquals(UPDATED_DS, DocumentUtils.documentToPrettyString(m_oldDsCaptor.getValue()).trim()); }
@Test public void testPreCommitChangedVetoThrowsException() throws SubSystemValidationException, NetconfMessageBuilderException { RequestScope.getCurrentScope().putInCache(RequestTask.CURRENT_REQ, m_request); doThrow(new SubSystemValidationException("Veto threw exception")).when(m_deviceInterface).veto(eq(m_device), eq(m_request), m_updatedDsCaptor.capture(), m_oldDsCaptor.capture()); try { m_deviceSubsystem.notifyPreCommitChange(m_changeNotifications); assertEquals(UPDATED_DS, DocumentUtils.documentToPrettyString(m_updatedDsCaptor.getValue()).trim()); assertEquals(OLD_DS, DocumentUtils.documentToPrettyString(m_oldDsCaptor.getValue()).trim()); fail("Should have failed"); } catch (SubSystemValidationException e) { assertEquals("Veto threw exception", e.getMessage()); verify(m_deviceStore).setDeviceXml(OLD_DS); } }