Skip to content

Commit ad92bba

Browse files
committed
Merge branch '128161801-add-tests' into 2.0.x
2 parents ec4d235 + 9d38cd0 commit ad92bba

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

cloudfoundry-client/src/main/java/org/cloudfoundry/uaa/clients/AbstractClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ abstract class AbstractClient {
9090
* Epoch of the moment the client information was last altered
9191
*/
9292
@JsonProperty("lastModified")
93+
@Nullable
9394
abstract Long getLastModified();
9495

9596
/**

integration-test/src/test/java/org/cloudfoundry/uaa/ClientsTest.java

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
import io.netty.util.AsciiString;
2020
import org.cloudfoundry.AbstractIntegrationTest;
21+
import org.cloudfoundry.uaa.clients.BatchCreateClientsRequest;
22+
import org.cloudfoundry.uaa.clients.BatchCreateClientsResponse;
23+
import org.cloudfoundry.uaa.clients.BatchDeleteClientsRequest;
2124
import org.cloudfoundry.uaa.clients.Client;
25+
import org.cloudfoundry.uaa.clients.CreateClient;
2226
import org.cloudfoundry.uaa.clients.CreateClientRequest;
2327
import org.cloudfoundry.uaa.clients.CreateClientResponse;
2428
import org.cloudfoundry.uaa.clients.DeleteClientRequest;
@@ -64,16 +68,60 @@ public void batchChangeSecret() {
6468
//
6569
}
6670

67-
@Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125554031")
6871
@Test
6972
public void batchCreate() {
70-
//
73+
String clientId1 = this.nameFactory.getClientId();
74+
String clientId2 = this.nameFactory.getClientId();
75+
String clientSecret = this.nameFactory.getClientSecret();
76+
77+
this.uaaClient.clients()
78+
.batchCreate(BatchCreateClientsRequest.builder()
79+
.client(CreateClient.builder()
80+
.approvalsDeleted(true)
81+
.authorizedGrantType(PASSWORD)
82+
.clientId(clientId1)
83+
.clientSecret(clientSecret)
84+
.scope("client.read", "client.write")
85+
.tokenSalt("test-token-salt")
86+
.build())
87+
.client(CreateClient.builder()
88+
.approvalsDeleted(true)
89+
.authorizedGrantType(PASSWORD, REFRESH_TOKEN)
90+
.clientId(clientId2)
91+
.clientSecret(clientSecret)
92+
.scope("client.write")
93+
.tokenSalt("filtered-test-token-salt")
94+
.build())
95+
.build())
96+
.flatMapIterable(BatchCreateClientsResponse::getClients)
97+
.filter(client -> clientId1.equals(client.getClientId()))
98+
.subscribe(this.<Client>testSubscriber()
99+
.expectThat(response -> {
100+
assertEquals(Arrays.asList(PASSWORD, REFRESH_TOKEN), response.getAuthorizedGrantTypes());
101+
assertEquals(clientId1, response.getClientId());
102+
assertEquals(Arrays.asList("client.read", "client.write"), response.getScopes());
103+
assertEquals("test-token-salt", response.getTokenSalt());
104+
}));
71105
}
72106

73-
@Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125575011")
74107
@Test
75108
public void batchDelete() {
76-
//
109+
String clientId1 = this.nameFactory.getClientId();
110+
String clientId2 = this.nameFactory.getClientId();
111+
String clientSecret = this.nameFactory.getClientSecret();
112+
113+
batchCreateClients(this.uaaClient, clientId1, clientId2, clientSecret)
114+
.flatMapIterable(BatchCreateClientsResponse::getClients)
115+
.map(Client::getClientId)
116+
.collectList()
117+
.then(clientIds -> this.uaaClient.clients()
118+
.batchDelete(BatchDeleteClientsRequest.builder()
119+
.clientIds(clientIds)
120+
.build()))
121+
.flatMap(ignore -> requestListClients(this.uaaClient))
122+
.filter(client -> clientId1.equals(client.getClientId()) || clientId2.equals(client.getClientId()))
123+
.subscribe(this.testSubscriber()
124+
.expectCount(0));
77125
}
78126

79127
@Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125572281")
@@ -240,6 +288,28 @@ public void updateMetadata() {
240288
}));
241289
}
242290

291+
private static Mono<BatchCreateClientsResponse> batchCreateClients(UaaClient uaaClient, String clientId1, String clientId2, String clientSecret) {
292+
return uaaClient.clients()
293+
.batchCreate(BatchCreateClientsRequest.builder()
294+
.client(CreateClient.builder()
295+
.approvalsDeleted(true)
296+
.authorizedGrantType(PASSWORD)
297+
.clientId(clientId1)
298+
.clientSecret(clientSecret)
299+
.scope("client.read", "client.write")
300+
.tokenSalt("test-token-salt")
301+
.build())
302+
.client(CreateClient.builder()
303+
.approvalsDeleted(true)
304+
.authorizedGrantType(PASSWORD, REFRESH_TOKEN)
305+
.clientId(clientId2)
306+
.clientSecret(clientSecret)
307+
.scope("client.write")
308+
.tokenSalt("alternate-test-token-salt")
309+
.build())
310+
.build());
311+
}
312+
243313
private static Mono<CreateClientResponse> requestCreateClient(UaaClient uaaClient, String clientId, String clientSecret) {
244314
return uaaClient.clients()
245315
.create(CreateClientRequest.builder()

0 commit comments

Comments
 (0)