Skip to content

Commit badb304

Browse files
Apply organization and space quota (#1330)
* Implement apply organization quota * Implement apply and remove space quota Signed-off-by: Daniel Garnier-Moiroux <daniel.garnier-moiroux@broadcom.com>
1 parent 59d0e90 commit badb304

File tree

32 files changed

+787
-36
lines changed

32 files changed

+787
-36
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/quotas/organizations/ReactorOrganizationQuotasV3.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,18 @@ public Mono<String> delete(DeleteOrganizationQuotaRequest request) {
9494
"organization_quotas", request.getOrganizationQuotaId()))
9595
.checkpoint();
9696
}
97+
98+
@Override
99+
public Mono<ApplyOrganizationQuotaResponse> apply(ApplyOrganizationQuotaRequest request) {
100+
return post(
101+
request,
102+
ApplyOrganizationQuotaResponse.class,
103+
builder ->
104+
builder.pathSegment(
105+
"organization_quotas",
106+
request.getOrganizationQuotaId(),
107+
"relationships",
108+
"organizations"))
109+
.checkpoint();
110+
}
97111
}

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/quotas/spaces/ReactorSpaceQuotasV3.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,33 @@ public Mono<String> delete(DeleteSpaceQuotaRequest request) {
8787
builder -> builder.pathSegment("space_quotas", request.getSpaceQuotaId()))
8888
.checkpoint();
8989
}
90+
91+
@Override
92+
public Mono<ApplySpaceQuotaResponse> apply(ApplySpaceQuotaRequest request) {
93+
return post(
94+
request,
95+
ApplySpaceQuotaResponse.class,
96+
builder ->
97+
builder.pathSegment(
98+
"space_quotas",
99+
request.getSpaceQuotaId(),
100+
"relationships",
101+
"spaces"))
102+
.checkpoint();
103+
}
104+
105+
@Override
106+
public Mono<Void> remove(RemoveSpaceQuotaRequest request) {
107+
return delete(
108+
request,
109+
Void.class,
110+
builder ->
111+
builder.pathSegment(
112+
"space_quotas",
113+
request.getSpaceQuotaId(),
114+
"relationships",
115+
"spaces",
116+
request.getSpaceId()))
117+
.checkpoint();
118+
}
90119
}

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/quotas/organizations/ReactorOrganizationQuotasV3Test.java

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222

2323
import java.time.Duration;
2424
import java.util.Collections;
25+
import java.util.Map;
2526
import org.cloudfoundry.client.v3.Link;
2627
import org.cloudfoundry.client.v3.Pagination;
2728
import org.cloudfoundry.client.v3.Relationship;
2829
import org.cloudfoundry.client.v3.ToManyRelationship;
29-
import org.cloudfoundry.client.v3.quotas.*;
30+
import org.cloudfoundry.client.v3.quotas.Apps;
31+
import org.cloudfoundry.client.v3.quotas.Routes;
32+
import org.cloudfoundry.client.v3.quotas.Services;
3033
import org.cloudfoundry.client.v3.quotas.organizations.*;
3134
import org.cloudfoundry.reactor.InteractionContext;
3235
import org.cloudfoundry.reactor.TestRequest;
@@ -51,13 +54,13 @@ void create() {
5154
.method(POST)
5255
.path("/organization_quotas")
5356
.payload(
54-
"fixtures/client/v3/organization_quotas/POST_request.json")
57+
"fixtures/client/v3/quotas/organizations/POST_request.json")
5558
.build())
5659
.response(
5760
TestResponse.builder()
5861
.status(OK)
5962
.payload(
60-
"fixtures/client/v3/organization_quotas/POST_response.json")
63+
"fixtures/client/v3/quotas/organizations/POST_response.json")
6164
.build())
6265
.build());
6366

@@ -115,7 +118,7 @@ void get() {
115118
TestResponse.builder()
116119
.status(OK)
117120
.payload(
118-
"fixtures/client/v3/organization_quotas/GET_{id}_response.json")
121+
"fixtures/client/v3/quotas/organizations/GET_{id}_response.json")
119122
.build())
120123
.build());
121124

@@ -146,7 +149,7 @@ void list() {
146149
TestResponse.builder()
147150
.status(OK)
148151
.payload(
149-
"fixtures/client/v3/organization_quotas/GET_response.json")
152+
"fixtures/client/v3/quotas/organizations/GET_response.json")
150153
.build())
151154
.build());
152155

@@ -193,13 +196,13 @@ void update() {
193196
.path(
194197
"/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52")
195198
.payload(
196-
"fixtures/client/v3/organization_quotas/PATCH_{id}_request.json")
199+
"fixtures/client/v3/quotas/organizations/PATCH_{id}_request.json")
197200
.build())
198201
.response(
199202
TestResponse.builder()
200203
.status(OK)
201204
.payload(
202-
"fixtures/client/v3/organization_quotas/PATCH_{id}_response.json")
205+
"fixtures/client/v3/quotas/organizations/PATCH_{id}_response.json")
203206
.build())
204207
.build());
205208

@@ -217,6 +220,47 @@ void update() {
217220
.verify(Duration.ofSeconds(5));
218221
}
219222

223+
@Test
224+
void apply() {
225+
mockRequest(
226+
InteractionContext.builder()
227+
.request(
228+
TestRequest.builder()
229+
.method(POST)
230+
.path(
231+
"/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/organizations")
232+
.payload(
233+
"fixtures/client/v3/quotas/organizations/relationships/POST_{id}_request.json")
234+
.build())
235+
.response(
236+
TestResponse.builder()
237+
.status(OK)
238+
.payload(
239+
"fixtures/client/v3/quotas/organizations/relationships/POST_{id}_response.json")
240+
.build())
241+
.build());
242+
243+
Relationship org1 = Relationship.builder().id("org-guid1").build();
244+
Relationship org2 = Relationship.builder().id("org-guid2").build();
245+
246+
ToManyRelationship organizationRelationships =
247+
ToManyRelationship.builder().data(org1, org2).build();
248+
249+
this.organizationQuotasV3
250+
.apply(
251+
ApplyOrganizationQuotaRequest.builder()
252+
.organizationQuotaId("24637893-3b77-489d-bb79-8466f0d88b52")
253+
.organizationRelationships(organizationRelationships)
254+
.build())
255+
.as(StepVerifier::create)
256+
.expectNext(
257+
ApplyOrganizationQuotaResponse.builder()
258+
.from(expectedApplyOrganizationQuotaResponse())
259+
.build())
260+
.expectComplete()
261+
.verify(Duration.ofSeconds(5));
262+
}
263+
220264
@NotNull
221265
private static OrganizationQuotaResource expectedOrganizationQuotaResource1() {
222266
return buildOrganizationQuotaResource(
@@ -232,6 +276,28 @@ private static OrganizationQuotaResource expectedOrganizationQuotaResource2() {
232276
"144251f2-a202-4ffe-ab47-9046c4077e99");
233277
}
234278

279+
@NotNull
280+
private static ApplyOrganizationQuotaResponse expectedApplyOrganizationQuotaResponse() {
281+
282+
Relationship org1 = Relationship.builder().id("org-guid1").build();
283+
Relationship org2 = Relationship.builder().id("org-guid2").build();
284+
Relationship existingOrg = Relationship.builder().id("previous-org-guid").build();
285+
286+
ToManyRelationship organizationRelationships =
287+
ToManyRelationship.builder().data(org1, org2, existingOrg).build();
288+
Link selfLink =
289+
Link.builder()
290+
.href(
291+
"https://api.example.org/v3/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/organizations")
292+
.build();
293+
Map<String, Link> links = Collections.singletonMap("self", selfLink);
294+
295+
return ApplyOrganizationQuotaResponse.builder()
296+
.organizationRelationships(organizationRelationships)
297+
.links(links)
298+
.build();
299+
}
300+
235301
@NotNull
236302
private static OrganizationQuotaResource buildOrganizationQuotaResource(
237303
String id, String name, String relatedOrganizationId) {

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/quotas/spaces/ReactorSpaceQuotasV3Test.java

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616

1717
package org.cloudfoundry.reactor.client.v3.quotas.spaces;
1818

19-
import static io.netty.handler.codec.http.HttpMethod.DELETE;
20-
import static io.netty.handler.codec.http.HttpMethod.GET;
21-
import static io.netty.handler.codec.http.HttpMethod.PATCH;
22-
import static io.netty.handler.codec.http.HttpMethod.POST;
23-
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
24-
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
19+
import static io.netty.handler.codec.http.HttpMethod.*;
20+
import static io.netty.handler.codec.http.HttpResponseStatus.*;
2521

2622
import java.time.Duration;
2723
import java.util.Collections;
28-
import org.cloudfoundry.client.v3.Link;
29-
import org.cloudfoundry.client.v3.Pagination;
30-
import org.cloudfoundry.client.v3.Relationship;
31-
import org.cloudfoundry.client.v3.ToManyRelationship;
32-
import org.cloudfoundry.client.v3.ToOneRelationship;
33-
import org.cloudfoundry.client.v3.quotas.*;
24+
import java.util.Map;
25+
import org.cloudfoundry.client.v3.*;
26+
import org.cloudfoundry.client.v3.quotas.Apps;
27+
import org.cloudfoundry.client.v3.quotas.Routes;
28+
import org.cloudfoundry.client.v3.quotas.Services;
3429
import org.cloudfoundry.client.v3.quotas.spaces.*;
3530
import org.cloudfoundry.reactor.InteractionContext;
3631
import org.cloudfoundry.reactor.TestRequest;
@@ -57,13 +52,13 @@ void create() {
5752
.method(POST)
5853
.path("/space_quotas")
5954
.payload(
60-
"fixtures/client/v3/space_quotas/POST_request.json")
55+
"fixtures/client/v3/quotas/spaces/POST_request.json")
6156
.build())
6257
.response(
6358
TestResponse.builder()
6459
.status(OK)
6560
.payload(
66-
"fixtures/client/v3/space_quotas/POST_response.json")
61+
"fixtures/client/v3/quotas/spaces/POST_response.json")
6762
.build())
6863
.build());
6964

@@ -143,7 +138,7 @@ void get() {
143138
TestResponse.builder()
144139
.status(OK)
145140
.payload(
146-
"fixtures/client/v3/space_quotas/GET_{id}_response.json")
141+
"fixtures/client/v3/quotas/spaces/GET_{id}_response.json")
147142
.build())
148143
.build());
149144

@@ -165,7 +160,7 @@ void list() {
165160
TestResponse.builder()
166161
.status(OK)
167162
.payload(
168-
"fixtures/client/v3/space_quotas/GET_response.json")
163+
"fixtures/client/v3/quotas/spaces/GET_response.json")
169164
.build())
170165
.build());
171166

@@ -211,13 +206,13 @@ void update() {
211206
.method(PATCH)
212207
.path("/space_quotas/" + EXPECTED_SPACE_QUOTA_ID_1)
213208
.payload(
214-
"fixtures/client/v3/space_quotas/PATCH_{id}_request.json")
209+
"fixtures/client/v3/quotas/spaces/PATCH_{id}_request.json")
215210
.build())
216211
.response(
217212
TestResponse.builder()
218213
.status(OK)
219214
.payload(
220-
"fixtures/client/v3/space_quotas/PATCH_{id}_response.json")
215+
"fixtures/client/v3/quotas/spaces/PATCH_{id}_response.json")
221216
.build())
222217
.build());
223218

@@ -235,6 +230,71 @@ void update() {
235230
.verify(Duration.ofSeconds(5));
236231
}
237232

233+
@Test
234+
void apply() {
235+
mockRequest(
236+
InteractionContext.builder()
237+
.request(
238+
TestRequest.builder()
239+
.method(POST)
240+
.path(
241+
"/space_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/spaces")
242+
.payload(
243+
"fixtures/client/v3/quotas/spaces/relationships/POST_{id}_request.json")
244+
.build())
245+
.response(
246+
TestResponse.builder()
247+
.status(OK)
248+
.payload(
249+
"fixtures/client/v3/quotas/spaces/relationships/POST_{id}_response.json")
250+
.build())
251+
.build());
252+
253+
Relationship space1 = Relationship.builder().id("space-guid1").build();
254+
Relationship space2 = Relationship.builder().id("space-guid2").build();
255+
256+
ToManyRelationship organizationRelationships =
257+
ToManyRelationship.builder().data(space1, space2).build();
258+
259+
this.spaceQuotasV3
260+
.apply(
261+
ApplySpaceQuotaRequest.builder()
262+
.spaceQuotaId("24637893-3b77-489d-bb79-8466f0d88b52")
263+
.spaceRelationships(organizationRelationships)
264+
.build())
265+
.as(StepVerifier::create)
266+
.expectNext(
267+
ApplySpaceQuotaResponse.builder()
268+
.from(expectedApplySpaceQuotaResponse())
269+
.build())
270+
.expectComplete()
271+
.verify(Duration.ofSeconds(5));
272+
}
273+
274+
@Test
275+
void remove() {
276+
mockRequest(
277+
InteractionContext.builder()
278+
.request(
279+
TestRequest.builder()
280+
.method(DELETE)
281+
.path(
282+
"/space_quotas/test-space-quota-id/relationships/spaces/test-space-guid")
283+
.build())
284+
.response(TestResponse.builder().status(NO_CONTENT).build())
285+
.build());
286+
287+
this.spaceQuotasV3
288+
.remove(
289+
RemoveSpaceQuotaRequest.builder()
290+
.spaceQuotaId("test-space-quota-id")
291+
.spaceId("test-space-guid")
292+
.build())
293+
.as(StepVerifier::create)
294+
.expectComplete()
295+
.verify(Duration.ofSeconds(5));
296+
}
297+
238298
@NotNull
239299
private static SpaceQuotaResource expectedSpaceQuotaResource1() {
240300
return buildSpaceQuotaResource(
@@ -252,6 +312,28 @@ private static SpaceQuotaResource expectedSpaceQuotaResource2() {
252312
null);
253313
}
254314

315+
@NotNull
316+
private static ApplySpaceQuotaResponse expectedApplySpaceQuotaResponse() {
317+
318+
Relationship space1 = Relationship.builder().id("space-guid1").build();
319+
Relationship space2 = Relationship.builder().id("space-guid2").build();
320+
Relationship existingSpace = Relationship.builder().id("previous-space-guid").build();
321+
322+
ToManyRelationship spaceRelationships =
323+
ToManyRelationship.builder().data(space1, space2, existingSpace).build();
324+
Link selfLink =
325+
Link.builder()
326+
.href(
327+
"https://api.example.org/v3/space_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/spaces")
328+
.build();
329+
Map<String, Link> links = Collections.singletonMap("self", selfLink);
330+
331+
return ApplySpaceQuotaResponse.builder()
332+
.spaceRelationships(spaceRelationships)
333+
.links(links)
334+
.build();
335+
}
336+
255337
@NotNull
256338
private static SpaceQuotaResource buildSpaceQuotaResource(
257339
String id, String name, String relatedOrganizationId, String relatedSpaceId) {

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/GET_response.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/GET_response.json

File renamed without changes.

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/GET_{id}_response.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/GET_{id}_response.json

File renamed without changes.

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/PATCH_{id}_request.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/PATCH_{id}_request.json

File renamed without changes.

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/PATCH_{id}_response.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/PATCH_{id}_response.json

File renamed without changes.

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/POST_request.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/POST_request.json

File renamed without changes.

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/organization_quotas/POST_response.json renamed to cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/quotas/organizations/POST_response.json

File renamed without changes.

0 commit comments

Comments
 (0)