Skip to content

Commit

Permalink
adding security groups delete api v3 impl and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslav-tomov authored Jul 7, 2023
1 parent 1a907f3 commit 53000cb
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse;
Expand Down Expand Up @@ -81,4 +82,12 @@ public Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest reque
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId()))
.checkpoint();
}

@Override
public Mono<String> delete(DeleteSecurityGroupRequest request) {
return delete(request, String.class,
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId()))
.checkpoint();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse;
import org.cloudfoundry.client.v3.securitygroups.Protocol;
import org.cloudfoundry.client.v3.securitygroups.Rule;
import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest;
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse;
Expand All @@ -44,10 +45,12 @@
import java.util.Collections;

import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpMethod.DELETE;;
import static io.netty.handler.codec.http.HttpMethod.PATCH;
import static io.netty.handler.codec.http.HttpMethod.POST;
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;;

public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest {

Expand Down Expand Up @@ -350,4 +353,28 @@ public void update() {
.verify(Duration.ofSeconds(5));

}

@Test
public void delete() {
mockRequest(InteractionContext.builder()
.request(TestRequest.builder()
.method(DELETE)
.path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
.build())
.response(TestResponse.builder()
.status(ACCEPTED)
.header("Location",
"https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
.build())
.build());

this.securityGroups
.delete(DeleteSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.build())
.as(StepVerifier::create)
.expectNext("b85a788e-671f-4549-814d-e34cdb2f539a")
.expectComplete()
.verify(Duration.ofSeconds(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public interface SecurityGroupsV3 {

/**
* Makes the <a href=
*
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#list-security-groups">List
* Security Groups</a> request
*
Expand All @@ -53,12 +52,21 @@ public interface SecurityGroupsV3 {

/**
* Makes the <a href=
*
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#update-a-security-group">Update
* Security Groups</a> request
*
* @param request the Update Security Group request
* @return the response from the List Security Group request
*/
Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest request);

/**
* Makes the <a href=
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#update-a-security-group">Delete
* Security Groups</a> request
*
* @param request the Delete Security Group request
* @return the response from the List Security Group request
*/
Mono<String> delete(DeleteSecurityGroupRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry.client.v3.securitygroups;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.immutables.value.Value;

/**
* The request payload for the Delete Security Group operation
*/
@JsonSerialize
@Value.Immutable
abstract class _DeleteSecurityGroupRequest {

/**
* The Security Group id
*/
@JsonIgnore
abstract String getSecurityGroupId();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.cloudfoundry.client.v3.securitygroups;

import org.junit.Test;

public class DeleteSecurityGroupRequestTest {

@Test(expected = IllegalStateException.class)
public void noSecurityGroupId() {
DeleteSecurityGroupRequest.builder()
.build();
}

@Test
public void valid() {
DeleteSecurityGroupRequest.builder()
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
.build();
}
}

0 comments on commit 53000cb

Please sign in to comment.