|
| 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