Skip to content

Commit c3e8232

Browse files
committed
AT improvements
* Remove log noise in ATs * Work around inability to create orgs with client credentials. Our AT setup was failing due to our use of client credentials in CFJC's `UaaClient`, in combination with cloudfoundry/cf-java-client#939.
1 parent fbdbf23 commit c3e8232

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryClientConfiguration.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class CloudFoundryClientConfiguration {
7575
protected CloudFoundryOperations cloudFoundryOperations(CloudFoundryProperties properties,
7676
CloudFoundryClient client,
7777
DopplerClient dopplerClient,
78-
UaaClient uaaClient) {
78+
@Qualifier("userCredentials") UaaClient uaaClient) {
7979
return DefaultCloudFoundryOperations.builder()
8080
.cloudFoundryClient(client)
8181
.dopplerClient(dopplerClient)
@@ -114,7 +114,18 @@ protected DopplerClient dopplerClient(ConnectionContext connectionContext,
114114
}
115115

116116
@Bean
117-
protected UaaClient uaaClient(ConnectionContext connectionContext,
117+
@Qualifier("userCredentials")
118+
protected UaaClient userCredentialsUaaClient(ConnectionContext connectionContext,
119+
@Qualifier("userCredentials") TokenProvider tokenProvider) {
120+
return ReactorUaaClient.builder()
121+
.connectionContext(connectionContext)
122+
.tokenProvider(tokenProvider)
123+
.build();
124+
}
125+
126+
@Bean
127+
@Qualifier("clientCredentials")
128+
protected UaaClient clientCredentialsUaaClient(ConnectionContext connectionContext,
118129
@Qualifier("clientCredentials") TokenProvider tokenProvider) {
119130
return ReactorUaaClient.builder()
120131
.connectionContext(connectionContext)

spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/cf/CloudFoundryService.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,26 @@ public Mono<Void> updateBrokerApp(String appName, String brokerClientId, List<St
176176
}
177177

178178
public Mono<Void> deleteApp(String appName) {
179-
return cloudFoundryOperations.applications().delete(DeleteApplicationRequest.builder()
180-
.name(appName)
181-
.deleteRoutes(true)
182-
.build())
179+
return cloudFoundryOperations.applications().list()
180+
.filter(app -> appName.equals(app.getName()))
181+
.singleOrEmpty()
182+
.flatMap(app -> cloudFoundryOperations.applications().delete(DeleteApplicationRequest.builder()
183+
.name(appName)
184+
.deleteRoutes(true)
185+
.build()))
183186
.doOnSuccess(item -> LOG.info("Success deleting app. appName={}", appName))
184187
.doOnError(e -> LOG.warn(String.format("Error deleting app. appName=%s, error=%s", appName,
185188
e.getMessage()), e))
186189
.onErrorResume(e -> Mono.empty());
187190
}
188191

189192
public Mono<Void> deleteServiceBroker(String brokerName) {
190-
return cloudFoundryOperations.serviceAdmin().delete(DeleteServiceBrokerRequest.builder()
191-
.name(brokerName)
192-
.build())
193+
return cloudFoundryOperations.serviceAdmin().list()
194+
.filter(serviceBroker -> brokerName.equals(serviceBroker.getName()))
195+
.singleOrEmpty()
196+
.flatMap(serviceBroker -> cloudFoundryOperations.serviceAdmin()
197+
.delete(DeleteServiceBrokerRequest.builder().name(brokerName).build())
198+
)
193199
.doOnSuccess(item -> LOG.info("Success deleting service broker. brokerName={}", brokerName))
194200
.doOnError(e -> LOG.warn(String.format("Error deleting service broker. brokerName=%s, error=%s ",
195201
brokerName, e.getMessage()), e))

spring-cloud-app-broker-acceptance-tests/src/test/java/org/springframework/cloud/appbroker/acceptance/fixtures/uaa/UaaService.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.slf4j.LoggerFactory;
2727
import reactor.core.publisher.Mono;
2828

29+
import org.springframework.beans.factory.annotation.Qualifier;
2930
import org.springframework.stereotype.Service;
3031

3132
@Service
@@ -35,7 +36,7 @@ public class UaaService {
3536

3637
private final UaaClient uaaClient;
3738

38-
public UaaService(UaaClient uaaClient) {
39+
public UaaService(@Qualifier("clientCredentials") UaaClient uaaClient) {
3940
this.uaaClient = uaaClient;
4041
}
4142

@@ -48,21 +49,19 @@ public Mono<GetClientResponse> getUaaClient(String clientId) {
4849
}
4950

5051
public Mono<Void> createClient(String clientId, String clientSecret, String... authorities) {
51-
return uaaClient.clients().delete(DeleteClientRequest
52-
.builder()
53-
.clientId(clientId)
54-
.build())
55-
.doOnError(error -> LOG.warn("Error deleting client: " + clientId + " with error: " + error))
56-
.onErrorResume(e -> Mono.empty())
57-
.then(uaaClient.clients().create(CreateClientRequest
58-
.builder()
59-
.clientId(clientId)
60-
.clientSecret(clientSecret)
61-
.authorizedGrantType(GrantType.CLIENT_CREDENTIALS)
62-
.authorities(authorities)
63-
.build())
64-
.doOnError(error -> LOG.error("Error creating client: " + clientId + " with error: " + error))
65-
.onErrorResume(e -> Mono.empty()))
52+
return getUaaClient(clientId)
53+
.flatMap(response -> uaaClient.clients()
54+
.delete(DeleteClientRequest.builder().clientId(clientId).build())
55+
.doOnError(error -> LOG.error("Error deleting client: " + clientId + " with error: " + error)))
56+
.then(uaaClient.clients()
57+
.create(CreateClientRequest
58+
.builder()
59+
.clientId(clientId)
60+
.clientSecret(clientSecret)
61+
.authorizedGrantType(GrantType.CLIENT_CREDENTIALS)
62+
.authorities(authorities)
63+
.build())
64+
.doOnError(error -> LOG.error("Error creating client: " + clientId + " with error: " + error)))
6665
.then();
6766
}
6867

0 commit comments

Comments
 (0)