CloudFoundryApi implements CloudFoundryApiService { @Override public List<String> listRouteApplications(String routeUuid) throws CloudFoundryException { log.debug("listRouteApplications"); try { ListRouteApplicationsResponse response = cfClient.routes() .listApplications( ListRouteApplicationsRequest.builder() .routeId(routeUuid) .build()) .block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getResources().stream() .map(appResource -> appResource.getMetadata().getId()) .collect(Collectors.toList()); } catch (RuntimeException r) { throw new CloudFoundryException(r); } }  @Override void bindApplications(String serviceInstanceId, List<ApplicationIdentity> applications); void bindRoutes(String serviceInstanceId, List<String> routeIds); @Override ApplicationActivity getApplicationActivity(String appUid); Instant getInstantFromLogMessageTimestamp(Long logMessageTimestamp); @Override String getApplicationState(String applicationUuid); @Override String getHost(String routeId); @Override boolean isAppRunning(String appUid); @Override List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames); @Override List<String> listApplicationRoutes(String applicationUuid); @Override List<String> listRouteApplications(String routeUuid); @Override boolean startApplication(String applicationUuid); @Override boolean stopApplication(String applicationUuid); @Override void unbind(String bindingId); boolean isValidOrganization(String organizationGuid);  }
@Test public void test_list_applications_of_route_should_fail() throws CloudFoundryException { Routes routes = mock(Routes.class); when(cfClient.routes()).thenReturn(routes); when(routes.listApplications(any(ListRouteApplicationsRequest.class))) .thenReturn(Mono.error(new RuntimeException())); verifyThrown(() -> cloudFoundryApi.listRouteApplications("route-id"), CloudFoundryException.class); }
@Test public void test_list_applications_of_route_should_succeed() throws CloudFoundryException { Routes routes = mock(Routes.class); when(cfClient.routes()).thenReturn(routes); when(routes.listApplications(any(ListRouteApplicationsRequest.class))) .thenReturn(Mono.just(ListRouteApplicationsResponse.builder() .resource(ApplicationResource.builder() .metadata(Metadata.builder() .id("application-id-1") .build()) .build()) .resource(ApplicationResource.builder() .metadata(Metadata.builder() .id("application-id-2") .build()) .build()) .build() )); List<String> routeIds = cloudFoundryApi.listRouteApplications("route-id"); verify(routes, times(1)).listApplications(any(ListRouteApplicationsRequest.class)); assertNotNull(routeIds); assertEquals(2, routeIds.size()); assertEquals("application-id-1", routeIds.get(0)); assertEquals("application-id-2", routeIds.get(1)); }