Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ Name | Description
`TEST_PROXY_USERNAME` | _(Optional)_ The username for a proxy to route all requests through
`TEST_SKIPSSLVALIDATION` | _(Optional)_ Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to `false`.
`UAA_API_REQUEST_LIMIT` | _(Optional)_ If your UAA server does rate limiting and returns 429 errors, set this variable to the smallest limit configured there. Whether your server limits UAA calls is shown in the log, together with the location of the configuration file on the server. Defaults to `0` (no limit).
`SKIP_BROWSER_AUTH_TESTS` | _(Optional)_ Set to `true` to skip integration tests that require browser-based authentication (e.g., SSO tests). Useful when the Cloud Foundry instance does not support browser-based authentication or when running tests in a non-interactive environment. Defaults to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really about "non-interactive" environments? Do we support interactive environments in our tests? Or is it about some UAA configuration that has browser-based auth?

`SKIP_METRIC_REGISTRAR_TESTS` | _(Optional)_ Set to `true` to skip integration tests that require the Metric Registrar service (e.g., MetricRegistrarTest). Useful when the Cloud Foundry instance does not have the Metric Registrar service available. Defaults to `false`.
`SKIP_TCP_ROUTING_TESTS` | _(Optional)_ Set to `true` to skip TCP routing integration tests (TcpRoutesTest, RouterGroupsTest). Useful when the Cloud Foundry instance does not have TCP routing configured (i.e., no `routing_endpoint` in the info payload). Defaults to `false`.
`SKIP_V2_TESTS` | _(Optional)_ Set to `true` to skip all V2 API integration tests. Useful when the Cloud Foundry V2 API is rate-limited or unavailable. When enabled, tests annotated with `@RequiresV2Api` will be skipped, including V3 tests that depend on V2 API calls (e.g., service broker creation). Defaults to `false`.

If you do not have access to a CloudFoundry instance with admin access, you can run one locally using [bosh-deployment](https://github.com/cloudfoundry/bosh-deployment) & [cf-deployment](https://github.com/cloudfoundry/cf-deployment/) and Virtualbox.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.cloudfoundry.client.v3.Metadata;
import org.cloudfoundry.client.v3.Relationship;
import org.cloudfoundry.client.v3.applications.Application;
import org.cloudfoundry.client.v3.applications.ApplicationResource;
import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest;
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipRequest;
Expand Down Expand Up @@ -129,6 +130,12 @@ final class CloudFoundryCleaner implements InitializingBean, DisposableBean {

private static final Logger LOGGER = LoggerFactory.getLogger("cloudfoundry-client.test");

private static final boolean RUN_V2_CLEANUP = isRunV2Tests();

private static boolean isRunV2Tests() {
return !"true".equalsIgnoreCase(System.getenv("SKIP_V2_TESTS"));
}
Comment on lines +133 to +137
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this in RequiresV2Api so the condition is shared.


private static final Map<String, Boolean> STANDARD_FEATURE_FLAGS =
FluentMap.<String, Boolean>builder()
.entry("app_bits_upload", true)
Expand Down Expand Up @@ -186,6 +193,32 @@ public void destroy() {
}

void clean() {
if (!RUN_V2_CLEANUP) {
LOGGER.info("Skipping V2 API cleanup operations (SKIP_V2_TESTS=true)");
// Only run V3 and UAA cleanup operations
Flux.empty()
.thenMany(
Mono.when( // No prerequisites - V3/UAA only
cleanClients(this.uaaClient, this.nameFactory),
cleanGroups(this.uaaClient, this.nameFactory),
cleanIdentityProviders(this.uaaClient, this.nameFactory),
cleanIdentityZones(this.uaaClient, this.nameFactory),
cleanUsersV3(this.cloudFoundryClient, this.nameFactory)))
.thenMany(
Mono.when(
cleanApplicationsV3(
this.cloudFoundryClient,
this.nameFactory,
false), // runV2Calls = false (V3-only path)
cleanUsers(this.uaaClient, this.nameFactory)))
.retryWhen(Retry.max(5).filter(SSLException.class::isInstance))
.doOnSubscribe(s -> LOGGER.debug(">> CLEANUP (V3 only) <<"))
.doOnComplete(() -> LOGGER.debug("<< CLEANUP (V3 only) >>"))
.then()
.block(Duration.ofMinutes(30));
return;
}

Flux.empty()
.thenMany(
Mono.when( // Before Routes
Expand Down Expand Up @@ -218,7 +251,8 @@ void clean() {
Mono.when(
cleanApplicationsV3(
this.cloudFoundryClient,
this.nameFactory), // After Routes, cannot run with
this.nameFactory,
true), // After Routes, cannot run with
// other cleanApps
cleanUsers(this.uaaClient, this.nameFactory) // After CF Users
))
Expand All @@ -241,32 +275,43 @@ void clean() {
}

private static Flux<Void> cleanApplicationsV3(
CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
return PaginationUtils.requestClientV3Resources(
page ->
cloudFoundryClient
.applicationsV3()
.list(ListApplicationsRequest.builder().page(page).build()))
.filter(application -> nameFactory.isApplicationName(application.getName()))
.delayUntil(
application ->
removeApplicationServiceBindings(cloudFoundryClient, application))
.flatMap(
application ->
cloudFoundryClient
.applicationsV3()
.delete(
DeleteApplicationRequest.builder()
.applicationId(application.getId())
.build())
.then()
.doOnError(
t ->
LOGGER.error(
"Unable to delete V3 application"
+ " {}",
application.getName(),
t)));
CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, boolean runV2Calls) {
Flux<ApplicationResource> apps =
PaginationUtils.requestClientV3Resources(
page ->
cloudFoundryClient
.applicationsV3()
.list(
ListApplicationsRequest.builder()
.page(page)
.build()))
.filter(
application ->
nameFactory.isApplicationName(application.getName()));

if (runV2Calls) {
apps =
apps.delayUntil(
application ->
removeApplicationServiceBindings(
cloudFoundryClient, application));
}
Comment on lines +292 to +298
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only v2 calls, which lists then deletes service bindings.
Can we port it to v3 instead of gating it with a boolean?


return apps.flatMap(
application ->
cloudFoundryClient
.applicationsV3()
.delete(
DeleteApplicationRequest.builder()
.applicationId(application.getId())
.build())
.then()
.doOnError(
t ->
LOGGER.error(
"Unable to delete V3 application" + " {}",
application.getName(),
t)));
}

private static Flux<Void> cleanBuildpacks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
Expand Down Expand Up @@ -350,6 +351,7 @@ RandomNameFactory nameFactory() {

@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's centralize this property name, e.g. in RequiresV2Api.

Mono<String> metricRegistrarServiceInstance(
CloudFoundryClient cloudFoundryClient, Mono<String> spaceId, NameFactory nameFactory) {
return spaceId.flatMap(
Expand Down Expand Up @@ -377,6 +379,7 @@ NetworkingClient networkingClient(

@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Mono<String> organizationId(
CloudFoundryClient cloudFoundryClient,
String organizationName,
Expand Down Expand Up @@ -516,6 +519,7 @@ String serviceName(NameFactory nameFactory) {

@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Mono<String> spaceId(
CloudFoundryClient cloudFoundryClient, Mono<String> organizationId, String spaceName) {
return organizationId
Expand All @@ -542,6 +546,7 @@ String spaceName(NameFactory nameFactory) {

@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackName) {
return stackName
.flux()
Expand Down Expand Up @@ -570,6 +575,7 @@ Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackNa
*/
@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Mono<String> stackName(CloudFoundryClient cloudFoundryClient) {
return PaginationUtils.requestClientV2Resources(
page ->
Expand All @@ -587,6 +593,7 @@ Mono<String> stackName(CloudFoundryClient cloudFoundryClient) {
@Lazy
@Bean(initMethod = "block")
@DependsOn("cloudFoundryCleaner")
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp(
CloudFoundryClient cloudFoundryClient,
Mono<String> spaceId,
Expand Down Expand Up @@ -623,6 +630,7 @@ String testLogCacheAppName(NameFactory nameFactory) {

@Lazy
@Bean
@ConditionalOnProperty(name = "SKIP_V2_TESTS", havingValue = "false", matchIfMissing = true)
TestLogCacheEndpoints testLogCacheEndpoints(
ConnectionContext connectionContext,
TokenProvider tokenProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
* Annotation to mark tests that require browser-based authentication (e.g., OAuth
* authorization code grants, implicit grants). Tests annotated with this will be skipped
* if the environment variable {@code SKIP_BROWSER_AUTH_TESTS} is set to "true".
*
* <p>Usage:
* <pre>
* &#64;RequiresBrowserAuth
* public class MyAuthTest extends AbstractIntegrationTest {
* // ...
* }
* </pre>
*
* <p>To skip browser auth tests, set the environment variable:
* <pre>
* export SKIP_BROWSER_AUTH_TESTS=true
* </pre>
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ExtendWith(RequiresBrowserAuth.BrowserAuthCondition.class)
public @interface RequiresBrowserAuth {

/**
* JUnit 5 ExecutionCondition that checks if Browser Auth tests should be skipped.
*/
class BrowserAuthCondition implements ExecutionCondition {

private static final String SKIP_BROWSER_AUTH_ENV = "SKIP_BROWSER_AUTH_TESTS";

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if ("true".equalsIgnoreCase(System.getenv(SKIP_BROWSER_AUTH_ENV))) {
return ConditionEvaluationResult.disabled(
"Tests requiring Browser Authentication are disabled via "
+ SKIP_BROWSER_AUTH_ENV
+ " environment variable");
}

return ConditionEvaluationResult.enabled("Browser authentication tests are enabled");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.cloudfoundry;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
* Annotation to mark tests that require the Metric Registrar service to be available.
* Tests annotated with this will be skipped if the environment variable
* {@code SKIP_METRIC_REGISTRAR_TESTS} is set to "true".
*
* <p>Usage:
* <pre>
* &#64;RequiresMetricRegistrar
* public class MetricTest extends AbstractIntegrationTest {
* // ...
* }
* </pre>
*
* <p>To skip metric registrar tests, set the environment variable:
* <pre>
* export SKIP_METRIC_REGISTRAR_TESTS=true
* </pre>
*/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ExtendWith(RequiresMetricRegistrar.RegistrarCondition.class)
public @interface RequiresMetricRegistrar {

/**
* JUnit 5 ExecutionCondition that checks if Metric Registrar tests should be skipped.
*/
class RegistrarCondition implements ExecutionCondition {

private static final String SKIP_REGISTRAR_ENV = "SKIP_METRIC_REGISTRAR_TESTS";

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if ("true".equalsIgnoreCase(System.getenv(SKIP_REGISTRAR_ENV))) {
return ConditionEvaluationResult.disabled(
"Tests requiring Metric Registrar Service are disabled via "
+ SKIP_REGISTRAR_ENV
+ " environment variable.");
}

return ConditionEvaluationResult.enabled("Metric Registrar tests are enabled");
}
}
}
Loading
Loading