From a990ba0d19eca04f76163238df50a87c3c1498f9 Mon Sep 17 00:00:00 2001 From: Georg Lokowandt Date: Tue, 10 Dec 2024 19:50:56 +0100 Subject: [PATCH] fix junit tests when jdk11 is used 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. --- .../applications/DefaultApplicationsTest.java | 74 ++++++++++++++++++- .../DefaultOrganizationsTest.java | 2 + .../operations/routes/DefaultRoutesTest.java | 13 ++++ .../serviceadmin/DefaultServiceAdminTest.java | 39 +++++++++- .../services/DefaultServicesTest.java | 8 ++ 5 files changed, 132 insertions(+), 4 deletions(-) diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java index 325957e50b..cdc9619d2d 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java @@ -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", @@ -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", @@ -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", @@ -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, @@ -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( @@ -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( () -> @@ -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()) @@ -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( @@ -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 @@ -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())) @@ -5472,6 +5543,7 @@ private static void requestRoutes( .entity( RouteEntity.builder() .host(host) + .port(port) .path( routePath == null ? "" diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/organizations/DefaultOrganizationsTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/organizations/DefaultOrganizationsTest.java index 3f967bf088..5cf74e14a1 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/organizations/DefaultOrganizationsTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/organizations/DefaultOrganizationsTest.java @@ -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, diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/routes/DefaultRoutesTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/routes/DefaultRoutesTest.java index f4cabd9c5e..fdd46f2eff 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/routes/DefaultRoutesTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/routes/DefaultRoutesTest.java @@ -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( @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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( @@ -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", @@ -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", diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdminTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdminTest.java index 56d7e0303a..55f11a7626 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdminTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/serviceadmin/DefaultServiceAdminTest.java @@ -270,7 +270,8 @@ void enableServiceAccessOrganizationNotFound() { @Test void enableServiceAccessServiceNotFound() { - requestListServicesWithNameEmpty(this.cloudFoundryClient, "bogus-service-name"); + requestListServicesWithNameAndServiceBrokerIdEmpty( + this.cloudFoundryClient, "bogus-service-name"); this.serviceAdmin .enableServiceAccess( @@ -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( @@ -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( @@ -985,7 +993,7 @@ private static void requestListServicesWithName( .build())); } - private static void requestListServicesWithNameEmpty( + private static void requestListServicesWithNameAndServiceBrokerIdEmpty( CloudFoundryClient cloudFoundryClient, String label) { when(cloudFoundryClient .services() @@ -993,6 +1001,31 @@ private static void requestListServicesWithNameEmpty( .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, diff --git a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/services/DefaultServicesTest.java b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/services/DefaultServicesTest.java index a09f995757..bb23eefd87 100644 --- a/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/services/DefaultServicesTest.java +++ b/cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/services/DefaultServicesTest.java @@ -123,6 +123,7 @@ final class DefaultServicesTest extends AbstractOperationsTest { void bindRouteServiceInstanceAlreadyBound() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListSpaceServiceInstancesUserProvided( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); requestListRoutes(this.cloudFoundryClient, "test-private-domain-id"); @@ -171,6 +172,7 @@ void bindRouteServiceInstanceDomainNotFound() { void bindRouteServiceInstancePrivateDomain() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListSpaceServiceInstancesUserProvided( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); requestListRoutes(this.cloudFoundryClient, "test-private-domain-id"); @@ -196,6 +198,7 @@ void bindRouteServiceInstancePrivateDomain() { void bindRouteServiceInstancePrivateDomainWithHostAndPath() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListSpaceServiceInstancesUserProvided( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); requestListRoutes( @@ -224,6 +227,7 @@ void bindRouteServiceInstancePrivateDomainWithHostAndPath() { void bindRouteServiceInstanceServiceInstanceNotFound() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListSpaceServiceInstancesEmpty( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); requestListRoutes(this.cloudFoundryClient, "test-private-domain-id"); @@ -945,6 +949,7 @@ void listServiceOfferings() { @Test void listServiceOfferingsSingle() { requestListSpaceServices(this.cloudFoundryClient, TEST_SPACE_ID, "test-service"); + requestListSpaceServicesTwo(this.cloudFoundryClient, TEST_SPACE_ID, "label1", "label2"); requestListSpaceServicePlans( this.cloudFoundryClient, "test-service-id", @@ -996,6 +1001,7 @@ void renameServiceInstance() { void unbindRoute() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListRoutes(this.cloudFoundryClient, "test-private-domain-id"); requestListSpaceServiceInstancesUserProvided( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); @@ -1017,6 +1023,7 @@ void unbindRoute() { void unbindRouteServiceInstanceRouteNotFound() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListRoutesEmpty(this.cloudFoundryClient, "test-private-domain-id"); requestListSpaceServiceInstances( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID); @@ -1040,6 +1047,7 @@ void unbindRouteServiceInstanceRouteNotFound() { void unbindRouteServiceInstanceServiceInstanceNotFound() { requestListOrganizationPrivateDomains( this.cloudFoundryClient, "test-domain-name", TEST_ORGANIZATION_ID); + requestListSharedDomains(cloudFoundryClient, "test-domain-name"); requestListRoutes(this.cloudFoundryClient, "test-private-domain-id"); requestListSpaceServiceInstancesEmpty( this.cloudFoundryClient, "test-service-instance-name", TEST_SPACE_ID);