Browse Source

add getPlayer-Method and test

feat-userClient
Steffen Nitschke 4 years ago
parent
commit
83e1e16946
  1. 7
      fh.fd.ci.client/src/main/java/de/fd/fh/network/UserClient.java
  2. 35
      fh.fd.ci.client/src/test/java/de/fd/fh/network/UserClientTest.java

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

@ -15,4 +15,11 @@ public interface UserClient
@Param("authToken") final String authenticationHeader, @Param("authToken") final String authenticationHeader,
final ChangeUserRequest request final ChangeUserRequest request
); );
@RequestLine("GET /users/{userId}")
@Headers(Utils.AUTHENTICATION_HEADER + ":Bearer {authToken}")
PlayerResponse getPlayer(
@Param("authToken") final String authenticationHeader,
@Param("userId") final String userId
);
} }

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

@ -1,8 +1,10 @@
package de.fd.fh.network; 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.ChangeUserRequest;
import de.fd.fh.shared.network.messages.PlayerResponse; import de.fd.fh.shared.network.messages.PlayerResponse;
import feign.Feign; import feign.Feign;
import feign.Request;
import feign.gson.GsonDecoder; import feign.gson.GsonDecoder;
import feign.gson.GsonEncoder; import feign.gson.GsonEncoder;
import feign.mock.HttpMethod; import feign.mock.HttpMethod;
@ -11,8 +13,7 @@ import feign.mock.MockTarget;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
class UserClientTest class UserClientTest
{ {
@ -52,6 +53,34 @@ class UserClientTest
assertEquals("TestName", response.getName()); assertEquals("TestName", response.getName());
assertEquals("12345", response.getId().getIdentifier()); assertEquals("12345", response.getId().getIdentifier());
mockClient.verifyOne(HttpMethod.POST, "/users");
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 getPlayerTest()
{
mockClient.ok(HttpMethod.GET, "/users/12345",
"{\n" +
" \"id\": {\n" +
" \"identifier\":\"12345\"\n" +
" },\n" +
" \"name\":\"TestName\"\n" +
"}");
final PlayerResponse response = client.getPlayer("TestAuthHeader", "12345");
assertNotNull(response);
assertEquals("TestName", response.getName());
assertEquals("12345", response.getId().getIdentifier());
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());
} }
} }
Loading…
Cancel
Save