CloudFoundryApi implements CloudFoundryApiService { public void bindRoutes(String serviceInstanceId, List<String> routeIds) throws CloudFoundryException { bind(routeIds, routeId -> cfClient.serviceInstances() .bindRoute( BindServiceInstanceRouteRequest.builder() .serviceInstanceId(serviceInstanceId) .routeId(routeId) .build())); }  @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_bind_routes_should_fail() throws CloudFoundryException { ServiceInstances serviceInstances = mock(ServiceInstances.class); when(cfClient.serviceInstances()).thenReturn(serviceInstances); when(serviceInstances.bindRoute(any(BindServiceInstanceRouteRequest.class))) .thenReturn(Mono.error(new RuntimeException("some error"))); verifyThrown(() -> cloudFoundryApi.bindRoutes("serviceInstanceId", Collections.singletonList("route-id")), CloudFoundryException.class); }
@Test public void test_bind_routes_should_succeed() throws CloudFoundryException { ServiceInstances serviceInstances = mock(ServiceInstances.class); when(cfClient.serviceInstances()).thenReturn(serviceInstances); when(serviceInstances.bindRoute(any(BindServiceInstanceRouteRequest.class))) .thenReturn(Mono.just(BindServiceInstanceRouteResponse.builder() .metadata(Metadata.builder() .build()) .entity(ServiceInstanceEntity.builder() .build()) .build())); cloudFoundryApi.bindRoutes("serviceInstanceId", Collections.singletonList("route-id")); verify(serviceInstances, times(1)).bindRoute(any(BindServiceInstanceRouteRequest.class)); }