Browse Source

add UserClient with updateUser-Method and test

feat-userClient
Steffen Nitschke 4 years ago
parent
commit
f6afde28f9
  1. 2
      fh.fd.ci.client/src/main/java/de/fd/fh/network/FeignClients.java
  2. 18
      fh.fd.ci.client/src/main/java/de/fd/fh/network/UserClient.java
  3. 17
      fh.fd.ci.client/src/test/java/de/fd/fh/network/FeignClientsTest.java
  4. 57
      fh.fd.ci.client/src/test/java/de/fd/fh/network/UserClientTest.java
  5. 2
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/UserService.java
  6. 1
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java
  7. 2
      fh.fd.ci.server/src/test/java/de/fd/fh/server/user/UserServiceTest.java
  8. 2
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/ChangeUserRequest.java
  9. 12
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/Identifier.java
  10. 13
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/PlayerResponse.java

2
fh.fd.ci.client/src/main/java/de/fd/fh/network/FeignClients.java

@ -12,10 +12,12 @@ public class FeignClients
private static final String BASE_URL = "http://localhost:4567"; private static final String BASE_URL = "http://localhost:4567";
private AccessClient accessClient; private AccessClient accessClient;
private UserClient userClient;
public FeignClients() public FeignClients()
{ {
accessClient = buildClient(AccessClient.class); accessClient = buildClient(AccessClient.class);
userClient = buildClient(UserClient.class);
} }
<T> T buildClient(final Class<T> client) <T> T buildClient(final Class<T> client)

18
fh.fd.ci.client/src/main/java/de/fd/fh/network/UserClient.java

@ -0,0 +1,18 @@
package de.fd.fh.network;
import de.fd.fh.shared.Utils;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import de.fd.fh.shared.network.messages.PlayerResponse;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
public interface UserClient
{
@RequestLine("POST /users")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
PlayerResponse updatePlayer(
@Param("authToken") final String authenticationHeader,
final ChangeUserRequest request
);
}

17
fh.fd.ci.client/src/test/java/de/fd/fh/network/FeignClientsTest.java

@ -0,0 +1,17 @@
package de.fd.fh.network;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class FeignClientsTest
{
@Test
void testInitFeignClients()
{
final FeignClients feignClients = new FeignClients();
assertNotNull(feignClients.getAccessClient());
assertNotNull(feignClients.getUserClient());
}
}

57
fh.fd.ci.client/src/test/java/de/fd/fh/network/UserClientTest.java

@ -0,0 +1,57 @@
package de.fd.fh.network;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import de.fd.fh.shared.network.messages.PlayerResponse;
import feign.Feign;
import feign.gson.GsonDecoder;
import feign.gson.GsonEncoder;
import feign.mock.HttpMethod;
import feign.mock.MockClient;
import feign.mock.MockTarget;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class UserClientTest
{
private UserClient client;
private MockClient mockClient;
@BeforeEach
void before()
{
mockClient = new MockClient();
client = Feign.builder()
.decoder(new GsonDecoder())
.encoder(new GsonEncoder())
.client(mockClient)
.target(new MockTarget<>(UserClient.class));
}
@Test
void updatePlayer()
{
mockClient.ok(HttpMethod.POST, "/users",
"{\n" +
" \"id\": {\n" +
" \"identifier\":\"12345\"\n" +
" },\n" +
" \"name\":\"TestName\"\n" +
"}");
final ChangeUserRequest request = new ChangeUserRequest(
"TestName",
"TestPassword");
final PlayerResponse response = client.updatePlayer("TestAuthHeader", request);
assertNotNull(response);
assertEquals("TestName", response.getName());
assertEquals("12345", response.getId().getIdentifier());
mockClient.verifyOne(HttpMethod.POST, "/users");
}
}

2
fh.fd.ci.server/src/main/java/de/fd/fh/server/user/UserService.java

@ -2,7 +2,7 @@ package de.fd.fh.server.user;
import de.fd.fh.server.user.events.ChangePasswordEvent; import de.fd.fh.server.user.events.ChangePasswordEvent;
import de.fd.fh.server.user.events.ChangeUserNameEvent; import de.fd.fh.server.user.events.ChangeUserNameEvent;
import de.fd.fh.server.user.web.ChangeUserRequest;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import de.fd.fh.server.user.web.UserRequest; import de.fd.fh.server.user.web.UserRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

1
fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java

@ -6,6 +6,7 @@ import de.fd.fh.server.access.AccessToken;
import de.fd.fh.server.user.User; import de.fd.fh.server.user.User;
import de.fd.fh.server.user.UserId; import de.fd.fh.server.user.UserId;
import de.fd.fh.server.user.UserService; import de.fd.fh.server.user.UserService;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import spark.Request; import spark.Request;
import spark.Response; import spark.Response;

2
fh.fd.ci.server/src/test/java/de/fd/fh/server/user/UserServiceTest.java

@ -1,6 +1,6 @@
package de.fd.fh.server.user; package de.fd.fh.server.user;
import de.fd.fh.server.user.web.ChangeUserRequest;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import de.fd.fh.server.user.web.UserRequest; import de.fd.fh.server.user.web.UserRequest;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

2
fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/ChangeUserRequest.java → fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/ChangeUserRequest.java

@ -1,4 +1,4 @@
package de.fd.fh.server.user.web;
package de.fd.fh.shared.network.messages;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;

12
fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/Identifier.java

@ -0,0 +1,12 @@
package de.fd.fh.shared.network.messages;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class Identifier
{
private String identifier;
}

13
fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/PlayerResponse.java

@ -0,0 +1,13 @@
package de.fd.fh.shared.network.messages;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class PlayerResponse
{
private final Identifier id;
private String name;
}
Loading…
Cancel
Save