### Question:
ServiceChainingUtil { static ServiceFunctionPath findServiceFunctionPathFromServiceChainName(@Nonnull final SfcName chainName) { final ServiceFunctionPaths allPaths = SfcProviderServicePathAPI.readAllServiceFunctionPaths(); if (allPaths == null || allPaths.getServiceFunctionPath() == null || allPaths.getServiceFunctionPath().isEmpty()) { return null; } for (ServiceFunctionPath serviceFunctionPath : allPaths.getServiceFunctionPath()) { if (chainName.equals(serviceFunctionPath.getServiceChainName())) { return serviceFunctionPath; } } return null; } private  ServiceChainingUtil(); static boolean resolveRemoteSfcComponents(final RenderedServicePath renderedServicePath,
                                                      final PolicyConfigurationContext context); static RenderedServicePath resolveReversedRenderedServicePath(final ServiceFunctionPath sfp, final TenantId tenantId,
                                                                          final DataBroker dataBroker, final Sgt sourceSgt,
                                                                          final Sgt destinationSgt, final PolicyConfigurationContext context); @VisibleForTesting static void setTimeout(long value);  }### Answer:
@Test public void findServiceFunctionPathFromServiceChainName_noPaths() { stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(null); final ServiceFunctionPath result = ServiceChainingUtil.findServiceFunctionPathFromServiceChainName(new SfcName(SFC_CHAIN_NAME)); assertNull(result); }
@Test public void findServiceFunctionPathFromServiceChainName_noPathFound() { final ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); final ServiceFunctionPathsBuilder serviceFunctionPathsBuilder = new ServiceFunctionPathsBuilder(); serviceFunctionPathsBuilder.setServiceFunctionPath(Collections.singletonList(serviceFunctionPathBuilder.build())); stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(serviceFunctionPathsBuilder.build()); final ServiceFunctionPath result = ServiceChainingUtil.findServiceFunctionPathFromServiceChainName(new SfcName(SFC_CHAIN_NAME)); assertNull(result); }
@Test public void findServiceFunctionPathFromServiceChainName_pathFound() { final ServiceFunctionPathBuilder serviceFunctionPathBuilder = new ServiceFunctionPathBuilder(); serviceFunctionPathBuilder.setName(new SfpName(SFC_PATH_NAME)) .setServiceChainName(new SfcName(SFC_CHAIN_NAME)); final ServiceFunctionPathsBuilder serviceFunctionPathsBuilder = new ServiceFunctionPathsBuilder(); serviceFunctionPathsBuilder.setServiceFunctionPath(Collections.singletonList(serviceFunctionPathBuilder.build())); stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(serviceFunctionPathsBuilder.build()); final ServiceFunctionPath result = ServiceChainingUtil.findServiceFunctionPathFromServiceChainName(new SfcName(SFC_CHAIN_NAME)); assertNotNull(result); }
@Test public void testFindServiceFunctionPath() throws Exception { final String sfcNameValue = "123"; final ServiceFunctionPath sfcPath = createSfp(sfcNameValue); final ServiceFunctionPaths sfcPaths = new ServiceFunctionPathsBuilder() .setServiceFunctionPath(Collections.singletonList(sfcPath)) .build(); stub(method(SfcProviderServicePathAPI.class, "readAllServiceFunctionPaths")).toReturn(sfcPaths); final ServiceFunctionPath servicePath = ServiceChainingUtil.findServiceFunctionPathFromServiceChainName(new SfcName(sfcNameValue)); assertEquals(sfcPath, servicePath); }