@SuppressWarnings("unchecked") @Test public void validateIovisorModuleInstanceTest() { DataBroker dataBroker = Mockito.mock(DataBroker.class); when(dataBroker.newReadOnlyTransaction()).thenReturn(mock(ReadOnlyTransaction.class)); PowerMockito.mockStatic(DataStoreHelper.class); Optional<IovisorModuleInstances> result = mock(Optional.class); PowerMockito.when(DataStoreHelper.readFromDs(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(ReadOnlyTransaction.class))) .thenReturn(result); Uri goodUri = mock(Uri.class); when(result.isPresent()).thenReturn(false); Assert.assertFalse(IovisorModuleUtils.validateIovisorModuleInstance(dataBroker, goodUri)); when(result.isPresent()).thenReturn(true); IovisorModuleInstance iovisorModuleInstance = mock(IovisorModuleInstance.class); when(iovisorModuleInstance.getUri()).thenReturn(goodUri); List<IovisorModuleInstance> iovisorModuleInstanceList = new ArrayList<>(); iovisorModuleInstanceList.add(iovisorModuleInstance); IovisorModuleInstances iovisorModuleInstances = mock(IovisorModuleInstances.class); when(iovisorModuleInstances.getIovisorModuleInstance()).thenReturn(iovisorModuleInstanceList); when(result.get()).thenReturn(iovisorModuleInstances); Assert.assertTrue(IovisorModuleUtils.validateIovisorModuleInstance(dataBroker, goodUri)); Uri wrongUri = mock(Uri.class); Assert.assertFalse(IovisorModuleUtils.validateIovisorModuleInstance(dataBroker, wrongUri)); }
public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; }
IovisorModuleUtils { public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; } }
IovisorModuleUtils { public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; } private  IovisorModuleUtils(); }
IovisorModuleUtils { public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; } private  IovisorModuleUtils(); static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri); }
IovisorModuleUtils { public static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri) { Optional<IovisorModuleInstances> res = DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, IovisorIidFactory.iovisorModuleInstanceWildCardIid(), dataBroker.newReadOnlyTransaction()); if (res.isPresent()) { for (IovisorModuleInstance instance : res.get().getIovisorModuleInstance()) { if (instance.getUri().equals(iovisorModuleUri)) { return true; } } } return false; } private  IovisorModuleUtils(); static boolean validateIovisorModuleInstance(DataBroker dataBroker, Uri iovisorModuleUri);  }