Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ public Mono<String> delete(DeleteOrganizationQuotaRequest request) {
"organization_quotas", request.getOrganizationQuotaId()))
.checkpoint();
}

@Override
public Mono<ApplyOrganizationQuotaResponse> apply(ApplyOrganizationQuotaRequest request) {
return post(
request,
ApplyOrganizationQuotaResponse.class,
builder ->
builder.pathSegment(
"organization_quotas",
request.getOrganizationQuotaId(),
"relationships",
"organizations"))
.checkpoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,33 @@ public Mono<String> delete(DeleteSpaceQuotaRequest request) {
builder -> builder.pathSegment("space_quotas", request.getSpaceQuotaId()))
.checkpoint();
}

@Override
public Mono<ApplySpaceQuotaResponse> apply(ApplySpaceQuotaRequest request) {
return post(
request,
ApplySpaceQuotaResponse.class,
builder ->
builder.pathSegment(
"space_quotas",
request.getSpaceQuotaId(),
"relationships",
"spaces"))
.checkpoint();
}

@Override
public Mono<Void> remove(RemoveSpaceQuotaRequest request) {
return delete(
request,
Void.class,
builder ->
builder.pathSegment(
"space_quotas",
request.getSpaceQuotaId(),
"relationships",
"spaces",
request.getSpaceId()))
.checkpoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

import java.time.Duration;
import java.util.Collections;
import java.util.Map;
import org.cloudfoundry.client.v3.Link;
import org.cloudfoundry.client.v3.Pagination;
import org.cloudfoundry.client.v3.Relationship;
import org.cloudfoundry.client.v3.ToManyRelationship;
import org.cloudfoundry.client.v3.quotas.*;
import org.cloudfoundry.client.v3.quotas.Apps;
import org.cloudfoundry.client.v3.quotas.Routes;
import org.cloudfoundry.client.v3.quotas.Services;
import org.cloudfoundry.client.v3.quotas.organizations.*;
import org.cloudfoundry.reactor.InteractionContext;
import org.cloudfoundry.reactor.TestRequest;
Expand All @@ -51,13 +54,13 @@ void create() {
.method(POST)
.path("/organization_quotas")
.payload(
"fixtures/client/v3/organization_quotas/POST_request.json")
"fixtures/client/v3/quotas/organizations/POST_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/organization_quotas/POST_response.json")
"fixtures/client/v3/quotas/organizations/POST_response.json")
.build())
.build());

Expand Down Expand Up @@ -115,7 +118,7 @@ void get() {
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/organization_quotas/GET_{id}_response.json")
"fixtures/client/v3/quotas/organizations/GET_{id}_response.json")
.build())
.build());

Expand Down Expand Up @@ -146,7 +149,7 @@ void list() {
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/organization_quotas/GET_response.json")
"fixtures/client/v3/quotas/organizations/GET_response.json")
.build())
.build());

Expand Down Expand Up @@ -193,13 +196,13 @@ void update() {
.path(
"/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52")
.payload(
"fixtures/client/v3/organization_quotas/PATCH_{id}_request.json")
"fixtures/client/v3/quotas/organizations/PATCH_{id}_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/organization_quotas/PATCH_{id}_response.json")
"fixtures/client/v3/quotas/organizations/PATCH_{id}_response.json")
.build())
.build());

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

@Test
void apply() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(POST)
.path(
"/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/organizations")
.payload(
"fixtures/client/v3/quotas/organizations/relationships/POST_{id}_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/quotas/organizations/relationships/POST_{id}_response.json")
.build())
.build());

Relationship org1 = Relationship.builder().id("org-guid1").build();
Relationship org2 = Relationship.builder().id("org-guid2").build();

ToManyRelationship organizationRelationships =
ToManyRelationship.builder().data(org1, org2).build();

this.organizationQuotasV3
.apply(
ApplyOrganizationQuotaRequest.builder()
.organizationQuotaId("24637893-3b77-489d-bb79-8466f0d88b52")
.organizationRelationships(organizationRelationships)
.build())
.as(StepVerifier::create)
.expectNext(
ApplyOrganizationQuotaResponse.builder()
.from(expectedApplyOrganizationQuotaResponse())
.build())
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@NotNull
private static OrganizationQuotaResource expectedOrganizationQuotaResource1() {
return buildOrganizationQuotaResource(
Expand All @@ -232,6 +276,28 @@ private static OrganizationQuotaResource expectedOrganizationQuotaResource2() {
"144251f2-a202-4ffe-ab47-9046c4077e99");
}

@NotNull
private static ApplyOrganizationQuotaResponse expectedApplyOrganizationQuotaResponse() {

Relationship org1 = Relationship.builder().id("org-guid1").build();
Relationship org2 = Relationship.builder().id("org-guid2").build();
Relationship existingOrg = Relationship.builder().id("previous-org-guid").build();

ToManyRelationship organizationRelationships =
ToManyRelationship.builder().data(org1, org2, existingOrg).build();
Link selfLink =
Link.builder()
.href(
"https://api.example.org/v3/organization_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/organizations")
.build();
Map<String, Link> links = Collections.singletonMap("self", selfLink);

return ApplyOrganizationQuotaResponse.builder()
.organizationRelationships(organizationRelationships)
.links(links)
.build();
}

@NotNull
private static OrganizationQuotaResource buildOrganizationQuotaResource(
String id, String name, String relatedOrganizationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@

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

import static io.netty.handler.codec.http.HttpMethod.DELETE;
import static io.netty.handler.codec.http.HttpMethod.GET;
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.ACCEPTED;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;

import java.time.Duration;
import java.util.Collections;
import org.cloudfoundry.client.v3.Link;
import org.cloudfoundry.client.v3.Pagination;
import org.cloudfoundry.client.v3.Relationship;
import org.cloudfoundry.client.v3.ToManyRelationship;
import org.cloudfoundry.client.v3.ToOneRelationship;
import org.cloudfoundry.client.v3.quotas.*;
import java.util.Map;
import org.cloudfoundry.client.v3.*;
import org.cloudfoundry.client.v3.quotas.Apps;
import org.cloudfoundry.client.v3.quotas.Routes;
import org.cloudfoundry.client.v3.quotas.Services;
import org.cloudfoundry.client.v3.quotas.spaces.*;
import org.cloudfoundry.reactor.InteractionContext;
import org.cloudfoundry.reactor.TestRequest;
Expand All @@ -57,13 +52,13 @@ void create() {
.method(POST)
.path("/space_quotas")
.payload(
"fixtures/client/v3/space_quotas/POST_request.json")
"fixtures/client/v3/quotas/spaces/POST_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/space_quotas/POST_response.json")
"fixtures/client/v3/quotas/spaces/POST_response.json")
.build())
.build());

Expand Down Expand Up @@ -143,7 +138,7 @@ void get() {
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/space_quotas/GET_{id}_response.json")
"fixtures/client/v3/quotas/spaces/GET_{id}_response.json")
.build())
.build());

Expand All @@ -165,7 +160,7 @@ void list() {
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/space_quotas/GET_response.json")
"fixtures/client/v3/quotas/spaces/GET_response.json")
.build())
.build());

Expand Down Expand Up @@ -211,13 +206,13 @@ void update() {
.method(PATCH)
.path("/space_quotas/" + EXPECTED_SPACE_QUOTA_ID_1)
.payload(
"fixtures/client/v3/space_quotas/PATCH_{id}_request.json")
"fixtures/client/v3/quotas/spaces/PATCH_{id}_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/space_quotas/PATCH_{id}_response.json")
"fixtures/client/v3/quotas/spaces/PATCH_{id}_response.json")
.build())
.build());

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

@Test
void apply() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(POST)
.path(
"/space_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/spaces")
.payload(
"fixtures/client/v3/quotas/spaces/relationships/POST_{id}_request.json")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/quotas/spaces/relationships/POST_{id}_response.json")
.build())
.build());

Relationship space1 = Relationship.builder().id("space-guid1").build();
Relationship space2 = Relationship.builder().id("space-guid2").build();

ToManyRelationship organizationRelationships =
ToManyRelationship.builder().data(space1, space2).build();

this.spaceQuotasV3
.apply(
ApplySpaceQuotaRequest.builder()
.spaceQuotaId("24637893-3b77-489d-bb79-8466f0d88b52")
.spaceRelationships(organizationRelationships)
.build())
.as(StepVerifier::create)
.expectNext(
ApplySpaceQuotaResponse.builder()
.from(expectedApplySpaceQuotaResponse())
.build())
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@Test
void remove() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(DELETE)
.path(
"/space_quotas/test-space-quota-id/relationships/spaces/test-space-guid")
.build())
.response(TestResponse.builder().status(NO_CONTENT).build())
.build());

this.spaceQuotasV3
.remove(
RemoveSpaceQuotaRequest.builder()
.spaceQuotaId("test-space-quota-id")
.spaceId("test-space-guid")
.build())
.as(StepVerifier::create)
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@NotNull
private static SpaceQuotaResource expectedSpaceQuotaResource1() {
return buildSpaceQuotaResource(
Expand All @@ -252,6 +312,28 @@ private static SpaceQuotaResource expectedSpaceQuotaResource2() {
null);
}

@NotNull
private static ApplySpaceQuotaResponse expectedApplySpaceQuotaResponse() {

Relationship space1 = Relationship.builder().id("space-guid1").build();
Relationship space2 = Relationship.builder().id("space-guid2").build();
Relationship existingSpace = Relationship.builder().id("previous-space-guid").build();

ToManyRelationship spaceRelationships =
ToManyRelationship.builder().data(space1, space2, existingSpace).build();
Link selfLink =
Link.builder()
.href(
"https://api.example.org/v3/space_quotas/24637893-3b77-489d-bb79-8466f0d88b52/relationships/spaces")
.build();
Map<String, Link> links = Collections.singletonMap("self", selfLink);

return ApplySpaceQuotaResponse.builder()
.spaceRelationships(spaceRelationships)
.links(links)
.build();
}

@NotNull
private static SpaceQuotaResource buildSpaceQuotaResource(
String id, String name, String relatedOrganizationId, String relatedSpaceId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": [
{
"guid": "org-guid1"
},
{
"guid": "org-guid2"
}
]
}
Loading
Loading