SfcGeniusSfStateReader extends SfcGeniusReaderAbstract { public CompletableFuture<List<SfpName>> readSfpNames(SfName sfName) { InstanceIdentifier<ServiceFunctionState> sfStateId = InstanceIdentifier.builder(ServiceFunctionsState.class) .child(ServiceFunctionState.class, new ServiceFunctionStateKey(sfName)).build(); return doReadOptional(LogicalDatastoreType.OPERATIONAL, sfStateId) .thenApply(optionalServiceFunctionState -> optionalServiceFunctionState .map(ServiceFunctionState::getSfServicePath) .orElse(Collections.emptyList()) .stream() .map(SfServicePath::getName) .collect(Collectors.toList()) ); } SfcGeniusSfStateReader(ReadTransaction readTransaction, Executor executor); CompletableFuture<List<SfpName>> readSfpNames(SfName sfName);  }
@Test public void readSfpNames() throws Exception { SfName sfName = new SfName("SF1"); InstanceIdentifier<ServiceFunctionState> sfStateIID = InstanceIdentifier.builder(ServiceFunctionsState.class) .child(ServiceFunctionState.class, new ServiceFunctionStateKey(sfName)).build(); List<SfServicePath> sfServicePaths = Arrays.asList( new SfServicePathBuilder().setName(new SfpName("SFP1")).build(), new SfServicePathBuilder().setName(new SfpName("SFP2")).build() ); when(serviceFunctionState.getSfServicePath()).thenReturn(sfServicePaths); doReturn(CompletableFuture.completedFuture(Optional.of(serviceFunctionState))) .when(sfcGeniusSfStateReader).doReadOptional(LogicalDatastoreType.OPERATIONAL, sfStateIID); List<SfpName> sfpNameList = sfcGeniusSfStateReader.readSfpNames(sfName).get(); assertThat(sfpNameList.size(), is(2)); assertThat(sfpNameList, containsInAnyOrder(new SfpName("SFP1"), new SfpName("SFP2"))); }
@Test public void readSfpNamesEmpty() throws Exception { SfName sfName = new SfName("SF1"); InstanceIdentifier<ServiceFunctionState> sfStateIID = InstanceIdentifier.builder(ServiceFunctionsState.class) .child(ServiceFunctionState.class, new ServiceFunctionStateKey(sfName)).build(); doReturn(CompletableFuture.completedFuture(Optional.empty())) .when(sfcGeniusSfStateReader).doReadOptional(LogicalDatastoreType.OPERATIONAL, sfStateIID); List<SfpName> sfpNameList = sfcGeniusSfStateReader.readSfpNames(sfName).get(); assertThat(sfpNameList.size(), is(0)); }