Skip to content

Commit 257ca3a

Browse files
abhishek7-sapDavid O'Sullivan
authored andcommitted
Modified Junit tests to adopt V3 changes.
1 parent 4f37f21 commit 257ca3a

3 files changed

Lines changed: 109 additions & 78 deletions

File tree

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
import org.cloudfoundry.client.v3.Relationship;
110110
import org.cloudfoundry.client.v3.Resource;
111111
import org.cloudfoundry.client.v3.ToOneRelationship;
112+
import org.cloudfoundry.client.v3.applications.ApplicationFeature;
112113
import org.cloudfoundry.client.v3.applications.ApplicationResource;
113114
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
114115
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
@@ -2626,16 +2627,16 @@ private static Mono<AbstractApplicationResource> requestUpdateApplicationHealthC
26262627
builder -> builder.healthCheckType(type.getValue()));
26272628
}
26282629

2629-
private static Mono<ApplicationResource> requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) {
2630+
private static Mono<ApplicationFeature> requestUpdateApplicationSsh(CloudFoundryClient cloudFoundryClient, String applicationId, boolean enabled) {
26302631
return requestUpdateApplicationFeature(cloudFoundryClient, applicationId,builder -> builder.featureName(APP_FEATURE_SSH).enabled(enabled));
26312632
}
26322633

2633-
private static Mono<ApplicationResource> requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator<UpdateApplicationFeatureRequest.Builder> modifier) {
2634+
private static Mono<ApplicationFeature> requestUpdateApplicationFeature(CloudFoundryClient cloudFoundryClient, String applicationId, UnaryOperator<UpdateApplicationFeatureRequest.Builder> modifier) {
26342635
return cloudFoundryClient.applicationsV3()
26352636
.updateFeature(modifier.apply(org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest.builder()
26362637
.applicationId(applicationId))
26372638
.build())
2638-
.cast(ApplicationResource.class);
2639+
.cast(ApplicationFeature.class);
26392640
}
26402641

26412642
private static Mono<AbstractApplicationResource> requestUpdateApplicationScale(

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public abstract class AbstractOperationsTest {
8080

8181
protected static final String TEST_USERNAME = "test-username";
8282

83+
protected static final String APP_FEATURE_SSH = "ssh";
84+
8385
protected final ApplicationsV2 applications = mock(ApplicationsV2.class, RETURNS_SMART_NULLS);
8486

8587
protected final ApplicationsV3 applicationsV3 = mock(ApplicationsV3.class, RETURNS_SMART_NULLS);

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java

Lines changed: 103 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@
127127
import org.cloudfoundry.client.v3.DockerData;
128128
import org.cloudfoundry.client.v3.Lifecycle;
129129
import org.cloudfoundry.client.v3.applications.ApplicationState;
130+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
131+
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
132+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
133+
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
130134
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
131135
import org.cloudfoundry.client.v3.applications.ListApplicationsResponse;
136+
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest;
137+
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureResponse;
132138
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
133139
import org.cloudfoundry.client.v3.tasks.CancelTaskResponse;
134140
import org.cloudfoundry.client.v3.tasks.CreateTaskRequest;
@@ -405,10 +411,11 @@ void deleteWithBoundRoutes() {
405411
}
406412

407413
@Test
408-
void disableSsh() {
409-
requestApplications(
410-
this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id");
411-
requestUpdateApplicationSsh(this.cloudFoundryClient, "test-metadata-id", false);
414+
public void disableSsh() {
415+
requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id");
416+
requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true);
417+
requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", false);
418+
412419

413420
this.applications
414421
.disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build())
@@ -418,8 +425,9 @@ void disableSsh() {
418425
}
419426

420427
@Test
421-
void disableSshAlreadyDisabled() {
422-
requestApplicationsWithSsh(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, false);
428+
public void disableSshAlreadyDisabled() {
429+
requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id");
430+
requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false);
423431

424432
this.applications
425433
.disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build())
@@ -429,8 +437,8 @@ void disableSshAlreadyDisabled() {
429437
}
430438

431439
@Test
432-
void disableSshNoApp() {
433-
requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
440+
public void disableSshNoApp() {
441+
requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
434442

435443
this.applications
436444
.disableSsh(DisableApplicationSshRequest.builder().name("test-app-name").build())
@@ -444,10 +452,10 @@ void disableSshNoApp() {
444452
}
445453

446454
@Test
447-
void enableSsh() {
448-
requestApplications(
449-
this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id");
450-
requestUpdateApplicationSsh(this.cloudFoundryClient, "test-application-id", true);
455+
public void enableSsh() {
456+
requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id");
457+
requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",false);
458+
requestUpdateApplicationSshV3(this.cloudFoundryClient, "test-application-id", true);
451459

452460
this.applications
453461
.enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build())
@@ -457,8 +465,9 @@ void enableSsh() {
457465
}
458466

459467
@Test
460-
void enableSshAlreadyEnabled() {
461-
requestApplicationsWithSsh(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, true);
468+
public void enableSshAlreadyEnabled() {
469+
requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id");
470+
requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true);
462471

463472
this.applications
464473
.enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build())
@@ -468,8 +477,8 @@ void enableSshAlreadyEnabled() {
468477
}
469478

470479
@Test
471-
void enableSshNoApp() {
472-
requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
480+
public void enableSshNoApp() {
481+
requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
473482

474483
this.applications
475484
.enableSsh(EnableApplicationSshRequest.builder().name("test-app-name").build())
@@ -721,8 +730,8 @@ void getDetectedBuildpack() {
721730
}
722731

723732
@Test
724-
void getEnvironments() {
725-
requestApplications(this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id");
733+
public void getEnvironments() {
734+
requestApplicationsV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID, "test-metadata-id");
726735
requestApplicationEnvironment(this.cloudFoundryClient, "test-metadata-id");
727736

728737
this.applications
@@ -753,8 +762,8 @@ void getEnvironments() {
753762
}
754763

755764
@Test
756-
void getEnvironmentsNoApp() {
757-
requestApplicationsEmpty(this.cloudFoundryClient, "test-app", TEST_SPACE_ID);
765+
public void getEnvironmentsNoApp() {
766+
requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app", TEST_SPACE_ID);
758767

759768
this.applications
760769
.getEnvironments(
@@ -3733,9 +3742,9 @@ void setHealthCheck() {
37333742
}
37343743

37353744
@Test
3736-
void sshEnabled() {
3737-
requestApplications(
3738-
this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-metadata-id");
3745+
public void sshEnabled() {
3746+
requestApplicationsV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID, "test-application-id");
3747+
requestGetSshEnabled(this.cloudFoundryClient,"test-application-id",true);
37393748

37403749
this.applications
37413750
.sshEnabled(ApplicationSshEnabledRequest.builder().name("test-app-name").build())
@@ -3746,8 +3755,8 @@ void sshEnabled() {
37463755
}
37473756

37483757
@Test
3749-
void sshEnabledNoApp() {
3750-
requestApplicationsEmpty(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
3758+
public void sshEnabledNoApp() {
3759+
requestApplicationsEmptyV3(this.cloudFoundryClient, "test-app-name", TEST_SPACE_ID);
37513760

37523761
this.applications
37533762
.sshEnabled(ApplicationSshEnabledRequest.builder().name("test-app-name").build())
@@ -3760,6 +3769,7 @@ void sshEnabledNoApp() {
37603769
.verify(Duration.ofSeconds(5));
37613770
}
37623771

3772+
37633773
@Test
37643774
void startApplicationFailurePartial() {
37653775
requestApplicationsSpecificState(
@@ -4046,27 +4056,19 @@ private static void requestApplicationEmptyStats(
40464056
.thenReturn(Mono.just(ApplicationStatisticsResponse.builder().build()));
40474057
}
40484058

4049-
private static void requestApplicationEnvironment(
4050-
CloudFoundryClient cloudFoundryClient, String applicationId) {
4051-
when(cloudFoundryClient
4052-
.applicationsV2()
4053-
.environment(
4054-
ApplicationEnvironmentRequest.builder()
4055-
.applicationId(applicationId)
4056-
.build()))
4057-
.thenReturn(
4058-
Mono.just(
4059-
ApplicationEnvironmentResponse.builder()
4060-
.runningEnvironmentJson(
4061-
"running-env-name", "running-env-value")
4062-
.applicationEnvironmentJson(
4063-
"application-env-name", "application-env-value")
4064-
.stagingEnvironmentJson(
4065-
"staging-env-name", "staging-env-value")
4066-
.environmentJson("env-name", "env-value")
4067-
.systemEnvironmentJson(
4068-
"system-env-name", "system-env-value")
4069-
.build()));
4059+
private static void requestApplicationEnvironment(CloudFoundryClient cloudFoundryClient, String applicationId) {
4060+
when(cloudFoundryClient.applicationsV3()
4061+
.getEnvironment(GetApplicationEnvironmentRequest.builder()
4062+
.applicationId(applicationId)
4063+
.build()))
4064+
.thenReturn(Mono
4065+
.just(GetApplicationEnvironmentResponse.builder()
4066+
.runningEnvironmentVariable("running-env-name", "running-env-value")
4067+
.applicationEnvironmentVariable("application-env-name", "application-env-value")
4068+
.stagingEnvironmentVariable("staging-env-name", "staging-env-value")
4069+
.environmentVariable("env-name", "env-value")
4070+
.systemEnvironmentVariable("system-env-name", "system-env-value")
4071+
.build()));
40704072
}
40714073

40724074
private static void requestApplicationInstances(
@@ -4661,33 +4663,33 @@ private static void requestApplicationsEmpty(
46614663
.thenReturn(Mono.just(fill(ListSpaceApplicationsResponse.builder()).build()));
46624664
}
46634665

4664-
private static void requestApplicationsSpecificState(
4665-
CloudFoundryClient cloudFoundryClient,
4666-
String application,
4667-
String spaceId,
4668-
String stateReturned) {
4669-
when(cloudFoundryClient
4670-
.spaces()
4671-
.listApplications(
4672-
ListSpaceApplicationsRequest.builder()
4673-
.name(application)
4674-
.page(1)
4675-
.spaceId(spaceId)
4676-
.build()))
4677-
.thenReturn(
4678-
Mono.just(
4679-
fill(ListSpaceApplicationsResponse.builder())
4680-
.resource(
4681-
fill(ApplicationResource.builder(), "application-")
4682-
.entity(
4683-
fill(
4684-
ApplicationEntity
4685-
.builder(),
4686-
"application-entity-")
4687-
.state(stateReturned)
4688-
.build())
4689-
.build())
4690-
.build()));
4666+
private static void requestApplicationsEmptyV3(CloudFoundryClient cloudFoundryClient, String application, String spaceId) {
4667+
when(cloudFoundryClient.applicationsV3()
4668+
.list(ListApplicationsRequest.builder()
4669+
.name(application)
4670+
.spaceId(spaceId)
4671+
.page(1)
4672+
.build()))
4673+
.thenReturn(Mono
4674+
.just(fill(ListApplicationsResponse.builder())
4675+
.build()));
4676+
}
4677+
4678+
private static void requestApplicationsSpecificState(CloudFoundryClient cloudFoundryClient, String application, String spaceId, String stateReturned) {
4679+
when(cloudFoundryClient.spaces()
4680+
.listApplications(ListSpaceApplicationsRequest.builder()
4681+
.name(application)
4682+
.page(1)
4683+
.spaceId(spaceId)
4684+
.build()))
4685+
.thenReturn(Mono
4686+
.just(fill(ListSpaceApplicationsResponse.builder())
4687+
.resource(fill(ApplicationResource.builder(), "application-")
4688+
.entity(fill(ApplicationEntity.builder(), "application-entity-")
4689+
.state(stateReturned)
4690+
.build())
4691+
.build())
4692+
.build()));
46914693
}
46924694

46934695
private static void requestApplicationsV3(
@@ -5850,8 +5852,34 @@ private static void requestUpdateApplicationSsh(
58505852
.build()));
58515853
}
58525854

5853-
private static void requestUpdateApplicationState(
5854-
CloudFoundryClient cloudFoundryClient, String applicationId, String state) {
5855+
private static void requestUpdateApplicationSshV3(CloudFoundryClient cloudFoundryClient, String applicationId, Boolean enabled) {
5856+
5857+
when(cloudFoundryClient.applicationsV3()
5858+
.updateFeature(UpdateApplicationFeatureRequest.builder()
5859+
.applicationId(applicationId)
5860+
.featureName(APP_FEATURE_SSH)
5861+
.enabled(enabled)
5862+
.build()))
5863+
.thenReturn(Mono
5864+
.just(fill(UpdateApplicationFeatureResponse.builder())
5865+
.description("test-description")
5866+
.name("test-application-name")
5867+
.enabled(enabled)
5868+
.build()));
5869+
}
5870+
5871+
private static void requestGetSshEnabled(CloudFoundryClient cloudFoundryClient, String applicationId,boolean status) {
5872+
when(cloudFoundryClient.applicationsV3()
5873+
.getSshEnabled(GetApplicationSshEnabledRequest.builder()
5874+
.applicationId(applicationId).build()))
5875+
.thenReturn(Mono
5876+
.just(fill(GetApplicationSshEnabledResponse.builder())
5877+
.reason("test-reason")
5878+
.enabled(status)
5879+
.build()));
5880+
}
5881+
5882+
private static void requestUpdateApplicationState(CloudFoundryClient cloudFoundryClient, String applicationId, String state) {
58555883
requestUpdateApplicationState(cloudFoundryClient, applicationId, state, 1);
58565884
}
58575885

0 commit comments

Comments
 (0)