|
|
@ -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"); |
|
|
|
} |
|
|
|
} |