|
| 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.deployments; |
| 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.deployments.CancelDeploymentRequest; |
| 24 | +import org.cloudfoundry.client.v3.deployments.CreateDeploymentRequest; |
| 25 | +import org.cloudfoundry.client.v3.deployments.CreateDeploymentResponse; |
| 26 | +import org.cloudfoundry.client.v3.deployments.DeploymentRelationships; |
| 27 | +import org.cloudfoundry.client.v3.deployments.DeploymentResource; |
| 28 | +import org.cloudfoundry.client.v3.deployments.DeploymentState; |
| 29 | +import org.cloudfoundry.client.v3.deployments.GetDeploymentRequest; |
| 30 | +import org.cloudfoundry.client.v3.deployments.GetDeploymentResponse; |
| 31 | +import org.cloudfoundry.client.v3.deployments.ListDeploymentsRequest; |
| 32 | +import org.cloudfoundry.client.v3.deployments.ListDeploymentsResponse; |
| 33 | +import org.cloudfoundry.client.v3.deployments.Process; |
| 34 | +import org.cloudfoundry.client.v3.deployments.Revision; |
| 35 | +import org.cloudfoundry.reactor.InteractionContext; |
| 36 | +import org.cloudfoundry.reactor.TestRequest; |
| 37 | +import org.cloudfoundry.reactor.TestResponse; |
| 38 | +import org.cloudfoundry.reactor.client.AbstractClientApiTest; |
| 39 | +import org.junit.Test; |
| 40 | +import reactor.test.StepVerifier; |
| 41 | + |
| 42 | +import java.time.Duration; |
| 43 | + |
| 44 | +import static io.netty.handler.codec.http.HttpMethod.GET; |
| 45 | +import static io.netty.handler.codec.http.HttpMethod.POST; |
| 46 | +import static io.netty.handler.codec.http.HttpResponseStatus.OK; |
| 47 | +import static java.util.Collections.singletonList; |
| 48 | + |
| 49 | +public class ReactorDeploymentsV3Test extends AbstractClientApiTest { |
| 50 | + |
| 51 | + private final ReactorDeploymentsV3 deployments = new ReactorDeploymentsV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER); |
| 52 | + |
| 53 | + @Test |
| 54 | + public void cancel() { |
| 55 | + mockRequest(InteractionContext.builder() |
| 56 | + .request(TestRequest.builder() |
| 57 | + .method(POST).path("/deployments/test-deployment-id/actions/cancel") |
| 58 | + .payload("fixtures/client/v3/deployments/POST_{id}_cancel_request.json") |
| 59 | + .build()) |
| 60 | + .response(TestResponse.builder() |
| 61 | + .status(OK) |
| 62 | + .build()) |
| 63 | + .build()); |
| 64 | + |
| 65 | + this.deployments |
| 66 | + .cancel(CancelDeploymentRequest.builder() |
| 67 | + .deploymentId("test-deployment-id") |
| 68 | + .build()) |
| 69 | + .as(StepVerifier::create) |
| 70 | + .expectComplete() |
| 71 | + .verify(Duration.ofSeconds(5)); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void create() { |
| 76 | + mockRequest(InteractionContext.builder() |
| 77 | + .request(TestRequest.builder() |
| 78 | + .method(POST).path("/deployments") |
| 79 | + .payload("fixtures/client/v3/deployments/POST_request.json") |
| 80 | + .build()) |
| 81 | + .response(TestResponse.builder() |
| 82 | + .status(OK) |
| 83 | + .payload("fixtures/client/v3/deployments/POST_response.json") |
| 84 | + .build()) |
| 85 | + .build()); |
| 86 | + |
| 87 | + this.deployments |
| 88 | + .create(CreateDeploymentRequest.builder() |
| 89 | + .droplet(Relationship.builder().id("44ccfa61-dbcf-4a0d-82fe-f668e9d2a962").build()) |
| 90 | + .relationships(DeploymentRelationships.builder() |
| 91 | + .app(ToOneRelationship.builder() |
| 92 | + .data(Relationship.builder() |
| 93 | + .id("305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 94 | + .build()) |
| 95 | + .build()) |
| 96 | + .build()) |
| 97 | + .build()) |
| 98 | + .as(StepVerifier::create) |
| 99 | + |
| 100 | + .expectNext(CreateDeploymentResponse.builder() |
| 101 | + .id("59c3d133-2b83-46f3-960e-7765a129aea4") |
| 102 | + .state(DeploymentState.DEPLOYING) |
| 103 | + .droplet(Relationship.builder() |
| 104 | + .id("44ccfa61-dbcf-4a0d-82fe-f668e9d2a962") |
| 105 | + .build()) |
| 106 | + .previousDroplet(Relationship.builder() |
| 107 | + .id("cc6bc315-bd06-49ce-92c2-bc3ad45268c2") |
| 108 | + .build()) |
| 109 | + .newProcesses(singletonList(Process.builder() |
| 110 | + .id("fd5d3e60-f88c-4c37-b1ae-667cfc65a856") |
| 111 | + .type("web-deployment-59c3d133-2b83-46f3-960e-7765a129aea4") |
| 112 | + .build())) |
| 113 | + .revision(Revision.builder() |
| 114 | + .id("56126cba-656a-4eba-a81e-7e9951b2df57") |
| 115 | + .version(1) |
| 116 | + .build()) |
| 117 | + .createdAt("2018-04-25T22:42:10Z") |
| 118 | + .updatedAt("2018-04-25T22:42:10Z") |
| 119 | + .relationships(DeploymentRelationships.builder() |
| 120 | + .app(ToOneRelationship.builder() |
| 121 | + .data(Relationship.builder() |
| 122 | + .id("305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 123 | + .build()) |
| 124 | + .build()) |
| 125 | + .build()) |
| 126 | + .link("self", Link.builder() |
| 127 | + .href("https://api.example.org/v3/deployments/59c3d133-2b83-46f3-960e-7765a129aea4") |
| 128 | + .build()) |
| 129 | + .link("app", Link.builder() |
| 130 | + .href("https://api.example.org/v3/apps/305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 131 | + .build()) |
| 132 | + .build()) |
| 133 | + .expectComplete() |
| 134 | + .verify(Duration.ofSeconds(5)); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void get() { |
| 139 | + mockRequest(InteractionContext.builder() |
| 140 | + .request(TestRequest.builder() |
| 141 | + .method(GET).path("/deployments/test-deployment-id") |
| 142 | + .build()) |
| 143 | + .response(TestResponse.builder() |
| 144 | + .status(OK) |
| 145 | + .payload("fixtures/client/v3/deployments/GET_{id}_response.json") |
| 146 | + .build()) |
| 147 | + .build()); |
| 148 | + |
| 149 | + this.deployments |
| 150 | + .get(GetDeploymentRequest.builder() |
| 151 | + .deploymentId("test-deployment-id") |
| 152 | + .build()) |
| 153 | + .as(StepVerifier::create) |
| 154 | + |
| 155 | + .expectNext(GetDeploymentResponse.builder() |
| 156 | + .id("59c3d133-2b83-46f3-960e-7765a129aea4") |
| 157 | + .state(DeploymentState.DEPLOYING) |
| 158 | + .droplet(Relationship.builder() |
| 159 | + .id("44ccfa61-dbcf-4a0d-82fe-f668e9d2a962") |
| 160 | + .build()) |
| 161 | + .previousDroplet(Relationship.builder() |
| 162 | + .id("cc6bc315-bd06-49ce-92c2-bc3ad45268c2") |
| 163 | + .build()) |
| 164 | + .newProcesses(singletonList(Process.builder() |
| 165 | + .id("fd5d3e60-f88c-4c37-b1ae-667cfc65a856") |
| 166 | + .type("web-deployment-59c3d133-2b83-46f3-960e-7765a129aea4") |
| 167 | + .build())) |
| 168 | + .revision(Revision.builder() |
| 169 | + .id("56126cba-656a-4eba-a81e-7e9951b2df57") |
| 170 | + .version(1) |
| 171 | + .build()) |
| 172 | + .createdAt("2018-04-25T22:42:10Z") |
| 173 | + .updatedAt("2018-04-25T22:42:10Z") |
| 174 | + .relationships(DeploymentRelationships.builder() |
| 175 | + .app(ToOneRelationship.builder() |
| 176 | + .data(Relationship.builder() |
| 177 | + .id("305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 178 | + .build()) |
| 179 | + .build()) |
| 180 | + .build()) |
| 181 | + .link("self", Link.builder() |
| 182 | + .href("https://api.example.org/v3/deployments/59c3d133-2b83-46f3-960e-7765a129aea4") |
| 183 | + .build()) |
| 184 | + .link("app", Link.builder() |
| 185 | + .href("https://api.example.org/v3/apps/305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 186 | + .build()) |
| 187 | + .build()) |
| 188 | + .expectComplete() |
| 189 | + .verify(Duration.ofSeconds(5)); |
| 190 | + } |
| 191 | + |
| 192 | + @Test |
| 193 | + public void list() { |
| 194 | + mockRequest(InteractionContext.builder() |
| 195 | + .request(TestRequest.builder() |
| 196 | + .method(GET).path("/deployments") |
| 197 | + .build()) |
| 198 | + .response(TestResponse.builder() |
| 199 | + .status(OK) |
| 200 | + .payload("fixtures/client/v3/deployments/GET_response.json") |
| 201 | + .build()) |
| 202 | + .build()); |
| 203 | + |
| 204 | + this.deployments |
| 205 | + .list(ListDeploymentsRequest.builder() |
| 206 | + .build()) |
| 207 | + .as(StepVerifier::create) |
| 208 | + .expectNext(ListDeploymentsResponse.builder() |
| 209 | + .pagination(Pagination.builder() |
| 210 | + .totalResults(1) |
| 211 | + .totalPages(1) |
| 212 | + .first(Link.builder() |
| 213 | + .href("https://api.example.org/v3/deployments?page=1&per_page=2") |
| 214 | + .build()) |
| 215 | + .last(Link.builder() |
| 216 | + .href("https://api.example.org/v3/deployments?page=1&per_page=2") |
| 217 | + .build()) |
| 218 | + .build()) |
| 219 | + .resource(DeploymentResource.builder() |
| 220 | + .id("59c3d133-2b83-46f3-960e-7765a129aea4") |
| 221 | + .state(DeploymentState.DEPLOYING) |
| 222 | + .droplet(Relationship.builder() |
| 223 | + .id("44ccfa61-dbcf-4a0d-82fe-f668e9d2a962") |
| 224 | + .build()) |
| 225 | + .previousDroplet(Relationship.builder() |
| 226 | + .id("cc6bc315-bd06-49ce-92c2-bc3ad45268c2") |
| 227 | + .build()) |
| 228 | + .newProcesses(singletonList(Process.builder() |
| 229 | + .id("fd5d3e60-f88c-4c37-b1ae-667cfc65a856") |
| 230 | + .type("web-deployment-59c3d133-2b83-46f3-960e-7765a129aea4") |
| 231 | + .build())) |
| 232 | + .revision(Revision.builder() |
| 233 | + .id("56126cba-656a-4eba-a81e-7e9951b2df57") |
| 234 | + .version(1) |
| 235 | + .build()) |
| 236 | + .createdAt("2018-04-25T22:42:10Z") |
| 237 | + .updatedAt("2018-04-25T22:42:10Z") |
| 238 | + .relationships(DeploymentRelationships.builder() |
| 239 | + .app(ToOneRelationship.builder() |
| 240 | + .data(Relationship.builder() |
| 241 | + .id("305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 242 | + .build()) |
| 243 | + .build()) |
| 244 | + .build()) |
| 245 | + .link("self", Link.builder() |
| 246 | + .href("https://api.example.org/v3/deployments/59c3d133-2b83-46f3-960e-7765a129aea4") |
| 247 | + .build()) |
| 248 | + .link("app", Link.builder() |
| 249 | + .href("https://api.example.org/v3/apps/305cea31-5a44-45ca-b51b-e89c7a8ef8b2") |
| 250 | + .build()) |
| 251 | + .build()) |
| 252 | + .build()) |
| 253 | + .expectComplete() |
| 254 | + .verify(Duration.ofSeconds(5)); |
| 255 | + } |
| 256 | + |
| 257 | +} |
0 commit comments