DeviceConfigInterceptor implements ModelNodeInterceptor { @Override public void interceptEditConfig(HelperDrivenModelNode modelNode, EditContext editContext) throws EditConfigException { EditContainmentNode editNode = editContext.getEditNode(); if (editNode.getName().equals("device-management") && editNode.getNamespace().equals(NS) && isCreateOrMergeOrReplace(editNode.getEditOperation())) { DeviceAdapterId adapterId = getAdapterId(editNode); if (adapterId.getType() == null || adapterId.getInterfaceVersion() == null || adapterId.getModel() == null || adapterId.getVendor() == null) { return; } if (m_adapterManager.getDeviceAdapter(adapterId) == null) { NetconfRpcError error = NetconfRpcErrorUtil.getApplicationError(NetconfRpcErrorTag.INVALID_VALUE, "Invalid adapter details for device. " + adapterId + " not deployed"); throw new EditConfigException(error); } } } DeviceConfigInterceptor(AdapterManager adapterManager); @Override void interceptEditConfig(HelperDrivenModelNode modelNode, EditContext editContext);  }
@Test public void testCreationOfDeviceWithAvailableAdapter() { ArgumentCaptor<DeviceAdapterId> adapter = ArgumentCaptor.forClass(DeviceAdapterId.class); EditContainmentNode deviceEditNode = new EditContainmentNode(DEVICE_MANAGEMENT_QNAME, EditConfigOperations.MERGE); deviceEditNode.addLeafChangeNode(TYPE_QNAME, new GenericConfigAttribute(TYPE, NS, "TYPE1")); deviceEditNode.addLeafChangeNode(INTERFACE_VERSION_QNAME, new GenericConfigAttribute(INTERFACE_VERSION, NS, "1.0")); deviceEditNode.addLeafChangeNode(VENDOR_QNAME, new GenericConfigAttribute(VENDOR, NS, "VENDOR1")); deviceEditNode.addLeafChangeNode(MODEL_QNAME, new GenericConfigAttribute(MODEL, NS, "MODEL1")); EditContext editContext = new EditContext(deviceEditNode, null, ERROR_ON_ROLLBACK, null); m_deviceConfigInterceptor.interceptEditConfig(m_modelNode, editContext); verify(m_adapterManager).getDeviceAdapter(adapter.capture()); }
@Test public void testWhenJustModificationOfProperties() { EditContainmentNode deviceEditNode = new EditContainmentNode(DEVICE_MANAGEMENT_QNAME, EditConfigOperations.MERGE); deviceEditNode.addLeafChangeNode(TYPE_QNAME, new GenericConfigAttribute(TYPE, NS, "TYPE1")); deviceEditNode.addLeafChangeNode(INTERFACE_VERSION_QNAME, new GenericConfigAttribute(INTERFACE_VERSION, NS, "1.0")); EditContext editContext = new EditContext(deviceEditNode, null, ERROR_ON_ROLLBACK, null); m_deviceConfigInterceptor.interceptEditConfig(m_modelNode, editContext); verifyZeroInteractions(m_adapterManager); }
@Test public void testCreationOfDeviceWithNoAvailableAdapter() { ArgumentCaptor<DeviceAdapterId> adapter = ArgumentCaptor.forClass(DeviceAdapterId.class); EditContainmentNode deviceEditNode = new EditContainmentNode(DEVICE_MANAGEMENT_QNAME, EditConfigOperations.MERGE); deviceEditNode.addLeafChangeNode(TYPE_QNAME, new GenericConfigAttribute(TYPE, NS, "TYPE2")); deviceEditNode.addLeafChangeNode(INTERFACE_VERSION_QNAME, new GenericConfigAttribute(INTERFACE_VERSION, NS, "2.0")); deviceEditNode.addLeafChangeNode(VENDOR_QNAME, new GenericConfigAttribute(VENDOR, NS, "VENDOR2")); deviceEditNode.addLeafChangeNode(MODEL_QNAME, new GenericConfigAttribute(MODEL, NS, "MODEL2")); EditContext editContext = new EditContext(deviceEditNode, null, ERROR_ON_ROLLBACK, null); try { m_deviceConfigInterceptor.interceptEditConfig(m_modelNode, editContext); } catch (EditConfigException e) { NetconfRpcError error = e.getRpcError(); assertEquals(ADAPTER_NOR_DEPLOYED_ERROR, error.getErrorMessage()); assertEquals(INVALID_VALUE, error.getErrorTag()); assertEquals(Application, error.getErrorType()); assertEquals(Error, error.getErrorSeverity()); verify(m_adapterManager).getDeviceAdapter(adapter.capture()); } }