Skip to content

Commit 53000cb

Browse files
adding security groups delete api v3 impl and tests
1 parent 1a907f3 commit 53000cb

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest;
2121
import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse;
2222
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
23+
import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest;
2324
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest;
2425
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse;
2526
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse;
@@ -81,4 +82,12 @@ public Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest reque
8182
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId()))
8283
.checkpoint();
8384
}
85+
86+
@Override
87+
public Mono<String> delete(DeleteSecurityGroupRequest request) {
88+
return delete(request, String.class,
89+
builder -> builder.pathSegment("security_groups", request.getSecurityGroupId()))
90+
.checkpoint();
91+
92+
}
8493
}

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse;
3030
import org.cloudfoundry.client.v3.securitygroups.Protocol;
3131
import org.cloudfoundry.client.v3.securitygroups.Rule;
32+
import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest;
3233
import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest;
3334
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest;
3435
import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse;
@@ -44,10 +45,12 @@
4445
import java.util.Collections;
4546

4647
import static io.netty.handler.codec.http.HttpMethod.GET;
48+
import static io.netty.handler.codec.http.HttpMethod.DELETE;;
4749
import static io.netty.handler.codec.http.HttpMethod.PATCH;
4850
import static io.netty.handler.codec.http.HttpMethod.POST;
4951
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
5052
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
53+
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;;
5154

5255
public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest {
5356

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

352355
}
356+
357+
@Test
358+
public void delete() {
359+
mockRequest(InteractionContext.builder()
360+
.request(TestRequest.builder()
361+
.method(DELETE)
362+
.path("/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
363+
.build())
364+
.response(TestResponse.builder()
365+
.status(ACCEPTED)
366+
.header("Location",
367+
"https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a")
368+
.build())
369+
.build());
370+
371+
this.securityGroups
372+
.delete(DeleteSecurityGroupRequest.builder()
373+
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
374+
.build())
375+
.as(StepVerifier::create)
376+
.expectNext("b85a788e-671f-4549-814d-e34cdb2f539a")
377+
.expectComplete()
378+
.verify(Duration.ofSeconds(5));
379+
}
353380
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public interface SecurityGroupsV3 {
4242

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

5453
/**
5554
* Makes the <a href=
56-
*
5755
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#update-a-security-group">Update
5856
* Security Groups</a> request
5957
*
6058
* @param request the Update Security Group request
6159
* @return the response from the List Security Group request
6260
*/
6361
Mono<UpdateSecurityGroupResponse> update(UpdateSecurityGroupRequest request);
62+
63+
/**
64+
* Makes the <a href=
65+
* "https://v3-apidocs.cloudfoundry.org/version/3.140.0/index.html#update-a-security-group">Delete
66+
* Security Groups</a> request
67+
*
68+
* @param request the Delete Security Group request
69+
* @return the response from the List Security Group request
70+
*/
71+
Mono<String> delete(DeleteSecurityGroupRequest request);
6472
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2013-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3.securitygroups;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
20+
import com.fasterxml.jackson.annotation.JsonIgnore;
21+
import org.immutables.value.Value;
22+
23+
/**
24+
* The request payload for the Delete Security Group operation
25+
*/
26+
@JsonSerialize
27+
@Value.Immutable
28+
abstract class _DeleteSecurityGroupRequest {
29+
30+
/**
31+
* The Security Group id
32+
*/
33+
@JsonIgnore
34+
abstract String getSecurityGroupId();
35+
36+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.cloudfoundry.client.v3.securitygroups;
2+
3+
import org.junit.Test;
4+
5+
public class DeleteSecurityGroupRequestTest {
6+
7+
@Test(expected = IllegalStateException.class)
8+
public void noSecurityGroupId() {
9+
DeleteSecurityGroupRequest.builder()
10+
.build();
11+
}
12+
13+
@Test
14+
public void valid() {
15+
DeleteSecurityGroupRequest.builder()
16+
.securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a")
17+
.build();
18+
}
19+
}

0 commit comments

Comments
 (0)