DeleteSecurityGroup implements DeleteServiceInstanceBindingPostFilter { @Override public void run(DeleteServiceInstanceBindingRequest request, Void response) { securityGroupId(request.getBindingId()) .flatMap(securityGroupId -> cloudFoundryClient.securityGroups() .delete(DeleteSecurityGroupRequest.builder() .securityGroupId(securityGroupId) .build())) .doOnError(resp -> log.error("Fail to delete security group {}", request.getBindingId())) .timeout(Duration.ofSeconds(60)) .subscribe(resp -> log.debug("Security group {} deleted", request.getBindingId())); } @Autowired  DeleteSecurityGroup(CloudFoundryClient cloudFoundryClient); @Override void run(DeleteServiceInstanceBindingRequest request, Void response);  }
@Test public void should_not_delete_if_security_group_does_not_exist() throws Exception { givenSecurityGroupDoesNotExist(this.cloudFoundryClient, "test-securitygroup-name"); givenDeleteSecurityGroupsSucceeds(this.cloudFoundryClient, "test-securitygroup-id"); DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder() .serviceInstanceId("serviceInstanceId") .bindingId("test-securitygroup-name") .serviceDefinitionId("serviceDefinitionId") .planId("planId") .build(); deleteSecurityGroup.run(request, null); Mockito.verify(cloudFoundryClient.securityGroups(), Mockito.never()) .delete(any()); }