Skip to content

Commit 281649f

Browse files
Added test case for user version 3 API
1 parent 0a433f8 commit 281649f

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

  • integration-test/src/test/java/org/cloudfoundry/client/v3
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3;
18+
19+
import org.cloudfoundry.AbstractIntegrationTest;
20+
import org.cloudfoundry.CloudFoundryVersion;
21+
import org.cloudfoundry.IfCloudFoundryVersion;
22+
import org.cloudfoundry.client.CloudFoundryClient;
23+
import org.cloudfoundry.client.v3.users.*;
24+
import org.cloudfoundry.util.PaginationUtils;
25+
import org.junit.jupiter.api.Test;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import reactor.core.publisher.Mono;
28+
import reactor.test.StepVerifier;
29+
30+
import java.time.Duration;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
34+
@IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_4_v3)
35+
public final class UsersTest extends AbstractIntegrationTest {
36+
37+
@Autowired
38+
private CloudFoundryClient cloudFoundryClient;
39+
40+
@Test
41+
public void create() {
42+
String userId = this.nameFactory.getUserId();
43+
44+
this.cloudFoundryClient
45+
.usersV3()
46+
.create(CreateUserRequest.builder()
47+
.userId(userId)
48+
.build()
49+
)
50+
.single()
51+
.as(StepVerifier::create)
52+
.expectNextCount(1)
53+
.expectComplete()
54+
.verify(Duration.ofMinutes(5));
55+
}
56+
57+
@Test
58+
public void get() {
59+
String userId = this.nameFactory.getUserId();
60+
61+
createUser(this.cloudFoundryClient, userId)
62+
.flatMap(createUserResponse ->
63+
this.cloudFoundryClient.usersV3()
64+
.get(GetUserRequest.builder()
65+
.userId(userId)
66+
.build()))
67+
.map(GetUserResponse::getId)
68+
.as(StepVerifier::create)
69+
.expectNext(userId)
70+
.expectComplete()
71+
.verify(Duration.ofMinutes(5));
72+
}
73+
74+
@Test
75+
public void list() {
76+
String userId = this.nameFactory.getUserId();
77+
createUser(this.cloudFoundryClient, userId)
78+
.thenMany(
79+
PaginationUtils.requestClientV3Resources(
80+
page ->
81+
this.cloudFoundryClient
82+
.usersV3()
83+
.list(
84+
ListUsersRequest.builder()
85+
.page(page)
86+
.build())))
87+
.filter(resource -> userId.equals(resource.getId()))
88+
.map(UserResource::getId)
89+
.as(StepVerifier::create)
90+
.expectNext(userId)
91+
.expectComplete()
92+
.verify(Duration.ofMinutes(5));
93+
}
94+
95+
@Test
96+
public void update() {
97+
String userId = this.nameFactory.getUserId();
98+
99+
createUser(this.cloudFoundryClient, userId)
100+
.flatMap(createUserResponse ->
101+
this.cloudFoundryClient.usersV3()
102+
.update(UpdateUserRequest.builder()
103+
.userId(userId)
104+
.metadata(Metadata.builder()
105+
.annotation(
106+
"annotationKey",
107+
"annotationValue")
108+
.label(
109+
"labelKey",
110+
"labelValue")
111+
.build())
112+
.build()))
113+
.then(getUser(cloudFoundryClient, userId))
114+
.as(StepVerifier::create)
115+
.consumeNextWith(
116+
GetUserResponse -> {
117+
Metadata metadata = GetUserResponse.getMetadata();
118+
assertThat(metadata.getAnnotations().get("annotationKey"))
119+
.isEqualTo("annotationValue");
120+
assertThat(metadata.getLabels().get("labelKey"))
121+
.isEqualTo("labelValue");
122+
})
123+
.expectComplete()
124+
.verify(Duration.ofMinutes(5));
125+
126+
}
127+
128+
@Test
129+
public void delete() {
130+
String userId = this.nameFactory.getUserId();
131+
132+
createUser(this.cloudFoundryClient, userId)
133+
.flatMap(
134+
createUserResponse ->
135+
this.cloudFoundryClient
136+
.usersV3()
137+
.delete(
138+
DeleteUserRequest.builder()
139+
.userId(createUserResponse.getId())
140+
.build()))
141+
.as(StepVerifier::create)
142+
.expectComplete()
143+
.verify(Duration.ofMinutes(5));
144+
}
145+
146+
private static Mono<CreateUserResponse> createUser(
147+
CloudFoundryClient cloudFoundryClient, String userId) {
148+
return cloudFoundryClient
149+
.usersV3()
150+
.create(CreateUserRequest.builder().userId(userId).build());
151+
}
152+
153+
private static Mono<GetUserResponse> getUser(
154+
CloudFoundryClient cloudFoundryClient, String userId) {
155+
return cloudFoundryClient
156+
.usersV3()
157+
.get(GetUserRequest.builder().userId(userId).build());
158+
}
159+
}

0 commit comments

Comments
 (0)