2021-05-11 04:14:18 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.json;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2021-05-30 16:07:05 +00:00
|
|
|
import net.jqwik.api.*;
|
|
|
|
import net.jqwik.api.lifecycle.BeforeContainer;
|
|
|
|
import net.jqwik.api.lifecycle.BeforeProperty;
|
2021-05-11 04:14:18 +00:00
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
2021-05-13 14:10:51 +00:00
|
|
|
import org.junit.jupiter.api.Disabled;
|
2021-05-11 04:14:18 +00:00
|
|
|
import org.junit.jupiter.api.Test;
|
2021-05-30 16:07:05 +00:00
|
|
|
|
2021-05-11 04:14:18 +00:00
|
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
|
2021-05-30 16:07:05 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
2021-05-11 04:14:18 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
2021-05-30 16:07:05 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Rock;
|
2021-05-11 04:14:18 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
2021-05-28 12:51:17 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.json.basic.EventMessage;
|
2021-05-30 16:07:05 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.*;
|
2021-05-11 04:14:18 +00:00
|
|
|
|
2021-05-30 16:07:05 +00:00
|
|
|
import java.util.*;
|
2021-05-11 04:14:18 +00:00
|
|
|
|
2021-05-11 02:25:35 +00:00
|
|
|
class JSONTest {
|
2021-05-11 04:14:18 +00:00
|
|
|
|
|
|
|
String messageStructureStart;
|
|
|
|
|
|
|
|
/** 0 is REQUESTS, 1 is EVENTS */
|
|
|
|
String[] messageStructureEnd;
|
|
|
|
|
|
|
|
/** Still need to add: messages, messageType */
|
2021-05-28 12:51:17 +00:00
|
|
|
EventMessage target;
|
2021-05-11 04:14:18 +00:00
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
void setUp() {
|
|
|
|
messageStructureStart = """
|
2021-05-30 16:07:05 +00:00
|
|
|
{
|
|
|
|
"messages":[
|
|
|
|
""";
|
|
|
|
messageStructureEnd = new String[]{
|
|
|
|
"""
|
2021-05-18 12:19:09 +00:00
|
|
|
],
|
|
|
|
"messageType": "REQUESTS",
|
|
|
|
"customContentType": "TestCustomContent",
|
|
|
|
"customContent": {
|
|
|
|
"customKey" = "customResult",
|
|
|
|
"customNumber" = 15,
|
|
|
|
"customProperty" = true
|
|
|
|
}
|
|
|
|
""",
|
2021-05-30 16:07:05 +00:00
|
|
|
"""
|
2021-05-18 12:19:09 +00:00
|
|
|
],
|
|
|
|
"messageType": "EVENTS",
|
|
|
|
"customContentType": "TestCustomContent",
|
|
|
|
"customContent": {
|
|
|
|
"customKey": "customResult",
|
|
|
|
"customNumber": 15,
|
|
|
|
"customProperty": true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""",
|
2021-05-11 04:14:18 +00:00
|
|
|
};
|
2021-05-28 12:51:17 +00:00
|
|
|
target = new EventMessage();
|
2021-05-11 04:14:18 +00:00
|
|
|
target.customContentType = "TestCustomContent";
|
|
|
|
target.customContent = new HashMap<String, Object>();
|
|
|
|
target.customContent.put("customKey", "customResult");
|
|
|
|
target.customContent.put("customNumber", 15);
|
|
|
|
target.customContent.put("customProperty", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
void tearDown() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void parseNotificationEvents() {
|
|
|
|
Event[] targetEvents = {
|
|
|
|
new EventBuilder(EventType.Ack).buildGameStateEvent(),
|
|
|
|
new EventBuilder(EventType.Nack).buildGameStateEvent(),
|
|
|
|
};
|
|
|
|
|
|
|
|
String eventRepresentation = """
|
2021-05-30 16:07:05 +00:00
|
|
|
{"eventType": "Ack"},
|
|
|
|
{"eventType": "Nack"}
|
|
|
|
""";
|
2021-05-11 04:14:18 +00:00
|
|
|
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
|
|
|
|
|
|
|
|
target.messageType = MessageType.EVENTS;
|
|
|
|
target.messages = targetEvents;
|
|
|
|
|
|
|
|
assertThat(JSON.parse(completeMessageStructure)).isEqualTo(target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-05-17 18:11:21 +00:00
|
|
|
void parseMoreComplicatedEvents() {
|
2021-05-11 04:14:18 +00:00
|
|
|
String eventRepresentation = """
|
2021-05-30 16:07:05 +00:00
|
|
|
{
|
|
|
|
"eventType": "GamestateEvent",
|
|
|
|
"activeCharacter": {"entityID": "P2", "ID": 4},
|
|
|
|
"turnOrder": [
|
|
|
|
{"entityID": "P2", "ID": 4},
|
|
|
|
{"entityID": "P2", "ID": 2},
|
|
|
|
{"entityID": "P1", "ID": 3},
|
|
|
|
{"entityID": "NPC", "ID": 1},
|
|
|
|
{"entityID": "InfinityStones", "ID": 5},
|
|
|
|
{"entityID": "Rocks", "ID": 0}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
""";
|
2021-05-11 04:14:18 +00:00
|
|
|
String completeMessageStructure = messageStructureStart + eventRepresentation + messageStructureEnd[1];
|
|
|
|
|
|
|
|
System.out.println(JSON.parse(completeMessageStructure));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-05-13 14:10:51 +00:00
|
|
|
@Disabled
|
2021-05-11 04:14:18 +00:00
|
|
|
void simpleInDevTest() throws JsonProcessingException {
|
|
|
|
String simpleEntity = """
|
2021-05-30 16:07:05 +00:00
|
|
|
{
|
|
|
|
"entityID": "P2",
|
|
|
|
"ID": 4
|
|
|
|
}
|
|
|
|
""";
|
2021-05-11 04:14:18 +00:00
|
|
|
System.out.println(new ObjectMapper().readValue(simpleEntity, EntityID.class));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void stringify() {
|
|
|
|
}
|
2021-05-11 02:25:35 +00:00
|
|
|
}
|