Skip to content

Commit c656f6a

Browse files
committed
Merge branch '2.x'
2 parents d94daaa + d9063a3 commit c656f6a

File tree

34 files changed

+1365
-12
lines changed

34 files changed

+1365
-12
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.cloudfoundry.client.v3.organizations.OrganizationsV3;
5757
import org.cloudfoundry.client.v3.packages.Packages;
5858
import org.cloudfoundry.client.v3.processes.Processes;
59+
import org.cloudfoundry.client.v3.serviceInstances.ServiceInstancesV3;
5960
import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3;
6061
import org.cloudfoundry.client.v3.spaces.SpacesV3;
6162
import org.cloudfoundry.client.v3.tasks.Tasks;
@@ -101,6 +102,7 @@
101102
import org.cloudfoundry.reactor.client.v3.packages.ReactorPackages;
102103
import org.cloudfoundry.reactor.client.v3.processes.ReactorProcesses;
103104
import org.cloudfoundry.reactor.client.v3.servicebindings.ReactorServiceBindingsV3;
105+
import org.cloudfoundry.reactor.client.v3.serviceinstances.ReactorServiceInstancesV3;
104106
import org.cloudfoundry.reactor.client.v3.spaces.ReactorSpacesV3;
105107
import org.cloudfoundry.reactor.client.v3.tasks.ReactorTasks;
106108
import org.immutables.value.Value;
@@ -293,6 +295,12 @@ public ServiceInstances serviceInstances() {
293295
return new ReactorServiceInstances(getConnectionContext(), getRootV2(), getTokenProvider());
294296
}
295297

298+
@Override
299+
@Value.Derived
300+
public ServiceInstancesV3 serviceInstancesV3() {
301+
return new ReactorServiceInstancesV3(getConnectionContext(), getRootV3(), getTokenProvider());
302+
}
303+
296304
@Override
297305
@Value.Derived
298306
public ServiceKeys serviceKeys() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2013-2018 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.reactor.client.v3.serviceinstances;
18+
19+
import org.cloudfoundry.client.v3.serviceInstances.ListServiceInstancesRequest;
20+
import org.cloudfoundry.client.v3.serviceInstances.ListServiceInstancesResponse;
21+
import org.cloudfoundry.client.v3.serviceInstances.ListSharedSpacesRelationshipRequest;
22+
import org.cloudfoundry.client.v3.serviceInstances.ListSharedSpacesRelationshipResponse;
23+
import org.cloudfoundry.client.v3.serviceInstances.ServiceInstancesV3;
24+
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceRequest;
25+
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceResponse;
26+
import org.cloudfoundry.client.v3.serviceInstances.UnshareServiceInstanceRequest;
27+
import org.cloudfoundry.reactor.ConnectionContext;
28+
import org.cloudfoundry.reactor.TokenProvider;
29+
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
30+
import reactor.core.publisher.Mono;
31+
32+
/**
33+
* The Reactor-based implementation of {@link ServiceInstancesV3}
34+
*/
35+
public final class ReactorServiceInstancesV3 extends AbstractClientV3Operations implements ServiceInstancesV3 {
36+
37+
/**
38+
* Creates an instance
39+
*
40+
* @param connectionContext the {@link ConnectionContext} to use when communicating with the server
41+
* @param root the root URI of the server. Typically something like {@code https://api.run.pivotal.io}.
42+
* @param tokenProvider the {@link TokenProvider} to use when communicating with the server
43+
*/
44+
public ReactorServiceInstancesV3(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider) {
45+
super(connectionContext, root, tokenProvider);
46+
}
47+
48+
@Override
49+
public Mono<ListServiceInstancesResponse> list(ListServiceInstancesRequest request) {
50+
return get(request, ListServiceInstancesResponse.class, builder -> builder.pathSegment("service_instances"))
51+
.checkpoint();
52+
}
53+
54+
@Override
55+
public Mono<ListSharedSpacesRelationshipResponse> listSharedSpacesRelationship(ListSharedSpacesRelationshipRequest request) {
56+
return get(request, ListSharedSpacesRelationshipResponse.class, builder -> builder.pathSegment("service_instances", request.getServiceInstanceId(), "relationships", "shared_spaces"))
57+
.checkpoint();
58+
}
59+
60+
@Override
61+
public Mono<ShareServiceInstanceResponse> share(ShareServiceInstanceRequest request) {
62+
return post(request, ShareServiceInstanceResponse.class, builder -> builder.pathSegment("service_instances", request.getServiceInstanceId(), "relationships", "shared_spaces"))
63+
.checkpoint();
64+
}
65+
66+
@Override
67+
public Mono<Void> unshare(UnshareServiceInstanceRequest request) {
68+
return delete(request, Void.class, builder -> builder.pathSegment("service_instances", request.getServiceInstanceId(), "relationships", "shared_spaces", request.getSpaceId()))
69+
.checkpoint();
70+
}
71+
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
* Copyright 2013-2018 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.reactor.client.v3.serviceInstances;
18+
19+
import org.cloudfoundry.client.v3.Link;
20+
import org.cloudfoundry.client.v3.Pagination;
21+
import org.cloudfoundry.client.v3.Relationship;
22+
import org.cloudfoundry.client.v3.ToOneRelationship;
23+
import org.cloudfoundry.client.v3.serviceInstances.ListServiceInstancesRequest;
24+
import org.cloudfoundry.client.v3.serviceInstances.ListServiceInstancesResponse;
25+
import org.cloudfoundry.client.v3.serviceInstances.ListSharedSpacesRelationshipRequest;
26+
import org.cloudfoundry.client.v3.serviceInstances.ListSharedSpacesRelationshipResponse;
27+
import org.cloudfoundry.client.v3.serviceInstances.ServiceInstanceRelationships;
28+
import org.cloudfoundry.client.v3.serviceInstances.ServiceInstanceResource;
29+
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceRequest;
30+
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceResponse;
31+
import org.cloudfoundry.client.v3.serviceInstances.UnshareServiceInstanceRequest;
32+
import org.cloudfoundry.reactor.InteractionContext;
33+
import org.cloudfoundry.reactor.TestRequest;
34+
import org.cloudfoundry.reactor.TestResponse;
35+
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
36+
import org.cloudfoundry.reactor.client.v3.serviceinstances.ReactorServiceInstancesV3;
37+
import org.junit.Test;
38+
import reactor.test.StepVerifier;
39+
40+
import java.time.Duration;
41+
42+
import static io.netty.handler.codec.http.HttpMethod.DELETE;
43+
import static io.netty.handler.codec.http.HttpMethod.GET;
44+
import static io.netty.handler.codec.http.HttpMethod.POST;
45+
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
46+
import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT;
47+
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
48+
49+
50+
public final class ReactorServiceInstancesV3Test extends AbstractClientApiTest {
51+
52+
private final ReactorServiceInstancesV3 serviceInstances = new ReactorServiceInstancesV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER);
53+
54+
@Test
55+
public void list() {
56+
mockRequest(InteractionContext.builder()
57+
.request(TestRequest.builder()
58+
.method(GET).path("/service_instances?names=test-service-instance-name&space_guids=test-space-id&page=1")
59+
.build())
60+
.response(TestResponse.builder()
61+
.status(OK)
62+
.payload("fixtures/client/v3/serviceinstances/GET_response.json")
63+
.build())
64+
.build());
65+
66+
this.serviceInstances
67+
.list(ListServiceInstancesRequest.builder()
68+
.page(1)
69+
.serviceInstanceName("test-service-instance-name")
70+
.spaceId("test-space-id")
71+
.build())
72+
.as(StepVerifier::create)
73+
.expectNext(ListServiceInstancesResponse.builder()
74+
.pagination(Pagination.builder()
75+
.totalResults(3)
76+
.first(Link.builder()
77+
.href("/v3/service_instances?page=1&per_page=2")
78+
.build())
79+
.last(Link.builder()
80+
.href("/v3/service_instances?page=2&per_page=2")
81+
.build())
82+
.next(Link.builder()
83+
.href("/v3/service_instances?page=2&per_page=2")
84+
.build())
85+
.build())
86+
.resource(ServiceInstanceResource.builder()
87+
.id("85ccdcad-d725-4109-bca4-fd6ba062b5c8")
88+
.createdAt("2017-11-17T13:54:21Z")
89+
.name("my_service_instance1")
90+
.relationships(ServiceInstanceRelationships.builder()
91+
.space(ToOneRelationship.builder()
92+
.data(Relationship.builder()
93+
.id("ae0031f9-dd49-461c-a945-df40e77c39cb")
94+
.build())
95+
.build())
96+
.build())
97+
.link("space", Link.builder()
98+
.href("/v3/spaces/ae0031f9-dd49-461c-a945-df40e77c39cb")
99+
.build())
100+
.build())
101+
.resource(ServiceInstanceResource.builder()
102+
.id("85ccdcad-d725-4109-bca4-fd6ba062b5c7")
103+
.createdAt("2017-11-17T13:54:21Z")
104+
.name("my_service_instance2")
105+
.relationships(ServiceInstanceRelationships.builder()
106+
.space(ToOneRelationship.builder()
107+
.data(Relationship.builder()
108+
.id("ae0031f9-dd49-461c-a945-df40e77c39ce")
109+
.build())
110+
.build())
111+
.build())
112+
.link("space", Link.builder()
113+
.href("/v3/spaces/ae0031f9-dd49-461c-a945-df40e77c39ce")
114+
.build())
115+
.build())
116+
.resource(ServiceInstanceResource.builder()
117+
.id("85ccdcad-d725-4109-bca4-fd6ba062b5c6")
118+
.createdAt("2017-11-17T13:54:21Z")
119+
.name("my_service_instance3")
120+
.relationships(ServiceInstanceRelationships.builder()
121+
.space(ToOneRelationship.builder()
122+
.data(Relationship.builder()
123+
.id("ae0031f9-dd49-461c-a945-df40e77c39cf")
124+
.build())
125+
.build())
126+
.build())
127+
.link("space", Link.builder()
128+
.href("/v3/spaces/ae0031f9-dd49-461c-a945-df40e77c39cf")
129+
.build())
130+
.build())
131+
.build())
132+
.expectComplete()
133+
.verify(Duration.ofSeconds(5));
134+
}
135+
136+
@Test
137+
public void listSharedSpaces() {
138+
mockRequest(InteractionContext.builder()
139+
.request(TestRequest.builder()
140+
.method(GET).path("/service_instances/test-service-instance-id/relationships/shared_spaces")
141+
.build())
142+
.response(TestResponse.builder()
143+
.status(OK)
144+
.payload("fixtures/client/v3/serviceinstances/GET_{id}_relationships_spaces_shared_response.json")
145+
.build())
146+
.build());
147+
148+
this.serviceInstances
149+
.listSharedSpacesRelationship(ListSharedSpacesRelationshipRequest.builder()
150+
.serviceInstanceId("test-service-instance-id")
151+
.build())
152+
.as(StepVerifier::create)
153+
.expectNext(ListSharedSpacesRelationshipResponse.builder()
154+
.data(Relationship.builder()
155+
.id("68d54d31-9b3a-463b-ba94-e8e4c32edbac")
156+
.build())
157+
.data(Relationship.builder()
158+
.id("b19f6525-cbd3-4155-b156-dc0c2a431b4c")
159+
.build())
160+
.link("self", Link.builder()
161+
.href("/v3/service_instances/bdeg4371-cbd3-4155-b156-dc0c2a431b4c/relationships/shared_spaces")
162+
.build())
163+
.build())
164+
.expectComplete()
165+
.verify(Duration.ofSeconds(5));
166+
}
167+
168+
@Test
169+
public void share() {
170+
mockRequest(InteractionContext.builder()
171+
.request(TestRequest.builder()
172+
.method(POST).path("/service_instances/test-service-instance-id/relationships/shared_spaces")
173+
.payload("fixtures/client/v3/serviceinstances/POST_request.json")
174+
.build())
175+
.response(TestResponse.builder()
176+
.status(CREATED)
177+
.payload("fixtures/client/v3/serviceinstances/POST_response.json")
178+
.build())
179+
.build());
180+
181+
this.serviceInstances
182+
.share(ShareServiceInstanceRequest.builder()
183+
.serviceInstanceId("test-service-instance-id")
184+
.data(Relationship.builder()
185+
.id("space-guid-1")
186+
.build())
187+
.data(Relationship.builder()
188+
.id("space-guid-2")
189+
.build())
190+
.build())
191+
.as(StepVerifier::create)
192+
.expectNext(ShareServiceInstanceResponse.builder()
193+
.data(Relationship.builder()
194+
.id("68d54d31-9b3a-463b-ba94-e8e4c32edbac")
195+
.build())
196+
.data(Relationship.builder()
197+
.id("b19f6525-cbd3-4155-b156-dc0c2a431b4c")
198+
.build())
199+
.link("self", Link.builder()
200+
.href("https://api.example.org/v3/service_instances/bdeg4371-cbd3-4155-b156-dc0c2a431b4c/relationships/shared_spaces")
201+
.build())
202+
.build())
203+
.expectComplete()
204+
.verify(Duration.ofSeconds(5));
205+
}
206+
207+
@Test
208+
public void unshare() {
209+
mockRequest(InteractionContext.builder()
210+
.request(TestRequest.builder()
211+
.method(DELETE).path("/service_instances/test-service-instance-id/relationships/shared_spaces/test-space-id")
212+
.build())
213+
.response(TestResponse.builder()
214+
.status(NO_CONTENT)
215+
.build())
216+
.build());
217+
218+
this.serviceInstances
219+
.unshare(UnshareServiceInstanceRequest.builder()
220+
.serviceInstanceId("test-service-instance-id")
221+
.spaceId("test-space-id")
222+
.build())
223+
.as(StepVerifier::create)
224+
.expectComplete()
225+
.verify(Duration.ofSeconds(5));
226+
}
227+
}

0 commit comments

Comments
 (0)