@Test public void test_isValidOrganization_should_return_false_for_invalid_organization() throws CloudFoundryException { String fakeOrgId = "incorrect-organization-guid"; Organizations organizations = mock(Organizations.class); when(cfClient.organizations()).thenReturn(organizations); GetOrganizationRequest request = GetOrganizationRequest.builder().organizationId(fakeOrgId) .build(); when(organizations.get(request)) .thenReturn(Mono.error(new org.cloudfoundry.client.v2.ClientV2Exception(null, cloudFoundryApi.CF_ORGANIZATION_NOT_FOUND, fakeOrgId, fakeOrgId))); assertFalse(cloudFoundryApi.isValidOrganization(fakeOrgId)); }
public boolean isValidOrganization(String organizationGuid) throws CloudFoundryException { GetOrganizationResponse response = cfClient.organizations() .get(GetOrganizationRequest.builder().organizationId(organizationGuid).build()) .onErrorResume(throwable -> { if (throwable instanceof org.cloudfoundry.client.v2.ClientV2Exception && isNoOrganizationFoundError( (org.cloudfoundry.client.v2.ClientV2Exception) throwable)) { return Mono.just(GetOrganizationResponse.builder().build()); } else { return Mono.error(throwable); } }).block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getEntity() != null; }
CloudFoundryApi implements CloudFoundryApiService { public boolean isValidOrganization(String organizationGuid) throws CloudFoundryException { GetOrganizationResponse response = cfClient.organizations() .get(GetOrganizationRequest.builder().organizationId(organizationGuid).build()) .onErrorResume(throwable -> { if (throwable instanceof org.cloudfoundry.client.v2.ClientV2Exception && isNoOrganizationFoundError( (org.cloudfoundry.client.v2.ClientV2Exception) throwable)) { return Mono.just(GetOrganizationResponse.builder().build()); } else { return Mono.error(throwable); } }).block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getEntity() != null; } }
CloudFoundryApi implements CloudFoundryApiService { public boolean isValidOrganization(String organizationGuid) throws CloudFoundryException { GetOrganizationResponse response = cfClient.organizations() .get(GetOrganizationRequest.builder().organizationId(organizationGuid).build()) .onErrorResume(throwable -> { if (throwable instanceof org.cloudfoundry.client.v2.ClientV2Exception && isNoOrganizationFoundError( (org.cloudfoundry.client.v2.ClientV2Exception) throwable)) { return Mono.just(GetOrganizationResponse.builder().build()); } else { return Mono.error(throwable); } }).block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getEntity() != null; }  }
CloudFoundryApi implements CloudFoundryApiService { public boolean isValidOrganization(String organizationGuid) throws CloudFoundryException { GetOrganizationResponse response = cfClient.organizations() .get(GetOrganizationRequest.builder().organizationId(organizationGuid).build()) .onErrorResume(throwable -> { if (throwable instanceof org.cloudfoundry.client.v2.ClientV2Exception && isNoOrganizationFoundError( (org.cloudfoundry.client.v2.ClientV2Exception) throwable)) { return Mono.just(GetOrganizationResponse.builder().build()); } else { return Mono.error(throwable); } }).block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getEntity() != null; }  @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); }
CloudFoundryApi implements CloudFoundryApiService { public boolean isValidOrganization(String organizationGuid) throws CloudFoundryException { GetOrganizationResponse response = cfClient.organizations() .get(GetOrganizationRequest.builder().organizationId(organizationGuid).build()) .onErrorResume(throwable -> { if (throwable instanceof org.cloudfoundry.client.v2.ClientV2Exception && isNoOrganizationFoundError( (org.cloudfoundry.client.v2.ClientV2Exception) throwable)) { return Mono.just(GetOrganizationResponse.builder().build()); } else { return Mono.error(throwable); } }).block(Config.CF_API_TIMEOUT); return Optional.ofNullable(response).get().getEntity() != null; }  @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);  }