Skip to content

Commit

Permalink
fix junit tests when jdk11 is used
Browse files Browse the repository at this point in the history
in cloudfoundry-operations there are 32 JUnit errors when
jdk 11 or jdk17 are used. Those are fixed with this change.
So far not tested with later jdks.
  • Loading branch information
Lokowandtg committed Dec 10, 2024
1 parent 0e3d9ab commit a990ba0
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,12 @@ void pushExistingApplication() throws IOException {
requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
requestApplications(
this.cloudFoundryClient, "test-name", TEST_SPACE_ID, "test-application-id");
requestCreateApplication(
cloudFoundryClient,
ApplicationManifest.builder().name("test-name").build(),
TEST_SPACE_ID,
null,
"test-application-id");
requestUpdateApplication(
this.cloudFoundryClient,
"test-application-id",
Expand Down Expand Up @@ -1599,6 +1605,15 @@ void pushExistingApplicationWithEnvironmentVariables() throws IOException {
TEST_SPACE_ID,
"test-application-id",
Collections.singletonMap("test-key-1", "test-value-1"));
requestCreateApplication(
cloudFoundryClient,
ApplicationManifest.builder()
.name("test-name")
.environmentVariable("test-key-2", "test-value-2")
.build(),
TEST_SPACE_ID,
null,
"test-application-id");
requestUpdateApplication(
this.cloudFoundryClient,
"test-application-id",
Expand Down Expand Up @@ -1669,6 +1684,16 @@ void pushExistingApplicationWithNullEnvironment() throws IOException {
requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
requestApplications(
this.cloudFoundryClient, "test-name", TEST_SPACE_ID, "test-application-id", null);
requestCreateApplication(
cloudFoundryClient,
ApplicationManifest.builder()
.name("test-name")
.environmentVariable("test-key-1", "test-value-1")
.environmentVariable("test-key-2", "test-value-2")
.build(),
TEST_SPACE_ID,
null,
"test-application-id");
requestUpdateApplication(
this.cloudFoundryClient,
"test-application-id",
Expand Down Expand Up @@ -1756,11 +1781,20 @@ void pushExistingRouteWithHost() throws IOException {
requestSharedDomains(
this.cloudFoundryClient, "test-shared-domain", "test-shared-domain-id");
requestApplicationRoutes(this.cloudFoundryClient, "test-application-id", "test-route-id");
requestCreateRoute(
this.cloudFoundryClient,
"test-shared-domain-id",
"test-host",
null,
null,
"test-space-id",
"test-route-id");
requestRoutes(
this.cloudFoundryClient,
"test-shared-domain-id",
"test-host",
null,
null,
"test-route-id");
requestListMatchingResources(
this.cloudFoundryClient,
Expand Down Expand Up @@ -1817,7 +1851,16 @@ void pushExistingRouteWithNoHost() throws IOException {
requestSharedDomains(
this.cloudFoundryClient, "test-shared-domain", "test-shared-domain-id");
requestApplicationRoutes(this.cloudFoundryClient, "test-application-id", "test-route-id");
requestRoutes(this.cloudFoundryClient, "test-shared-domain-id", "", null, "test-route-id");
requestRoutes(
this.cloudFoundryClient, "test-shared-domain-id", "", null, null, "test-route-id");
requestCreateRoute(
this.cloudFoundryClient,
"test-shared-domain-id",
"",
null,
null,
"test-space-id",
"test-route-id");
requestListMatchingResources(
this.cloudFoundryClient,
Arrays.asList(
Expand Down Expand Up @@ -2952,6 +2995,7 @@ void pushStartFailsStaging() throws IOException {
requestUpdateApplicationState(this.cloudFoundryClient, "test-application-id", "STOPPED");
requestUpdateApplicationState(this.cloudFoundryClient, "test-application-id", "STARTED");
requestGetApplicationFailing(this.cloudFoundryClient, "test-application-id");
requestInstancesApplicationFailing(this.cloudFoundryClient, "test-application-id");

StepVerifier.withVirtualTime(
() ->
Expand Down Expand Up @@ -3244,6 +3288,7 @@ void restageStagingFailure() {
"test-metadata-id");
requestRestageApplication(this.cloudFoundryClient, "test-metadata-id");
requestGetApplicationFailing(this.cloudFoundryClient, "test-metadata-id");
requestInstancesApplicationFailing(this.cloudFoundryClient, "test-metadata-id");

this.applications
.restage(RestageApplicationRequest.builder().name("test-application-name").build())
Expand Down Expand Up @@ -3317,6 +3362,7 @@ void restageTimeout() {
"test-metadata-id");
requestRestageApplication(this.cloudFoundryClient, "test-metadata-id");
requestGetApplicationTimeout(this.cloudFoundryClient, "test-metadata-id");
requestInstancesApplicationFailing(this.cloudFoundryClient, "test-metadata-id");

this.applications
.restage(
Expand Down Expand Up @@ -4983,6 +5029,29 @@ private static void requestGetApplicationFailing(
.build()));
}

private static void requestInstancesApplicationFailing(
CloudFoundryClient cloudFoundryClient, String applicationId) {
when(cloudFoundryClient
.applicationsV2()
.instances(
ApplicationInstancesRequest.builder()
.applicationId(applicationId)
.build()))
.thenReturn(
Mono.just(
fill(
ApplicationInstancesResponse.builder(),
"application-instances-")
.instance(
"instance-0",
fill(
ApplicationInstanceInfo.builder(),
"application-instance-info-")
.state("FAILED")
.build())
.build()));
}

private static void requestGetApplicationTimeout(
CloudFoundryClient cloudFoundryClient, String applicationId) {
when(cloudFoundryClient
Expand Down Expand Up @@ -5452,11 +5521,13 @@ private static void requestRoutes(
CloudFoundryClient cloudFoundryClient,
String domainId,
String host,
Integer port,
String routePath,
String routeId) {
ListRoutesRequest.Builder requestBuilder = ListRoutesRequest.builder();

Optional.ofNullable(host).ifPresent(requestBuilder::host);
Optional.ofNullable(port).ifPresent(requestBuilder::port);
Optional.ofNullable(routePath).ifPresent(requestBuilder::path);

when(cloudFoundryClient.routes().list(requestBuilder.domainId(domainId).page(1).build()))
Expand All @@ -5472,6 +5543,7 @@ private static void requestRoutes(
.entity(
RouteEntity.builder()
.host(host)
.port(port)
.path(
routePath == null
? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void createSetRolesByUsernameDisabled() {
@Test
void createWithQuota() {
requestOrganizationQuotaDefinitions(this.cloudFoundryClient, "test-quota-definition-name");

requestCreateOrganization(this.cloudFoundryClient, TEST_ORGANIZATION_NAME, null);
requestCreateOrganization(
this.cloudFoundryClient,
TEST_ORGANIZATION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void createRouteInvalidDomain() {
void createRouteInvalidSpace() {
requestSpacesEmpty(this.cloudFoundryClient, TEST_ORGANIZATION_ID, TEST_SPACE_NAME);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");

this.routes
.create(
Expand All @@ -236,6 +237,7 @@ void createRouteInvalidSpace() {
void createRouteNoHost() {
requestSpaces(this.cloudFoundryClient, TEST_ORGANIZATION_ID, TEST_SPACE_NAME);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestCreateRoute(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand All @@ -262,6 +264,7 @@ void createRouteNoHost() {
void createRouteNoPath() {
requestSpaces(this.cloudFoundryClient, TEST_ORGANIZATION_ID, TEST_SPACE_NAME);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestCreateRoute(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand All @@ -288,6 +291,7 @@ void createRouteNoPath() {
void createRoutePrivateDomain() {
requestSpaces(this.cloudFoundryClient, TEST_ORGANIZATION_ID, TEST_SPACE_NAME);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestCreateRoute(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -365,6 +369,7 @@ private static void mockDeleteOrphanedRoutes(CloudFoundryClient cloudFoundryClie
@Test
void deleteRoute() {
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutes(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -531,6 +536,7 @@ void mapRouteAssignedPort() {
void mapRouteExists() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutes(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand All @@ -556,6 +562,7 @@ void mapRouteExists() {
void mapRouteInvalidApplicationName() {
requestApplicationsEmpty(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutesEmpty(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -616,6 +623,7 @@ void mapRouteInvalidDomain() {
void mapRouteNoHost() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutesEmpty(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -648,6 +656,7 @@ void mapRouteNoHost() {
void mapRoutePath() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutesTwo(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand All @@ -672,6 +681,7 @@ void mapRoutePath() {
void mapRoutePrivateDomain() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutesEmpty(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -760,6 +770,7 @@ void unmapRouteAssignedPort() {
void unmapRouteInvalidApplicationName() {
requestApplicationsEmpty(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");

this.routes
.unmap(
Expand Down Expand Up @@ -804,6 +815,7 @@ void unmapRouteInvalidDomain() {
void unmapRouteInvalidRoute() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutesEmpty(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down Expand Up @@ -832,6 +844,7 @@ void unmapRouteInvalidRoute() {
void unmapRoutePrivateDomain() {
requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID);
requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-domain");
requestSharedDomains(cloudFoundryClient, "test-domain");
requestRoutes(
this.cloudFoundryClient,
"test-private-domain-metadata-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ void enableServiceAccessOrganizationNotFound() {

@Test
void enableServiceAccessServiceNotFound() {
requestListServicesWithNameEmpty(this.cloudFoundryClient, "bogus-service-name");
requestListServicesWithNameAndServiceBrokerIdEmpty(
this.cloudFoundryClient, "bogus-service-name");

this.serviceAdmin
.enableServiceAccess(
Expand Down Expand Up @@ -488,6 +489,9 @@ void listServiceAccessSettingsSpecifyOrganizationNotFound() {
requestListServiceBrokers(this.cloudFoundryClient);
requestListServicePlanVisibilities(this.cloudFoundryClient);
requestListOrganizationsEmpty(this.cloudFoundryClient, "bogus-organization-name");
requestListServicesWithNameEmptyAndServiceBrokerIdAndLabelSet(
this.cloudFoundryClient, "bogus-service-name");
requestListServicesWithNameEmptyAndServiceBrokerIdSet(this.cloudFoundryClient);

this.serviceAdmin
.listServiceAccessSettings(
Expand Down Expand Up @@ -534,7 +538,11 @@ void listServiceAccessSettingsSpecifyService() {
void listServiceAccessSettingsSpecifyServiceNotFound() {
requestListServiceBrokers(this.cloudFoundryClient);
requestListServicePlanVisibilitiesEmpty(this.cloudFoundryClient);
requestListServicesWithNameEmpty(this.cloudFoundryClient, "bogus-service-name");
requestListServicesWithNameEmptyAndServiceBrokerIdAndLabelSet(
this.cloudFoundryClient, "bogus-service-name");
requestListServicesWithNameEmptyAndServiceBrokerIdSet(this.cloudFoundryClient);
requestListServicesWithNameAndServiceBrokerIdEmpty(
this.cloudFoundryClient, "bogus-service-name");

this.serviceAdmin
.listServiceAccessSettings(
Expand Down Expand Up @@ -985,14 +993,39 @@ private static void requestListServicesWithName(
.build()));
}

private static void requestListServicesWithNameEmpty(
private static void requestListServicesWithNameAndServiceBrokerIdEmpty(
CloudFoundryClient cloudFoundryClient, String label) {
when(cloudFoundryClient
.services()
.list(ListServicesRequest.builder().label(label).page(1).build()))
.thenReturn(Mono.just(fill(ListServicesResponse.builder()).build()));
}

private static void requestListServicesWithNameEmptyAndServiceBrokerIdAndLabelSet(
CloudFoundryClient cloudFoundryClient, String label) {
when(cloudFoundryClient
.services()
.list(
ListServicesRequest.builder()
.label(label)
.page(1)
.serviceBrokerId("test-service-broker-id")
.build()))
.thenReturn(Mono.just(fill(ListServicesResponse.builder()).build()));
}

private static void requestListServicesWithNameEmptyAndServiceBrokerIdSet(
CloudFoundryClient cloudFoundryClient) {
when(cloudFoundryClient
.services()
.list(
ListServicesRequest.builder()
.page(1)
.serviceBrokerId("test-service-broker-id")
.build()))
.thenReturn(Mono.just(fill(ListServicesResponse.builder()).build()));
}

private static void requestUpdateServiceBroker(
CloudFoundryClient cloudFoundryClient,
String name,
Expand Down
Loading

0 comments on commit a990ba0

Please sign in to comment.