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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.cloudfoundry.client.v3.spaces.SpacesV3;
import org.cloudfoundry.client.v3.stacks.StacksV3;
import org.cloudfoundry.client.v3.tasks.Tasks;
import org.cloudfoundry.client.v3.users.UsersV3;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.TokenProvider;
import org.cloudfoundry.reactor.client.v2.applications.ReactorApplicationsV2;
Expand Down Expand Up @@ -133,6 +134,7 @@
import org.cloudfoundry.reactor.client.v3.spaces.ReactorSpacesV3;
import org.cloudfoundry.reactor.client.v3.stacks.ReactorStacksV3;
import org.cloudfoundry.reactor.client.v3.tasks.ReactorTasks;
import org.cloudfoundry.reactor.client.v3.users.ReactorUsersV3;
import org.immutables.value.Value;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -500,6 +502,12 @@ public Users users() {
return new ReactorUsers(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags());
}

@Override
@Value.Derived
public UsersV3 usersV3() {
return new ReactorUsersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags());
}

/**
* The connection context
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2013-2021 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.reactor.client.v3.users;

import org.cloudfoundry.client.v3.users.*;
import org.cloudfoundry.reactor.ConnectionContext;
import org.cloudfoundry.reactor.TokenProvider;
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
* The Reactor-based implementation of {@link UsersV3}
*/
public class ReactorUsersV3 extends AbstractClientV3Operations implements UsersV3 {

/**
* Creates an instance
*
* @param connectionContext the {@link ConnectionContext} to use when communicating with the server
* @param root the root URI of the server. Typically, something like {@code https://api.cloudfoundry.your.company.com}.
* @param tokenProvider the {@link TokenProvider} to use when communicating with the server
* @param requestTags map with custom http headers which will be added to web request
*/
public ReactorUsersV3(
ConnectionContext connectionContext,
Mono<String> root,
TokenProvider tokenProvider,
Map<String, String> requestTags) {
super(connectionContext, root, tokenProvider, requestTags);
}

@Override
public Mono<CreateUserResponse> create(CreateUserRequest request) {
return post(
request,
CreateUserResponse.class,
builder -> builder.pathSegment("users"))
.checkpoint();
}

@Override
public Mono<GetUserResponse> get(GetUserRequest request) {
return get(
request,
GetUserResponse.class,
builder -> builder.pathSegment("users", request.getUserId()))
.checkpoint();
}

@Override
public Mono<UpdateUserResponse> update(UpdateUserRequest request) {
return patch(
request,
UpdateUserResponse.class,
builder -> builder.pathSegment("users", request.getUserId()))
.checkpoint();
}

@Override
public Mono<Void> delete(DeleteUserRequest request) {
return delete(
request,
Void.class,
builder -> builder.pathSegment("users", request.getUserId()))
.checkpoint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* Copyright 2013-2021 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.reactor.client.v3.users;

import org.cloudfoundry.client.v3.Link;
import org.cloudfoundry.client.v3.Metadata;
import org.cloudfoundry.client.v3.users.*;
import org.cloudfoundry.reactor.InteractionContext;
import org.cloudfoundry.reactor.TestRequest;
import org.cloudfoundry.reactor.TestResponse;
import org.cloudfoundry.reactor.client.AbstractClientApiTest;
import org.junit.jupiter.api.Test;
import reactor.test.StepVerifier;

import java.time.Duration;
import java.util.Collections;
import java.util.Map;

import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;

final class ReactorUsersTest extends AbstractClientApiTest {
private final ReactorUsersV3 users =
new ReactorUsersV3(CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap());

@Test
void create() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(POST)
.path("/users")
.payload(
"fixtures/client/v3/users/POST_request.json")
.build())
.response(
TestResponse.builder()
.status(CREATED)
.payload(
"fixtures/client/v3/users/POST_response.json")
.build())
.build());

this.users
.create(CreateUserRequest.builder()
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build()
)
.as(StepVerifier::create)
.expectNext(
CreateUserResponse.builder()
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.createdAt("2019-03-08T01:06:19Z")
.updatedAt("2019-03-08T01:06:19Z")
.username("some-name")
.presentationName("some-name")
.origin("uaa")
.metadata(
Metadata.builder()
.putAllAnnotations(Collections.emptyMap())
.putAllLabels(Collections.emptyMap())
.build())
.link(
"self",
Link.builder()
.href(
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build())
.build()
)
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@Test
void get() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(GET)
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build())
.response(
TestResponse.builder()
.status(OK)
.payload(
"fixtures/client/v3/users/GET_{id}_response.json")
.build())
.build());

this.users
.get(GetUserRequest.builder()
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build()
)
.as(StepVerifier::create)
.expectNext(
GetUserResponse.builder()
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.createdAt("2019-03-08T01:06:19Z")
.updatedAt("2019-03-08T01:06:19Z")
.username("some-name")
.presentationName("some-name")
.origin("uaa")
.metadata(
Metadata.builder()
.putAllAnnotations(Collections.emptyMap())
.putAllLabels(Collections.emptyMap())
.build())
.link(
"self",
Link.builder()
.href(
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build())
.build()
)
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@Test
void update() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(PATCH)
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.payload(
"fixtures/client/v3/users/PATCH_{id}_request.json")
.build())
.response(
TestResponse.builder()
.status(CREATED)
.payload(
"fixtures/client/v3/users/PATCH_{id}_response.json")
.build())
.build());

this.users
.update(UpdateUserRequest.builder()
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.metadata(Metadata.builder()
.putAllAnnotations(Map.of("note", "detailed information"))
.putAllLabels(Map.of("environment", "production"))
.build())
.build()
)
.as(StepVerifier::create)
.expectNext(
UpdateUserResponse.builder()
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.createdAt("2019-03-08T01:06:19Z")
.updatedAt("2019-03-08T01:06:19Z")
.username("some-name")
.presentationName("some-name")
.origin("uaa")
.metadata(Metadata.builder()
.putAllAnnotations(Map.of("note", "detailed information"))
.putAllLabels(Map.of("environment", "production"))
.build())
.link(
"self",
Link.builder()
.href(
"https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build())
.build()
)
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@Test
void delete() {
mockRequest(
InteractionContext.builder()
.request(
TestRequest.builder()
.method(DELETE)
.path("/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build())
.response(
TestResponse.builder()
.status(ACCEPTED)
.build())
.build());

this.users
.delete(DeleteUserRequest.builder()
.userId("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
.build()
)
.as(StepVerifier::create)
.expectComplete()
.verify(Duration.ofSeconds(5));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
"created_at": "2019-03-08T01:06:19Z",
"updated_at": "2019-03-08T01:06:19Z",
"username": "some-name",
"presentation_name": "some-name",
"origin": "uaa",
"metadata": {
"labels": {},
"annotations": {}
},
"links": {
"self": {
"href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"metadata": {
"labels": {
"environment": "production"
},
"annotations": {
"note": "detailed information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
"created_at": "2019-03-08T01:06:19Z",
"updated_at": "2019-03-08T01:06:19Z",
"username": "some-name",
"presentation_name": "some-name",
"origin": "uaa",
"metadata": {
"labels": {
"environment": "production"
},
"annotations": {
"note": "detailed information"
}
},
"links": {
"self": {
"href": "https://api.example.org/v3/users/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
}
Loading