feat: created BasicAnswer, and cleaned up some code

This commit is contained in:
Yannik Bretschneider 2021-05-18 14:19:09 +02:00
parent 2d33f150a8
commit 37e84b6e15
3 changed files with 55 additions and 46 deletions

View File

@ -0,0 +1,10 @@
package uulm.teamname.marvelous.gamelibrary.json.basic;
import uulm.teamname.marvelous.gamelibrary.json.MessageType;
/** Basic answer to a message. It contains */
public class BasicAnswer {
String userID;
MessageType messageType;
boolean optionals;
}

View File

@ -1,6 +1,5 @@
package uulm.teamname.marvelous.gamelibrary.json.ingame; package uulm.teamname.marvelous.gamelibrary.json.ingame;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.json.MessageType; import uulm.teamname.marvelous.gamelibrary.json.MessageType;

View File

@ -30,31 +30,31 @@ class JSONTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
messageStructureStart = """ messageStructureStart = """
{ {
"messages":[ "messages":[
"""; """;
messageStructureEnd = new String[] { messageStructureEnd = new String[] {
""" """
], ],
"messageType": "REQUESTS", "messageType": "REQUESTS",
"customContentType": "TestCustomContent", "customContentType": "TestCustomContent",
"customContent": { "customContent": {
"customKey" = "customResult", "customKey" = "customResult",
"customNumber" = 15, "customNumber" = 15,
"customProperty" = true "customProperty" = true
} }
""", """,
""" """
], ],
"messageType": "EVENTS", "messageType": "EVENTS",
"customContentType": "TestCustomContent", "customContentType": "TestCustomContent",
"customContent": { "customContent": {
"customKey": "customResult", "customKey": "customResult",
"customNumber": 15, "customNumber": 15,
"customProperty": true "customProperty": true
} }
} }
""", """,
}; };
target = new MessageStructure(); target = new MessageStructure();
target.customContentType = "TestCustomContent"; target.customContentType = "TestCustomContent";
@ -76,9 +76,9 @@ class JSONTest {
}; };
String eventRepresentation = """ String eventRepresentation = """
{"eventType": "Ack"}, {"eventType": "Ack"},
{"eventType": "Nack"} {"eventType": "Nack"}
"""; """;
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1]; String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
target.messageType = MessageType.EVENTS; target.messageType = MessageType.EVENTS;
@ -91,7 +91,7 @@ class JSONTest {
@Test @Test
void parseMoreComplicatedEvents() { void parseMoreComplicatedEvents() {
String eventRepresentation = """ String eventRepresentation = """
{ {
"eventType": "GamestateEvent", "eventType": "GamestateEvent",
"activeCharacter": {"entityID": "P2", "ID": 4}, "activeCharacter": {"entityID": "P2", "ID": 4},
"turnOrder": [ "turnOrder": [
@ -102,8 +102,8 @@ class JSONTest {
{"entityID": "InfinityStones", "ID": 5}, {"entityID": "InfinityStones", "ID": 5},
{"entityID": "Rocks", "ID": 0} {"entityID": "Rocks", "ID": 0}
] ]
} }
"""; """;
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1]; String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
System.out.println(JSON.parse(completeMessageStructure)); System.out.println(JSON.parse(completeMessageStructure));
@ -113,11 +113,11 @@ class JSONTest {
@Disabled @Disabled
void simpleInDevTest() throws JsonProcessingException { void simpleInDevTest() throws JsonProcessingException {
String simpleEntity = """ String simpleEntity = """
{ {
"entityID": "P2", "entityID": "P2",
"ID": 4 "ID": 4
} }
"""; """;
System.out.println(new ObjectMapper().readValue(simpleEntity, EntityID.class)); System.out.println(new ObjectMapper().readValue(simpleEntity, EntityID.class));
} }