mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
networking/refactor: Rename messages to requests, use builder class
This commit is contained in:
1 parent
10a3eebc55
commit
0c1ad832ea
16 files changed
+429
-342
No files matched your search
@@ -1,52 +0,0 @@
|
||||
package net.william278.huskhomes.messenger;
|
||||
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageTests {
|
||||
|
||||
@Test
|
||||
public void testMessageSerializationWithEmptyPayload() {
|
||||
final Message message = new Message(
|
||||
Message.MessageType.TELEPORT_REQUEST,
|
||||
"TestSender",
|
||||
"TestTarget",
|
||||
MessagePayload.empty(),
|
||||
Message.RelayType.MESSAGE,
|
||||
"TestClusterId");
|
||||
Assertions.assertNotNull(message.toJson());
|
||||
|
||||
final Message readMessage = Message.fromJson(message.toJson());
|
||||
Assertions.assertEquals(message.uuid, readMessage.uuid);
|
||||
Assertions.assertEquals(message.sender, readMessage.sender);
|
||||
Assertions.assertEquals(message.targetPlayer, readMessage.targetPlayer);
|
||||
Assertions.assertEquals(message.type, readMessage.type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSerializationWithPositionPayload() {
|
||||
final Message message = new Message(
|
||||
Message.MessageType.POSITION_REQUEST,
|
||||
"TestSender",
|
||||
"TestTarget",
|
||||
MessagePayload.withPosition(new Position(63.25, 127.43, -32, 180f, -94.3f,
|
||||
new World("TestWorld", UUID.randomUUID()), new Server("TestServer"))),
|
||||
Message.RelayType.REPLY,
|
||||
"TestClusterId");
|
||||
Assertions.assertNotNull(message.toJson());
|
||||
|
||||
final Message readMessage = Message.fromJson(message.toJson());
|
||||
Assertions.assertEquals(message.uuid, readMessage.uuid);
|
||||
Assertions.assertNotNull(readMessage.payload.position);
|
||||
|
||||
assert message.payload.position != null;
|
||||
Assertions.assertEquals(message.payload.position.x, readMessage.payload.position.x);
|
||||
Assertions.assertEquals(message.payload.position.y, readMessage.payload.position.y);
|
||||
Assertions.assertEquals(message.payload.position.z, readMessage.payload.position.z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.william278.huskhomes.network;
|
||||
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RequestTests {
|
||||
|
||||
private final static Request DUMMY_NO_PAYLOAD = Request.builder()
|
||||
.withType(Request.MessageType.TELEPORT_REQUEST)
|
||||
.withTargetPlayer("TestTarget")
|
||||
.withPayload(Payload.empty())
|
||||
.build();
|
||||
|
||||
private final static Request DUMMY_PAYLOAD = Request.builder()
|
||||
.withType(Request.MessageType.TELEPORT_REQUEST)
|
||||
.withTargetPlayer("TestTarget")
|
||||
.withPayload(Payload.withPosition(
|
||||
new Position(63.25, 127.43, -32, 180f, -94.3f,
|
||||
new World("TestWorld", UUID.randomUUID()), new Server("TestServer"))))
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void testMessageSerializationWithEmptyPayload() {
|
||||
Assertions.assertNotNull(DUMMY_NO_PAYLOAD.toJson());
|
||||
|
||||
final Request readRequest = Request.fromJson(DUMMY_NO_PAYLOAD.toJson());
|
||||
Assertions.assertEquals(DUMMY_NO_PAYLOAD.getUuid(), readRequest.getUuid());
|
||||
Assertions.assertEquals(DUMMY_NO_PAYLOAD.getTargetPlayer(), readRequest.getTargetPlayer());
|
||||
Assertions.assertEquals(DUMMY_NO_PAYLOAD.getType(), readRequest.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSerializationWithPositionPayload() {
|
||||
Assertions.assertNotNull(DUMMY_PAYLOAD.toJson());
|
||||
|
||||
final Request readRequest = Request.fromJson(DUMMY_PAYLOAD.toJson());
|
||||
Assertions.assertEquals(DUMMY_PAYLOAD.getUuid(), readRequest.getUuid());
|
||||
Assertions.assertNotNull(readRequest.getPayload().position);
|
||||
|
||||
assert readRequest.getPayload().position != null && DUMMY_PAYLOAD.getPayload().position != null;
|
||||
Assertions.assertEquals(DUMMY_PAYLOAD.getPayload().position.x, readRequest.getPayload().position.x);
|
||||
Assertions.assertEquals(DUMMY_PAYLOAD.getPayload().position.y, readRequest.getPayload().position.y);
|
||||
Assertions.assertEquals(DUMMY_PAYLOAD.getPayload().position.z, readRequest.getPayload().position.z);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user