4 Commits

  1. 2
      fh.fd.ci.client/src/main/java/de/fd/fh/network/FeignClients.java
  2. 32
      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. 110
      fh.fd.ci.client/src/test/java/de/fd/fh/network/UserClientTest.java
  5. 4
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/UserService.java
  6. 2
      fh.fd.ci.server/src/main/java/de/fd/fh/server/user/web/UserController.java
  7. 4
      fh.fd.ci.server/src/test/java/de/fd/fh/server/user/UserServiceTest.java
  8. 1
      fh.fd.ci.server/src/test/java/de/fd/fh/server/user/web/UserControllerTest.java
  9. 2
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/ChangeUserRequest.java
  10. 12
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/Identifier.java
  11. 13
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/PlayerResponse.java
  12. 2
      fh.fd.ci.shared/src/main/java/de/fd/fh/shared/network/messages/UserRequest.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 AccessClient accessClient;
private UserClient userClient;
public FeignClients()
{
accessClient = buildClient(AccessClient.class);
userClient = buildClient(UserClient.class);
}
<T> T buildClient(final Class<T> client)

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

@ -0,0 +1,32 @@
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;
public interface UserClient
{
@RequestLine("POST /users")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
PlayerResponse updatePlayer(
@Param("authToken") final String authenticationHeader,
final ChangeUserRequest request
);
@RequestLine("GET /users/{userId}")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
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
);
}

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());
}
}

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

@ -0,0 +1,110 @@
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;
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.*;
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());
final Request sended = mockClient.verifyOne(HttpMethod.POST, "/users");
assertTrue(sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().isPresent());
assertEquals("Bearer TestAuthHeader",
sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().get());
}
@Test
void getShortPlayerTest()
{
mockClient.ok(HttpMethod.GET, "/users/12345",
"{\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.getCurrentPlayer("TestAuthHeader");
assertNotNull(response);
assertEquals("TestName", response.getName());
assertEquals("12345", response.getId().getIdentifier());
final Request sended = mockClient.verifyOne(HttpMethod.GET, "/users");
assertTrue(sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().isPresent());
assertEquals("Bearer TestAuthHeader",
sended.headers().get(Utils.AUTHENTICATION_HEADER).stream().findFirst().get());
}
}

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

@ -2,8 +2,8 @@ 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.server.user.web.ChangeUserRequest;
import de.fd.fh.server.user.web.UserRequest;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
import de.fd.fh.shared.network.messages.UserRequest;
import lombok.RequiredArgsConstructor;
import java.util.Observable;

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

@ -6,6 +6,8 @@ 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.ChangeUserRequest;
import de.fd.fh.shared.network.messages.UserRequest;
import lombok.RequiredArgsConstructor;
import spark.Request;
import spark.Response;

4
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.server.user.web.ChangeUserRequest;
import de.fd.fh.server.user.web.UserRequest;
import de.fd.fh.shared.network.messages.ChangeUserRequest;
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/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.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;
}

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