Skip to content

Commit

Permalink
[ECO-5193][TM*] Added unit tests to MessageTest
Browse files Browse the repository at this point in the history
1. Added serializer test for fields refSerial, refType and Operation
1. Added deserializer test for fields refSerial, refType and Operation
  • Loading branch information
sacOO7 committed Jan 17, 2025
1 parent be9a613 commit 96ee57d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions lib/src/test/java/io/ably/lib/types/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,63 @@ public void deserialize_message_with_serial() throws Exception {
assertEquals("01826232498871-001@abcdefghij:001", message.serial);
}

@Test
public void serialize_message_with_operation() {
// Given
Message message = new Message("test-name", "test-data");
message.clientId = "test-client-id";
message.connectionKey = "test-key";
message.refSerial = "test-ref-serial";
message.refType = "test-ref-type";
Message.Operation operation = new Message.Operation();
operation.clientId = "operation-client-id";
operation.description = "operation-description";
message.operation = operation;

// When
JsonElement serializedElement = serializer.serialize(message, null, null);

// Then
JsonObject serializedObject = serializedElement.getAsJsonObject();
assertEquals("test-client-id", serializedObject.get("clientId").getAsString());
assertEquals("test-key", serializedObject.get("connectionKey").getAsString());
assertEquals("test-data", serializedObject.get("data").getAsString());
assertEquals("test-name", serializedObject.get("name").getAsString());
assertEquals("test-ref-serial", serializedObject.get("refSerial").getAsString());
assertEquals("test-ref-type", serializedObject.get("refType").getAsString());
JsonObject operationObject = serializedObject.getAsJsonObject("operation");
assertEquals("operation-client-id", operationObject.get("clientId").getAsString());
assertEquals("operation-description", operationObject.get("description").getAsString());
}

@Test
public void deserialize_message_with_operation() throws Exception {
// Given
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("clientId", "test-client-id");
jsonObject.addProperty("data", "test-data");
jsonObject.addProperty("name", "test-name");
jsonObject.addProperty("refSerial", "test-ref-serial");
jsonObject.addProperty("refType", "test-ref-type");
jsonObject.addProperty("connectionKey", "test-key");
JsonObject operationObject = new JsonObject();
operationObject.addProperty("clientId", "operation-client-id");
operationObject.addProperty("description", "operation-description");
jsonObject.add("operation", operationObject);

// When
Message message = Message.fromEncoded(jsonObject, new ChannelOptions());

// Then
assertEquals("test-client-id", message.clientId);
assertEquals("test-data", message.data);
assertEquals("test-name", message.name);
assertEquals("test-ref-serial", message.refSerial);
assertEquals("test-ref-type", message.refType);
assertEquals("test-key", message.connectionKey);
assertEquals("operation-client-id", message.operation.clientId);
assertEquals("operation-description", message.operation.description);
}

@Test
public void deserialize_message_with_unknown_action() throws Exception {
Expand Down

0 comments on commit 96ee57d

Please sign in to comment.