@Test public void testGetUserIntentVnMapping() throws Exception{ Class<CliTrigger> class1 = CliTrigger.class; Method method = class1.getDeclaredMethod("getUserIntentVnMapping", new Class[]{UserId.class}); method.setAccessible(true); UserId userId = mock(UserId.class); UserIntentVnMapping result; ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); Optional<UserIntentVnMapping> optional = mock(Optional.class); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture); when(checkedFuture.get()).thenReturn(optional); when(optional.isPresent()) .thenReturn(false) .thenReturn(true); when(optional.get()).thenReturn(mock(UserIntentVnMapping.class)); result = (UserIntentVnMapping) method.invoke(cliTrigger,userId); Assert.assertTrue(result == null); result = (UserIntentVnMapping) method.invoke(cliTrigger,userId); Assert.assertTrue(result != null); verify(optional).get(); verify(optional,times(2)).isPresent(); }
private UserIntentVnMapping getUserIntentVnMapping(UserId userId) { ReadOnlyTransaction readOnlyTransaction = dataProvider.newReadOnlyTransaction(); InstanceIdentifier<UserIntentVnMapping> userIntentVnMappingIid = InstanceIdentifier .builder(IntentVnMappingResults.class) .child(UserIntentVnMapping.class, new UserIntentVnMappingKey(userId)) .build(); Optional<UserIntentVnMapping> result = null; try { result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get(); } catch (Exception e) { LOG.error("Exception:",e); } if (result.isPresent()) { LOG.info("getUserIntentVnMapping OK"); return result.get(); }else{ LOG.info("getUserIntentVnMapping ERROR"); return null; } }
CliTrigger implements AutoCloseable { private UserIntentVnMapping getUserIntentVnMapping(UserId userId) { ReadOnlyTransaction readOnlyTransaction = dataProvider.newReadOnlyTransaction(); InstanceIdentifier<UserIntentVnMapping> userIntentVnMappingIid = InstanceIdentifier .builder(IntentVnMappingResults.class) .child(UserIntentVnMapping.class, new UserIntentVnMappingKey(userId)) .build(); Optional<UserIntentVnMapping> result = null; try { result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get(); } catch (Exception e) { LOG.error("Exception:",e); } if (result.isPresent()) { LOG.info("getUserIntentVnMapping OK"); return result.get(); }else{ LOG.info("getUserIntentVnMapping ERROR"); return null; } } }
CliTrigger implements AutoCloseable { private UserIntentVnMapping getUserIntentVnMapping(UserId userId) { ReadOnlyTransaction readOnlyTransaction = dataProvider.newReadOnlyTransaction(); InstanceIdentifier<UserIntentVnMapping> userIntentVnMappingIid = InstanceIdentifier .builder(IntentVnMappingResults.class) .child(UserIntentVnMapping.class, new UserIntentVnMappingKey(userId)) .build(); Optional<UserIntentVnMapping> result = null; try { result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get(); } catch (Exception e) { LOG.error("Exception:",e); } if (result.isPresent()) { LOG.info("getUserIntentVnMapping OK"); return result.get(); }else{ LOG.info("getUserIntentVnMapping ERROR"); return null; } } CliTrigger(DataBroker dataProvider); }
CliTrigger implements AutoCloseable { private UserIntentVnMapping getUserIntentVnMapping(UserId userId) { ReadOnlyTransaction readOnlyTransaction = dataProvider.newReadOnlyTransaction(); InstanceIdentifier<UserIntentVnMapping> userIntentVnMappingIid = InstanceIdentifier .builder(IntentVnMappingResults.class) .child(UserIntentVnMapping.class, new UserIntentVnMappingKey(userId)) .build(); Optional<UserIntentVnMapping> result = null; try { result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get(); } catch (Exception e) { LOG.error("Exception:",e); } if (result.isPresent()) { LOG.info("getUserIntentVnMapping OK"); return result.get(); }else{ LOG.info("getUserIntentVnMapping ERROR"); return null; } } CliTrigger(DataBroker dataProvider); @Override void close(); }
CliTrigger implements AutoCloseable { private UserIntentVnMapping getUserIntentVnMapping(UserId userId) { ReadOnlyTransaction readOnlyTransaction = dataProvider.newReadOnlyTransaction(); InstanceIdentifier<UserIntentVnMapping> userIntentVnMappingIid = InstanceIdentifier .builder(IntentVnMappingResults.class) .child(UserIntentVnMapping.class, new UserIntentVnMappingKey(userId)) .build(); Optional<UserIntentVnMapping> result = null; try { result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get(); } catch (Exception e) { LOG.error("Exception:",e); } if (result.isPresent()) { LOG.info("getUserIntentVnMapping OK"); return result.get(); }else{ LOG.info("getUserIntentVnMapping ERROR"); return null; } } CliTrigger(DataBroker dataProvider); @Override void close();  }