|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.appbroker.deployer.cloudfoundry; |
18 | 18 |
|
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.Map; |
| 21 | + |
19 | 22 | import org.cloudfoundry.client.CloudFoundryClient; |
20 | 23 | import org.cloudfoundry.client.v2.applications.ApplicationsV2; |
21 | 24 | import org.cloudfoundry.client.v2.applications.UpdateApplicationResponse; |
|
46 | 49 | import org.junit.jupiter.api.BeforeEach; |
47 | 50 | import org.junit.jupiter.api.Test; |
48 | 51 | import org.junit.jupiter.api.extension.ExtendWith; |
| 52 | +import org.mockito.ArgumentCaptor; |
49 | 53 | import org.mockito.Mock; |
50 | 54 | import org.mockito.junit.jupiter.MockitoExtension; |
51 | 55 | import org.mockito.junit.jupiter.MockitoSettings; |
@@ -118,14 +122,10 @@ void setUp() { |
118 | 122 |
|
119 | 123 | appDeployer = new CloudFoundryAppDeployer(deploymentProperties, |
120 | 124 | cloudFoundryOperations, cloudFoundryClient, operationsUtils, targetProperties, resourceLoader); |
121 | | - } |
122 | 125 |
|
123 | | - @Test |
124 | | - void updateApp() { |
125 | 126 | when(operationsApplications.get(any())) |
126 | 127 | .thenReturn(Mono.just(createApplicationDetail())); |
127 | | - when(applicationsV2.update(any())) |
128 | | - .thenReturn(Mono.just(UpdateApplicationResponse.builder().build())); |
| 128 | + |
129 | 129 | when(packages.create(any())) |
130 | 130 | .thenReturn(Mono.just(CreatePackageResponse |
131 | 131 | .builder() |
@@ -193,17 +193,55 @@ void updateApp() { |
193 | 193 | .createdAt("DATETIME") |
194 | 194 | .id("deployment-id") |
195 | 195 | .build())); |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + @Test |
| 200 | + void updateApp() { |
| 201 | + when(applicationsV2.update(any())) |
| 202 | + .thenReturn(Mono.just(UpdateApplicationResponse.builder().build())); |
| 203 | + |
| 204 | + UpdateApplicationRequest request = |
| 205 | + UpdateApplicationRequest |
| 206 | + .builder() |
| 207 | + .name(APP_NAME) |
| 208 | + .path(APP_PATH) |
| 209 | + .build(); |
| 210 | + |
| 211 | + StepVerifier.create(appDeployer.update(request)) |
| 212 | + .assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME)) |
| 213 | + .verifyComplete(); |
| 214 | + } |
| 215 | + |
| 216 | + @Test |
| 217 | + void updateAppProperties() { |
| 218 | + ArgumentCaptor<org.cloudfoundry.client.v2.applications.UpdateApplicationRequest> updateApplicationRequestCaptor = |
| 219 | + ArgumentCaptor.forClass(org.cloudfoundry.client.v2.applications.UpdateApplicationRequest.class); |
| 220 | + |
| 221 | + when(applicationsV2.update(updateApplicationRequestCaptor.capture())) |
| 222 | + .thenReturn(Mono.just(UpdateApplicationResponse.builder().build())); |
| 223 | + |
| 224 | + Map<String, String> properties = new HashMap<>(); |
| 225 | + properties.put("count", "2"); |
| 226 | + properties.put("disk", "2G"); |
| 227 | + properties.put("memory", "1G"); |
196 | 228 |
|
197 | 229 | UpdateApplicationRequest request = |
198 | 230 | UpdateApplicationRequest |
199 | 231 | .builder() |
200 | 232 | .name(APP_NAME) |
201 | 233 | .path(APP_PATH) |
| 234 | + .properties(properties) |
202 | 235 | .build(); |
203 | 236 |
|
204 | 237 | StepVerifier.create(appDeployer.update(request)) |
205 | 238 | .assertNext(response -> assertThat(response.getName()).isEqualTo(APP_NAME)) |
206 | 239 | .verifyComplete(); |
| 240 | + |
| 241 | + org.cloudfoundry.client.v2.applications.UpdateApplicationRequest updateApplicationRequest = updateApplicationRequestCaptor.getValue(); |
| 242 | + assertThat(updateApplicationRequest.getInstances()).isEqualTo(2); |
| 243 | + assertThat(updateApplicationRequest.getDiskQuota()).isEqualTo(2048); |
| 244 | + assertThat(updateApplicationRequest.getMemory()).isEqualTo(1024); |
207 | 245 | } |
208 | 246 |
|
209 | 247 | private ApplicationDetail createApplicationDetail() { |
|
0 commit comments