Browse Source

add getCurrentPlayer-Method and test and adjust getPlayer-Method

feat-userClient
Steffen Nitschke 4 years ago
parent
commit
b9654f8697
  1. 9
      fh.fd.ci.client/src/main/java/de/fd/fh/network/UserClient.java
  2. 32
      fh.fd.ci.client/src/test/java/de/fd/fh/network/UserClientTest.java
  3. 2
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/UserService.java
  4. 1
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java
  5. 2
      fh.fd.ci.server/src/test/java/de/fd/fh/server/user/UserServiceTest.java
  6. 1
      fh.fd.ci.server/src/test/java/de/fd/fh/server/user/web/UserControllerTest.java
  7. 2
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/UserRequest.java

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

@ -3,6 +3,7 @@ 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 de.fd.fh.shared.network.messages.UserRequest;
import feign.Headers;
import feign.Param;
import feign.RequestLine;
@ -18,8 +19,14 @@ public interface UserClient
@RequestLine("GET /users/{userId}")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
PlayerResponse getPlayer(
UserRequest getShortPlayer(
@Param("authToken") final String authenticationHeader,
@Param("userId") final String userId
);
@RequestLine("GET /users")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
PlayerResponse getCurrentPlayer(
@Param("authToken") final String authenticationHeader
);
}

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

@ -3,6 +3,7 @@ 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 de.fd.fh.shared.network.messages.UserRequest;
import feign.Feign;
import feign.Request;
import feign.gson.GsonDecoder;
@ -61,23 +62,46 @@ class UserClientTest
}
@Test
void getPlayerTest()
void getShortPlayerTest()
{
mockClient.ok(HttpMethod.GET, "/users/12345",
"{\n" +
" \"id\": {\n" +
" \"id\":\"12345\",\n" +
" \"name\":\"TestName\"\n" +
"}");
final UserRequest response = client.getShortPlayer("TestAuthHeader", "12345");
assertNotNull(response);
assertEquals("TestName", response.getName());
assertEquals("12345", response.getId());
final Request sended = mockClient.verifyOne(HttpMethod.GET, "/users/12345");
assertTrue(sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().isPresent());
assertEquals("Bearer TestAuthHeader",
sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().get());
}
@Test
void getCurrentPlayerTest()
{
mockClient.ok(HttpMethod.GET, "/users",
"{\n" +
" \"id\":\n" +
" {\n" +
" \"identifier\":\"12345\"\n" +
" },\n" +
" \"name\":\"TestName\"\n" +
"}");
final PlayerResponse response = client.getPlayer("TestAuthHeader", "12345");
final PlayerResponse response = client.getCurrentPlayer("TestAuthHeader");
assertNotNull(response);
assertEquals("TestName", response.getName());
assertEquals("12345", response.getId().getIdentifier());
final Request sended = mockClient.verifyOne(HttpMethod.GET, "/users/12345");
final Request sended = mockClient.verifyOne(HttpMethod.GET, "/users");
assertTrue(sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().isPresent());
assertEquals("Bearer TestAuthHeader",

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

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

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

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

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

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

1
fh.fd.ci.server/src/test/java/de/fd/fh/server/user/web/UserControllerTest.java

@ -5,6 +5,7 @@ import de.fd.fh.server.access.AccessToken;
import de.fd.fh.server.user.User;
import de.fd.fh.server.user.UserId;
import de.fd.fh.server.user.UserService;
import de.fd.fh.shared.network.messages.UserRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

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

@ -1,4 +1,4 @@
package de.fd.fh.server.user.web;
package de.fd.fh.shared.network.messages;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Loading…
Cancel
Save