test: completed MessageDeserializationTest
This commit is contained in:
parent
3e02d86700
commit
173fc70c3b
@ -9,7 +9,7 @@ import uulm.teamname.marvelous.gamelibrary.messages.*;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
public class MessageDeserializerTest {
|
public class MessageDeserializationTest {
|
||||||
|
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class MessageDeserializerTest {
|
|||||||
// message.messageType = MessageType.CONFIRM_SELECTION;
|
// message.messageType = MessageType.CONFIRM_SELECTION;
|
||||||
message.selectionComplete = true;
|
message.selectionComplete = true;
|
||||||
|
|
||||||
assertThat(mapper.readValue(jsonRepresentingMessage, ConfirmSelectionMessage.class))
|
assertThat((ConfirmSelectionMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
.isEqualTo(message);
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class MessageDeserializerTest {
|
|||||||
message.message = "error error";
|
message.message = "error error";
|
||||||
message.type = 0;
|
message.type = 0;
|
||||||
|
|
||||||
assertThat(mapper.readValue(jsonRepresentingMessage, ErrorMessage.class))
|
assertThat((ErrorMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
.isEqualTo(message);
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ public class MessageDeserializerTest {
|
|||||||
message.gameID = "6a39c3cf-26d8-409e-a309-45590f38ec4f";
|
message.gameID = "6a39c3cf-26d8-409e-a309-45590f38ec4f";
|
||||||
message.characterSelection = new CharacterProperties[] {racoon, quicksilver, hulk};
|
message.characterSelection = new CharacterProperties[] {racoon, quicksilver, hulk};
|
||||||
|
|
||||||
assertThat(mapper.readValue(jsonRepresentingMessage, GameAssignmentMessage.class))
|
assertThat((GameAssignmentMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
.isEqualTo(message);
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,4 +350,90 @@ public class MessageDeserializerTest {
|
|||||||
assertThat((GeneralAssignmentMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
assertThat((GeneralAssignmentMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
.isEqualTo(message);
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void goodbyeClientTest() throws JsonProcessingException {
|
||||||
|
var jsonRepresentingMessage = """
|
||||||
|
{
|
||||||
|
"messageType":"GOODBYE_ClIENT",
|
||||||
|
"message":"und schüss"
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var message = new GoodbyeClientMessage();
|
||||||
|
message.message = "und schüss";
|
||||||
|
|
||||||
|
assertThat((GoodbyeClientMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
|
.isEqualTo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void helloClientTest() throws JsonProcessingException {
|
||||||
|
var jsonRepresentingMessage = """
|
||||||
|
{
|
||||||
|
"messageType":"HELLO_CLIENT",
|
||||||
|
"runningGame":false
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var message = new HelloClientMessage();
|
||||||
|
message.runningGame = false;
|
||||||
|
|
||||||
|
|
||||||
|
assertThat((HelloClientMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
|
.isEqualTo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void helloServerTest() throws JsonProcessingException {
|
||||||
|
var jsonRepresentingMessage = """
|
||||||
|
{
|
||||||
|
"messageType": "HELLO_SERVER",
|
||||||
|
"name":"mynamehere",
|
||||||
|
"deviceID":"8f966f5a-9b62-456c-b4a3-50c90c75789c"
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var message = new HelloServerMessage();
|
||||||
|
message.name = "mynamehere";
|
||||||
|
message.deviceID = "8f966f5a-9b62-456c-b4a3-50c90c75789c";
|
||||||
|
|
||||||
|
assertThat((HelloServerMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
|
.isEqualTo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playerReadyTest() throws JsonProcessingException {
|
||||||
|
var jsonRepresentingMessage = """
|
||||||
|
{
|
||||||
|
"messageType":"PLAYER_READY",
|
||||||
|
"startGame":false,
|
||||||
|
"role":"PLAYER"
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var message = new PlayerReadyMessage();
|
||||||
|
message.startGame = false;
|
||||||
|
message.role = RoleEnum.PLAYER;
|
||||||
|
|
||||||
|
assertThat((PlayerReadyMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
|
.isEqualTo(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void reconnectTest() throws JsonProcessingException {
|
||||||
|
var jsonRepresentingMessage = """
|
||||||
|
{
|
||||||
|
"messageType":"RECONNECT",
|
||||||
|
"reconnect":false
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
var message = new ReconnectMessage();
|
||||||
|
message.reconnect = false;
|
||||||
|
|
||||||
|
assertThat((ReconnectMessage) mapper.readValue(jsonRepresentingMessage, BasicMessage.class))
|
||||||
|
.isEqualTo(message);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user