diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonMessage.java b/telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonRecord.java similarity index 66% rename from telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonMessage.java rename to telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonRecord.java index e522862e..be63e987 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonMessage.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/message/JsonRecord.java @@ -14,7 +14,7 @@ /** *

Description

- * The base class for all messages which are automatically encoded with the JsonMessageCodec. + * The base class for all records which are automatically encoded with the JsonMessageCodec. *

* All subclasses have to be valid json classes. This means that they could be encoded by * {@link JsonCodec} which is backed by {@link io.vertx.core.json.jackson.JacksonCodec JacksonCodec}. @@ -25,14 +25,14 @@ * public record TimeMessage( * @JsonProperty long receiveTime, * @JsonProperty long sendTime - * ) implements JsonMessage { + * ) implements JsonRecord { * } * } * * - * @author Jan von Pichowski (@jvpichowski), Cedric Boes (@cb0s), Ludwig Richter (@fussel178) + * @author Jan von Pichowski (@jvpichowski), Cedric Boes (@cb0s), Ludwig Richter (@fussel178), Pablo Klaschka (@pklaschka) */ -public interface JsonMessage { +public interface JsonRecord { /////////////////////////////////////////////////////////////////////////// // asynchronous decoding section @@ -41,21 +41,21 @@ public interface JsonMessage { /** * Asynchronous version of {@link #from(Buffer, Class)}. * - * @param type the class of the target {@link JsonMessage} + * @param type the class of the target {@link JsonRecord} * @param json the buffer whose contents contain the necessary information to construct - * the specified {@link JsonMessage} + * the specified {@link JsonRecord} * @param handler gets called when the conversion was successful * @param exceptionHandler gets called when a {@link DecodeException} occurred during conversion - * @param the type of the target {@link JsonMessage} + * @param the type of the target {@link JsonRecord} * @return {@code true} when the conversion was successful */ - static boolean on(Class type, Buffer json, Handler handler, - Handler exceptionHandler) { + static boolean on(Class type, Buffer json, Handler handler, + Handler exceptionHandler) { try { handler.handle(from(json, type)); return true; } catch (DecodeException | IllegalArgumentException e) { - logger.warn("Cannot convert buffer to JsonMessage {}:", type.getName(), e); + logger.warn("Cannot convert buffer to JSON record {}:", type.getName(), e); exceptionHandler.handle(e); return false; } @@ -64,22 +64,22 @@ static boolean on(Class type, Buffer json, Handler /** * Asynchronous version of {@link #from(String, Class)}. * - * @param type the class of the target {@link JsonMessage} + * @param type the class of the target {@link JsonRecord} * @param json the JSON {@link String} that contains the necessary information to construct - * the specified {@link JsonMessage} + * the specified {@link JsonRecord} * @param handler gets called when the conversion was successful * @param exceptionHandler gets called when a {@link DecodeException} or an {@link IllegalArgumentException} * occurred during conversion - * @param the type of the target {@link JsonMessage} + * @param the type of the target {@link JsonRecord} * @return {@code true} when the conversion was successful */ - static boolean on(Class type, String json, Handler handler, - Handler exceptionHandler) { + static boolean on(Class type, String json, Handler handler, + Handler exceptionHandler) { try { handler.handle(from(json, type)); return true; } catch (DecodeException | IllegalArgumentException e) { - logger.warn("Cannot convert JSON string to JsonMessage {}:", type.getName(), e); + logger.warn("Cannot convert JSON string to JSON record {}:", type.getName(), e); exceptionHandler.handle(e); return false; } @@ -88,22 +88,22 @@ static boolean on(Class type, String json, Handler /** * Asynchronous version of {@link #from(Object, Class)}. * - * @param type the class of the target {@link JsonMessage} + * @param type the class of the target {@link JsonRecord} * @param json the plain {@link Object} that contains the necessary information to construct - * the specified {@link JsonMessage} + * the specified {@link JsonRecord} * @param handler gets called when the conversion was successful * @param exceptionHandler gets called when a {@link DecodeException} or an {@link IllegalArgumentException} * occurred during conversion - * @param the type of the target {@link JsonMessage} + * @param the type of the target {@link JsonRecord} * @return {@code true} when the conversion was successful */ - static boolean on(Class type, Object json, Handler handler, - Handler exceptionHandler) { + static boolean on(Class type, Object json, Handler handler, + Handler exceptionHandler) { try { handler.handle(from(json, type)); return true; } catch (DecodeException | IllegalArgumentException e) { - logger.warn("Cannot convert Object to JsonMessage {}:", type.getName(), e); + logger.warn("Cannot convert Object to JSON record {}:", type.getName(), e); exceptionHandler.handle(e); return false; } @@ -112,22 +112,22 @@ static boolean on(Class type, Object json, Handler /** * Asynchronous version of {@link #from(Message, Class)}. * - * @param type the class of the target {@link JsonMessage} + * @param type the class of the target {@link JsonRecord} * @param message the message whose body contains the necessary information to construct - * the specified {@link JsonMessage} + * the specified {@link JsonRecord} * @param handler gets called when the conversion was successful * @param exceptionHandler gets called when a {@link DecodeException} or an {@link IllegalArgumentException} * occurred during conversion - * @param the type of the target {@link JsonMessage} + * @param the type of the target {@link JsonRecord} * @return {@code true} when the conversion was successful */ - static boolean on(Class type, Message message, Handler handler, - Handler exceptionHandler) { + static boolean on(Class type, Message message, Handler handler, + Handler exceptionHandler) { try { handler.handle(from(message, type)); return true; } catch (DecodeException | IllegalArgumentException e) { - logger.warn("Cannot convert Vertx Message to JsonMessage {}:", type.getName(), e); + logger.warn("Cannot convert Vertx Message to JSON record {}:", type.getName(), e); exceptionHandler.handle(e); return false; } @@ -136,7 +136,7 @@ static boolean on(Class type, Message message, Han /** * Like {@link #on(Class, Buffer, Handler, Handler)} but without an exception handler. */ - static boolean on(Class type, Buffer json, Handler handler) { + static boolean on(Class type, Buffer json, Handler handler) { return on(type, json, handler, e -> { }); } @@ -144,7 +144,7 @@ static boolean on(Class type, Buffer json, Handler /** * Like {@link #on(Class, String, Handler, Handler)} but without an exception handler. */ - static boolean on(Class type, String json, Handler handler) { + static boolean on(Class type, String json, Handler handler) { return on(type, json, handler, e -> { }); } @@ -152,7 +152,7 @@ static boolean on(Class type, String json, Handler /** * Like {@link #on(Class, Object, Handler, Handler)} but without an exception handler. */ - static boolean on(Class type, Object json, Handler handler) { + static boolean on(Class type, Object json, Handler handler) { return on(type, json, handler, e -> { }); } @@ -160,7 +160,7 @@ static boolean on(Class type, Object json, Handler /** * Like {@link #on(Class, Message, Handler, Handler)} but without an exception handler. */ - static boolean on(Class type, Message message, Handler handler) { + static boolean on(Class type, Message message, Handler handler) { return on(type, message, handler, e -> { }); } @@ -172,7 +172,7 @@ static boolean on(Class type, Message message, Han * * @return a future that represents the conversion state */ - static Future on(Class type, Buffer json) { + static Future on(Class type, Buffer json) { return Future.future(promise -> on(type, json, promise::complete, promise::fail)); } @@ -183,7 +183,7 @@ static Future on(Class type, Buffer json) { * * @return a future that represents the conversion state */ - static Future on(Class type, String json) { + static Future on(Class type, String json) { return Future.future(promise -> on(type, json, promise::complete, promise::fail)); } @@ -194,7 +194,7 @@ static Future on(Class type, String json) { * * @return a future that represents the conversion state */ - static Future on(Class type, Object json) { + static Future on(Class type, Object json) { return Future.future(promise -> on(type, json, promise::complete, promise::fail)); } @@ -204,7 +204,7 @@ static Future on(Class type, Object json) { * * @return a future that represents the conversion state */ - static Future on(Class type, Message message) { + static Future on(Class type, Message message) { return Future.future(promise -> on(type, message, promise::complete, promise::fail)); } @@ -213,62 +213,62 @@ static Future on(Class type, Message message) { /////////////////////////////////////////////////////////////////////////// /** - * Constructs a {@link JsonMessage} from a buffer which contains an encoded JSON string. + * Constructs a {@link JsonRecord} from a buffer which contains an encoded JSON string. * * @param json the buffer that contents contain the necessary information to construct - * the specified {@link JsonMessage} - * @param type the class of the target {@link JsonMessage} - * @param the type of the target {@link JsonMessage} + * the specified {@link JsonRecord} + * @param type the class of the target {@link JsonRecord} + * @param the type of the target {@link JsonRecord} * @return the decoded message * @throws DecodeException if the buffer contents does not contain the necessary information to successfully - * construct the specified {@link JsonMessage} + * construct the specified {@link JsonRecord} */ - static T from(Buffer json, Class type) throws DecodeException { + static T from(Buffer json, Class type) throws DecodeException { return Json.CODEC.fromBuffer(json, type); } /** - * Constructs a {@link JsonMessage} from a JSON {@link String}. + * Constructs a {@link JsonRecord} from a JSON {@link String}. * * @param json the JSON {@link String} that contains the necessary information to construct - * the specified {@link JsonMessage} - * @param type the class of the target {@link JsonMessage} - * @param the type of the target {@link JsonMessage} + * the specified {@link JsonRecord} + * @param type the class of the target {@link JsonRecord} + * @param the type of the target {@link JsonRecord} * @return the decoded message * @throws DecodeException if the JSON string does not contain the necessary information to successfully - * construct the specified {@link JsonMessage} + * construct the specified {@link JsonRecord} */ - static T from(String json, Class type) throws DecodeException { + static T from(String json, Class type) throws DecodeException { return Json.CODEC.fromString(json, type); } /** - * Constructs a {@link JsonMessage} from a plain {@link Object}. + * Constructs a {@link JsonRecord} from a plain {@link Object}. * * @param json the plain {@link Object} that contains the necessary information to construct - * the specified {@link JsonMessage} - * @param type the class of the target {@link JsonMessage} - * @param the type of the target {@link JsonMessage} + * the specified {@link JsonRecord} + * @param type the class of the target {@link JsonRecord} + * @param the type of the target {@link JsonRecord} * @return the decoded message * @throws DecodeException if the plain object does not contain the necessary information to successfully - * construct the specified {@link JsonMessage} + * construct the specified {@link JsonRecord} */ - static T from(Object json, Class type) throws DecodeException { + static T from(Object json, Class type) throws DecodeException { return Json.CODEC.fromValue(json, type); } /** - * Constructs a {@link JsonMessage} from a Vert.x EventBus {@link Message} body. + * Constructs a {@link JsonRecord} from a Vert.x EventBus {@link Message} body. * * @param message the message which body contains the necessary information to construct - * the specified {@link JsonMessage} - * @param type the class of the target {@link JsonMessage} - * @param the type of the target {@link JsonMessage} + * the specified {@link JsonRecord} + * @param type the class of the target {@link JsonRecord} + * @param the type of the target {@link JsonRecord} * @return the decoded message * @throws DecodeException if the raw message body does not contain the necessary information to successfully - * construct the specified {@link JsonMessage} + * construct the specified {@link JsonRecord} */ - static T from(Message message, Class type) throws DecodeException { + static T from(Message message, Class type) throws DecodeException { return from(message.body(), type); } @@ -286,22 +286,22 @@ default JsonObject json() throws IllegalArgumentException { } /** - * Constructs a {@link JsonObject} from the {@link JsonMessage}. + * Constructs a {@link JsonObject} from the {@link JsonRecord}. * * @return the constructed JSON object * @throws IllegalArgumentException if the JSON object cannot represent the type of - * any {@link JsonMessage} property + * any {@link JsonRecord} property */ default JsonObject toJsonObject() throws IllegalArgumentException { return JsonObject.mapFrom(this); } /** - * Constructs a {@link String} containing the properties of the {@link JsonMessage} as JSON values. + * Constructs a {@link String} containing the properties of the {@link JsonRecord} as JSON values. * * @param pretty if {@code true} the JSON output is properly formatted - * @return a JSON string representing the {@link JsonMessage} - * @throws EncodeException if the {@link JsonMessage} containing properties that cannot be represented + * @return a JSON string representing the {@link JsonRecord} + * @throws EncodeException if the {@link JsonRecord} containing properties that cannot be represented * by JSON values * @see io.vertx.core.json.jackson.JacksonCodec#toString(Object, boolean) */ @@ -317,11 +317,11 @@ default String toJsonString() throws EncodeException { } /** - * Constructs a {@link Buffer} containing the properties of the {@link JsonMessage} as JSON values + * Constructs a {@link Buffer} containing the properties of the {@link JsonRecord} as JSON values * * @param pretty if {@code true} the JSON output is properly formatted - * @return a buffer representing the {@link JsonMessage} - * @throws EncodeException if the {@link JsonMessage} containing properties that cannot be represented + * @return a buffer representing the {@link JsonRecord} + * @throws EncodeException if the {@link JsonRecord} containing properties that cannot be represented * by JSON values * @see io.vertx.core.json.jackson.JacksonCodec#toBuffer(Object, boolean) */ @@ -349,5 +349,5 @@ default String className() { return getClass().getName(); } - Logger logger = LoggerFactory.getLogger(JsonMessage.class); + Logger logger = LoggerFactory.getLogger(JsonRecord.class); } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/message/package-info.java b/telestion-api/src/main/java/de/wuespace/telestion/api/message/package-info.java index da34a483..4cf13962 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/message/package-info.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/message/package-info.java @@ -8,7 +8,7 @@ * Vert.x. JSON (Jackson Codec) is used to encode and decode messages for the event bus. *

* {@link de.wuespace.telestion.api.message.HeaderInformation} add support for message headers. They can be - * used to include data unrelated to the data itself of a message. + * used to include metadata unrelated to the payload of a message. *

* It is heavily recommended to use Telestion traits like {@link de.wuespace.telestion.api.verticle.trait.WithEventBus}, it contains different * helper methods for message serialization. diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/TelestionConfiguration.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/TelestionConfiguration.java index 882f1a2b..8445f90e 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/TelestionConfiguration.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/TelestionConfiguration.java @@ -1,13 +1,13 @@ package de.wuespace.telestion.api.verticle; -import de.wuespace.telestion.api.message.JsonMessage; +import de.wuespace.telestion.api.message.JsonRecord; /** * The base class for all Telestion Verticle configurations. - * It extends {@link JsonMessage} so all configurations are also valid json classes. + * It extends {@link JsonRecord} so all configurations are also valid json classes. * * @author Cedric Bös (@cb0s), Pablo Klaschka (@pklaschka), Jan von Pichowski (@jvpichowski), * Ludwig Richter (@fussel178) */ -public interface TelestionConfiguration extends JsonMessage { +public interface TelestionConfiguration extends JsonRecord { } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/DecodedMessage.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/DecodedMessage.java index de864517..29a23124 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/DecodedMessage.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/DecodedMessage.java @@ -1,59 +1,59 @@ package de.wuespace.telestion.api.verticle.trait; import com.fasterxml.jackson.annotation.JsonProperty; -import de.wuespace.telestion.api.message.JsonMessage; +import de.wuespace.telestion.api.message.JsonRecord; import io.vertx.core.Future; import io.vertx.core.eventbus.Message; import io.vertx.core.json.JsonObject; /** - * A wrapper for a {@link Message Vert.x message} and its body as {@link JsonMessage}. + * A wrapper for a {@link Message Vert.x message} and its body as {@link JsonRecord}. * * @param message the {@link Message Vert.x message} * @param body the decoded body of the {@link Message Vert.x message} - * @param the type of {@link JsonMessage} to map to + * @param the type of {@link JsonRecord} to map to * @param the type of the body of the {@link Message Vert.x message} - * @see JsonMessage#on(Class, Message) + * @see JsonRecord#on(Class, Message) * * @author Ludwig Richter (@fussel178) */ -public record DecodedMessage( +public record DecodedMessage( @JsonProperty V body, @JsonProperty Message message -) implements JsonMessage { +) implements JsonRecord { /** - * Returns a {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonMessage}. - * Fails if the {@code messageFuture}'s body cannot be mapped to the {@link JsonMessage} type + * Returns a {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonRecord}. + * Fails if the {@code messageFuture}'s body cannot be mapped to the {@link JsonRecord} type * or the {@code messageFuture} fails. * - * @param clazz the class type of the {@link JsonMessage} to map to + * @param clazz the class type of the {@link JsonRecord} to map to * @param messageFuture the future that returns the received message - * @param the type of {@link JsonMessage} to map to + * @param the type of {@link JsonRecord} to map to * @param the type of the body of the {@link Message Vert.x message} - * @return a new {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonMessage} - * @see JsonMessage#on(Class, Message) + * @return a new {@link Future} which succeeds with the {@code messageFuture}'s body as {@link JsonRecord} + * @see JsonRecord#on(Class, Message) */ - public static Future> compose( + public static Future> compose( Class clazz, Future> messageFuture) { return messageFuture.compose(message -> on(clazz, message)); } /** - * Return a {@link Future} which succeeds with the {@link Message Vert.x message}'s body as {@link JsonMessage}. - * Fails if the {@link Message Vert.x message}'s body cannot be mapped to the {@link JsonMessage} type. + * Returns a {@link Future} which succeeds with the {@link Message Vert.x message}'s body as {@link JsonRecord}. + * Fails if the {@link Message Vert.x message}'s body cannot be mapped to the {@link JsonRecord} type. * - * @param clazz the class type of the {@link JsonMessage} to map to + * @param clazz the class type of the {@link JsonRecord} to map to * @param message the {@link Message Vert.x message} - * @param the type of {@link JsonMessage} to map to + * @param the type of {@link JsonRecord} to map to * @param the type of the body of the {@link Message Vert.x message} * @return a new {@link Future} which returns a {@link DecodedMessage} with the message's contents - * @see JsonMessage#on(Class, Message) + * @see JsonRecord#on(Class, Message) */ - public static Future> on( + public static Future> on( Class clazz, Message message) { - return JsonMessage.on(clazz, message).map(decoded -> new DecodedMessage<>(decoded, message)); + return JsonRecord.on(clazz, message).map(decoded -> new DecodedMessage<>(decoded, message)); } } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/ExtendedMessageHandler.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/ExtendedMessageHandler.java index fcf5053c..c89817b8 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/ExtendedMessageHandler.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/ExtendedMessageHandler.java @@ -1,6 +1,6 @@ package de.wuespace.telestion.api.verticle.trait; -import de.wuespace.telestion.api.message.JsonMessage; +import de.wuespace.telestion.api.message.JsonRecord; import io.vertx.core.eventbus.Message; /** @@ -11,6 +11,6 @@ * @see WithEventBus#register(String, ExtendedMessageHandler, Class) */ @FunctionalInterface -public interface ExtendedMessageHandler { +public interface ExtendedMessageHandler { void handle(V body, Message message); } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/MessageHandler.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/MessageHandler.java index 68911d3c..e72c56fc 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/MessageHandler.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/MessageHandler.java @@ -1,6 +1,6 @@ package de.wuespace.telestion.api.verticle.trait; -import de.wuespace.telestion.api.message.JsonMessage; +import de.wuespace.telestion.api.message.JsonRecord; /** * An event handler which accepts the decoded body of the message @@ -10,6 +10,6 @@ * @see WithEventBus#register(String, MessageHandler, Class) */ @FunctionalInterface -public interface MessageHandler { +public interface MessageHandler { void handle(T body); } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/WithEventBus.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/WithEventBus.java index a6fea009..028af1c4 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/WithEventBus.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/WithEventBus.java @@ -1,7 +1,7 @@ package de.wuespace.telestion.api.verticle.trait; import de.wuespace.telestion.api.message.HeaderInformation; -import de.wuespace.telestion.api.message.JsonMessage; +import de.wuespace.telestion.api.message.JsonRecord; import de.wuespace.telestion.api.message.MultiMapUtils; import io.vertx.core.Future; import io.vertx.core.Handler; @@ -13,7 +13,7 @@ /** * Allows {@link Verticle} instances to get simplified access to the Vert.x event bus. - * These traits support automatic conversion of different message types like {@link JsonMessage} + * These traits support automatic conversion of different message types like {@link JsonRecord} * and automatic attachment of {@link MultiMap} or {@link HeaderInformation} to sent messages on the event bus. * *

Usage

@@ -91,14 +91,14 @@ default void publish(String address, Object message, HeaderInformation... header /** * @see io.vertx.core.eventbus.EventBus#publish(String, Object) */ - default void publish(String address, JsonMessage message) { + default void publish(String address, JsonRecord message) { publish(address, message.toJsonObject()); } /** * @see io.vertx.core.eventbus.EventBus#publish(String, Object, DeliveryOptions) */ - default void publish(String address, JsonMessage message, DeliveryOptions options) { + default void publish(String address, JsonRecord message, DeliveryOptions options) { publish(address, message.toJsonObject(), options); } @@ -106,7 +106,7 @@ default void publish(String address, JsonMessage message, DeliveryOptions option * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#publish(String, Object, DeliveryOptions) */ - default void publish(String address, JsonMessage message, DeliveryOptions options, MultiMap... headers) { + default void publish(String address, JsonRecord message, DeliveryOptions options, MultiMap... headers) { publish(address, message.toJsonObject(), options, headers); } @@ -114,7 +114,7 @@ default void publish(String address, JsonMessage message, DeliveryOptions option * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#publish(String, Object, DeliveryOptions) */ - default void publish(String address, JsonMessage message, DeliveryOptions options, HeaderInformation... headers) { + default void publish(String address, JsonRecord message, DeliveryOptions options, HeaderInformation... headers) { publish(address, message.toJsonObject(), options, headers); } @@ -122,7 +122,7 @@ default void publish(String address, JsonMessage message, DeliveryOptions option * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#publish(String, Object) */ - default void publish(String address, JsonMessage message, MultiMap... headers) { + default void publish(String address, JsonRecord message, MultiMap... headers) { publish(address, message.toJsonObject(), headers); } @@ -130,7 +130,7 @@ default void publish(String address, JsonMessage message, MultiMap... headers) { * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#publish(String, Object) */ - default void publish(String address, JsonMessage message, HeaderInformation... headers) { + default void publish(String address, JsonRecord message, HeaderInformation... headers) { publish(address, message.toJsonObject(), headers); } @@ -189,14 +189,14 @@ default void send(String address, Object message, HeaderInformation... headers) /** * @see io.vertx.core.eventbus.EventBus#send(String, Object) */ - default void send(String address, JsonMessage message) { + default void send(String address, JsonRecord message) { send(address, message.toJsonObject()); } /** * @see io.vertx.core.eventbus.EventBus#send(String, Object, DeliveryOptions) */ - default void send(String address, JsonMessage message, DeliveryOptions options) { + default void send(String address, JsonRecord message, DeliveryOptions options) { send(address, message.toJsonObject(), options); } @@ -204,7 +204,7 @@ default void send(String address, JsonMessage message, DeliveryOptions options) * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#send(String, Object, DeliveryOptions) */ - default void send(String address, JsonMessage message, DeliveryOptions options, MultiMap... headers) { + default void send(String address, JsonRecord message, DeliveryOptions options, MultiMap... headers) { send(address, message.toJsonObject(), options, headers); } @@ -212,7 +212,7 @@ default void send(String address, JsonMessage message, DeliveryOptions options, * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#send(String, Object, DeliveryOptions) */ - default void send(String address, JsonMessage message, DeliveryOptions options, HeaderInformation... headers) { + default void send(String address, JsonRecord message, DeliveryOptions options, HeaderInformation... headers) { send(address, message.toJsonObject(), options, headers); } @@ -220,7 +220,7 @@ default void send(String address, JsonMessage message, DeliveryOptions options, * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#send(String, Object) */ - default void send(String address, JsonMessage message, MultiMap... headers) { + default void send(String address, JsonRecord message, MultiMap... headers) { send(address, message.toJsonObject(), headers); } @@ -228,7 +228,7 @@ default void send(String address, JsonMessage message, MultiMap... headers) { * @param headers the headers that should be sent with the message * @see io.vertx.core.eventbus.EventBus#send(String, Object) */ - default void send(String address, JsonMessage message, HeaderInformation... headers) { + default void send(String address, JsonRecord message, HeaderInformation... headers) { send(address, message.toJsonObject(), headers); } @@ -295,14 +295,14 @@ default Future> request(String address, Object request, HeaderInf /** * @see io.vertx.core.eventbus.EventBus#request(String, Object) */ - default Future> request(String address, JsonMessage message) { + default Future> request(String address, JsonRecord message) { return request(address, message.toJsonObject()); } /** * @see io.vertx.core.eventbus.EventBus#request(String, Object, DeliveryOptions) */ - default Future> request(String address, JsonMessage message, DeliveryOptions options) { + default Future> request(String address, JsonRecord message, DeliveryOptions options) { return request(address, message.toJsonObject(), options); } @@ -312,7 +312,7 @@ default Future> request(String address, JsonMessage message, Deli */ default Future> request( String address, - JsonMessage message, + JsonRecord message, DeliveryOptions options, MultiMap... requestHeaders) { return request(address, message.toJsonObject(), options, requestHeaders); @@ -324,7 +324,7 @@ default Future> request( */ default Future> request( String address, - JsonMessage message, + JsonRecord message, DeliveryOptions options, HeaderInformation... requestHeaders) { return request(address, message.toJsonObject(), options, requestHeaders); @@ -334,7 +334,7 @@ default Future> request( * @param requestHeaders the headers that should be sent with the request message * @see io.vertx.core.eventbus.EventBus#request(String, Object) */ - default Future> request(String address, JsonMessage message, MultiMap... requestHeaders) { + default Future> request(String address, JsonRecord message, MultiMap... requestHeaders) { return request(address, message.toJsonObject(), requestHeaders); } @@ -342,7 +342,7 @@ default Future> request(String address, JsonMessage message, Mult * @param requestHeaders the headers that should be sent with the request message * @see io.vertx.core.eventbus.EventBus#request(String, Object) */ - default Future> request(String address, JsonMessage message, HeaderInformation... requestHeaders) { + default Future> request(String address, JsonRecord message, HeaderInformation... requestHeaders) { return request(address, message.toJsonObject(), requestHeaders); } @@ -350,7 +350,7 @@ default Future> request(String address, JsonMessage message, Head * @param responseType the type of the response to map to * @see io.vertx.core.eventbus.EventBus#request(String, Object) */ - default Future> request( + default Future> request( String address, Object request, Class responseType) { @@ -361,7 +361,7 @@ default Future Future> request( + default Future> request( String address, Object request, Class responseType, @@ -374,7 +374,7 @@ default Future Future> request( + default Future> request( String address, Object request, Class responseType, @@ -388,7 +388,7 @@ default Future Future> request( + default Future> request( String address, Object request, Class responseType, @@ -402,7 +402,7 @@ default Future Future> request( + default Future> request( String address, Object request, Class responseType, @@ -415,7 +415,7 @@ default Future Future> request( + default Future> request( String address, Object request, Class responseType, @@ -427,9 +427,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType) { return request(address, request.toJsonObject(), responseType); } @@ -438,9 +438,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType, DeliveryOptions options) { return request(address, request.toJsonObject(), responseType, options); @@ -451,9 +451,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType, DeliveryOptions options, MultiMap... requestHeaders) { @@ -465,9 +465,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType, DeliveryOptions options, HeaderInformation... requestHeaders) { @@ -479,9 +479,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType, MultiMap... requestHeaders) { return request(address, request.toJsonObject(), responseType, requestHeaders); @@ -492,9 +492,9 @@ default Future Future> request( + default Future> request( String address, - JsonMessage request, + JsonRecord request, Class responseType, HeaderInformation... requestHeaders) { return request(address, request.toJsonObject(), responseType, requestHeaders); @@ -515,18 +515,18 @@ default void register(String address, Handler> handler) { * @param type the type of received message to map to * @see io.vertx.core.eventbus.EventBus#consumer(String, Handler) */ - default void register(String address, MessageHandler handler, Class type) { - register(address, message -> JsonMessage.on(type, message, handler::handle)); + default void register(String address, MessageHandler handler, Class type) { + register(address, message -> JsonRecord.on(type, message, handler::handle)); } /** * @param type the type of received message to map to * @see io.vertx.core.eventbus.EventBus#consumer(String, Handler) */ - default void register( + default void register( String address, ExtendedMessageHandler handler, Class type) { - this.register(address, message -> JsonMessage.on(type, message, body -> handler.handle(body, message))); + this.register(address, message -> JsonRecord.on(type, message, body -> handler.handle(body, message))); } } diff --git a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/package-info.java b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/package-info.java index adfff588..ebdb69ea 100644 --- a/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/package-info.java +++ b/telestion-api/src/main/java/de/wuespace/telestion/api/verticle/trait/package-info.java @@ -8,9 +8,7 @@ *

* To use them, a {@link de.wuespace.telestion.api.verticle.TelestionVerticle} must simply implement one of the traits. *

- * Refer to the examples in {@code de.wuespace.telestion.example}. - *

- * (c) WueSpace e.V. + * (c) WueSpace e. V. * * @see de.wuespace.telestion.api.verticle */ diff --git a/telestion-api/src/test/java/de/wuespace/telestion/api/message/JsonMessageTest.java b/telestion-api/src/test/java/de/wuespace/telestion/api/message/JsonMessageTest.java index 84890fc2..c5fa43a9 100644 --- a/telestion-api/src/test/java/de/wuespace/telestion/api/message/JsonMessageTest.java +++ b/telestion-api/src/test/java/de/wuespace/telestion/api/message/JsonMessageTest.java @@ -27,10 +27,10 @@ public class DecodingViaHandlerTest { void shouldCallExtendedHandlerOnValidBuffer() { var buffer = VALID_JSON_OBJECT.toBuffer(); - var result = JsonMessage.on(TestMessage.class, buffer, + var result = JsonRecord.on(TestMessage.class, buffer, message -> assertThat(message, is(VALID_TEST_MESSAGE)), err -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, buffer, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, buffer, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE)), err -> fail()); @@ -42,10 +42,10 @@ void shouldCallExtendedHandlerOnValidBuffer() { void shouldCallExtendedExceptionHandlerOnInvalidBuffer() { var buffer = INVALID_JSON_OBJECT.toBuffer(); - var result = JsonMessage.on(TestMessage.class, buffer, + var result = JsonRecord.on(TestMessage.class, buffer, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, buffer, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, buffer, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); @@ -57,9 +57,9 @@ void shouldCallExtendedExceptionHandlerOnInvalidBuffer() { void shouldCallBasicHandlerOnValidBuffer() { var buffer = VALID_JSON_OBJECT.toBuffer(); - var result = JsonMessage.on(TestMessage.class, buffer, + var result = JsonRecord.on(TestMessage.class, buffer, message -> assertThat(message, is(VALID_TEST_MESSAGE))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, buffer, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, buffer, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))); assertThat(result, is(true)); @@ -70,8 +70,8 @@ void shouldCallBasicHandlerOnValidBuffer() { void shouldReturnFalseOnInvalidBufferInBasicMethod() { var buffer = INVALID_JSON_OBJECT.toBuffer(); - var result = JsonMessage.on(TestMessage.class, buffer, message -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, buffer, message -> fail()); + var result = JsonRecord.on(TestMessage.class, buffer, message -> fail()); + var anotherResult = JsonRecord.on(AnotherTestMessage.class, buffer, message -> fail()); assertThat(result, is(false)); assertThat(anotherResult, is(false)); @@ -81,10 +81,10 @@ void shouldReturnFalseOnInvalidBufferInBasicMethod() { void shouldCallExtendedHandlerOnValidJsonString() { var jsonString = VALID_JSON_OBJECT.toString(); - var result = JsonMessage.on(TestMessage.class, jsonString, + var result = JsonRecord.on(TestMessage.class, jsonString, message -> assertThat(message, is(VALID_TEST_MESSAGE)), err -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, jsonString, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, jsonString, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE)), err -> fail()); @@ -96,10 +96,10 @@ void shouldCallExtendedHandlerOnValidJsonString() { void shouldCallExtendedExceptionHandlerOnInvalidJsonString() { var jsonString = INVALID_JSON_OBJECT.toString(); - var result = JsonMessage.on(TestMessage.class, jsonString, + var result = JsonRecord.on(TestMessage.class, jsonString, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, jsonString, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, jsonString, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); @@ -111,9 +111,9 @@ void shouldCallExtendedExceptionHandlerOnInvalidJsonString() { void shouldCallBasicHandlerOnValidJsonString() { var jsonString = VALID_JSON_OBJECT.toString(); - var result = JsonMessage.on(TestMessage.class, jsonString, + var result = JsonRecord.on(TestMessage.class, jsonString, message -> assertThat(message, is(VALID_TEST_MESSAGE))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, jsonString, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, jsonString, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))); assertThat(result, is(true)); @@ -124,8 +124,8 @@ void shouldCallBasicHandlerOnValidJsonString() { void shouldReturnFalseOnInvalidJsonStringInBasicMethod() { var jsonString = INVALID_JSON_OBJECT.toString(); - var result = JsonMessage.on(TestMessage.class, jsonString, message -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, jsonString, message -> fail()); + var result = JsonRecord.on(TestMessage.class, jsonString, message -> fail()); + var anotherResult = JsonRecord.on(AnotherTestMessage.class, jsonString, message -> fail()); assertThat(result, is(false)); assertThat(anotherResult, is(false)); @@ -133,10 +133,10 @@ void shouldReturnFalseOnInvalidJsonStringInBasicMethod() { @Test void shouldCallExtendedHandlerOnValidPOJO() { - var result = JsonMessage.on(TestMessage.class, VALID_POJO, + var result = JsonRecord.on(TestMessage.class, VALID_POJO, message -> assertThat(message, is(VALID_TEST_MESSAGE)), err -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_POJO, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_POJO, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE)), err -> fail()); @@ -146,10 +146,10 @@ void shouldCallExtendedHandlerOnValidPOJO() { @Test void shouldCallExtendedExceptionHandlerOnInvalidPOJO() { - var result = JsonMessage.on(TestMessage.class, INVALID_POJO, + var result = JsonRecord.on(TestMessage.class, INVALID_POJO, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_POJO, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_POJO, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); @@ -159,9 +159,9 @@ void shouldCallExtendedExceptionHandlerOnInvalidPOJO() { @Test void shouldCallBasicHandlerOnValidPOJO() { - var result = JsonMessage.on(TestMessage.class, VALID_POJO, + var result = JsonRecord.on(TestMessage.class, VALID_POJO, message -> assertThat(message, is(VALID_TEST_MESSAGE))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_POJO, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_POJO, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))); assertThat(result, is(true)); @@ -170,8 +170,8 @@ void shouldCallBasicHandlerOnValidPOJO() { @Test void shouldReturnFalseOnInvalidPOJOInBasicMethod() { - var result = JsonMessage.on(TestMessage.class, INVALID_POJO, message -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_POJO, message -> fail()); + var result = JsonRecord.on(TestMessage.class, INVALID_POJO, message -> fail()); + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_POJO, message -> fail()); assertThat(result, is(false)); assertThat(anotherResult, is(false)); @@ -179,10 +179,10 @@ void shouldReturnFalseOnInvalidPOJOInBasicMethod() { @Test void shouldCallExtendedHandlerOnValidJsonObject() { - var result = JsonMessage.on(TestMessage.class, VALID_JSON_OBJECT, + var result = JsonRecord.on(TestMessage.class, VALID_JSON_OBJECT, message -> assertThat(message, is(VALID_TEST_MESSAGE)), err -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_JSON_OBJECT, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_JSON_OBJECT, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE)), err -> fail()); @@ -192,10 +192,10 @@ void shouldCallExtendedHandlerOnValidJsonObject() { @Test void shouldCallExtendedExceptionHandlerOnInvalidJsonObject() { - var result = JsonMessage.on(TestMessage.class, INVALID_JSON_OBJECT, + var result = JsonRecord.on(TestMessage.class, INVALID_JSON_OBJECT, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_JSON_OBJECT, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_JSON_OBJECT, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); @@ -205,9 +205,9 @@ void shouldCallExtendedExceptionHandlerOnInvalidJsonObject() { @Test void shouldCallBasicHandlerOnValidJsonObject() { - var result = JsonMessage.on(TestMessage.class, VALID_JSON_OBJECT, + var result = JsonRecord.on(TestMessage.class, VALID_JSON_OBJECT, message -> assertThat(message, is(VALID_TEST_MESSAGE))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_JSON_OBJECT, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_JSON_OBJECT, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))); assertThat(result, is(true)); @@ -216,8 +216,8 @@ void shouldCallBasicHandlerOnValidJsonObject() { @Test void shouldReturnFalseOnInvalidJsonObjectInBasicMethod() { - var result = JsonMessage.on(TestMessage.class, INVALID_JSON_OBJECT, message -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_JSON_OBJECT, + var result = JsonRecord.on(TestMessage.class, INVALID_JSON_OBJECT, message -> fail()); + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_JSON_OBJECT, message -> fail()); assertThat(result, is(false)); @@ -226,10 +226,10 @@ void shouldReturnFalseOnInvalidJsonObjectInBasicMethod() { @Test void shouldCallExtendedHandlerOnValidEventBusMessage() { - var result = JsonMessage.on(TestMessage.class, VALID_EVENTBUS_MESSAGE, + var result = JsonRecord.on(TestMessage.class, VALID_EVENTBUS_MESSAGE, message -> assertThat(message, is(VALID_TEST_MESSAGE)), err -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE)), err -> fail()); @@ -239,10 +239,10 @@ void shouldCallExtendedHandlerOnValidEventBusMessage() { @Test void shouldCallExtendedExceptionHandlerOnInvalidEventBusMessage() { - var result = JsonMessage.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE, + var result = JsonRecord.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE, message -> fail(), err -> assertThat(err, isA(RuntimeException.class))); @@ -252,9 +252,9 @@ void shouldCallExtendedExceptionHandlerOnInvalidEventBusMessage() { @Test void shouldCallBasicHandlerOnValidEventBusMessage() { - var result = JsonMessage.on(TestMessage.class, VALID_EVENTBUS_MESSAGE, + var result = JsonRecord.on(TestMessage.class, VALID_EVENTBUS_MESSAGE, message -> assertThat(message, is(VALID_TEST_MESSAGE))); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE, + var anotherResult = JsonRecord.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE, message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))); assertThat(result, is(true)); @@ -263,8 +263,8 @@ void shouldCallBasicHandlerOnValidEventBusMessage() { @Test void shouldReturnFalseOnInvalidEventBusMessageInBasicMethod() { - var result = JsonMessage.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE, message -> fail()); - var anotherResult = JsonMessage.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE, + var result = JsonRecord.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE, message -> fail()); + var anotherResult = JsonRecord.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE, message -> fail()); assertThat(result, is(false)); @@ -279,10 +279,10 @@ public class DecodingViaFutureTest { void shouldSucceedOnValidBuffer() { var buffer = VALID_JSON_OBJECT.toBuffer(); - JsonMessage.on(TestMessage.class, buffer) + JsonRecord.on(TestMessage.class, buffer) .onSuccess(message -> assertThat(message, is(VALID_TEST_MESSAGE))) .onFailure(err -> fail()); - JsonMessage.on(AnotherTestMessage.class, buffer) + JsonRecord.on(AnotherTestMessage.class, buffer) .onSuccess(message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))) .onFailure(err -> fail()); } @@ -291,10 +291,10 @@ void shouldSucceedOnValidBuffer() { void shouldFailOnInvalidBuffer() { var buffer = INVALID_JSON_OBJECT.toBuffer(); - JsonMessage.on(TestMessage.class, buffer) + JsonRecord.on(TestMessage.class, buffer) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); - JsonMessage.on(AnotherTestMessage.class, buffer) + JsonRecord.on(AnotherTestMessage.class, buffer) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); } @@ -303,10 +303,10 @@ void shouldFailOnInvalidBuffer() { void shouldSucceedOnValidJsonString() { var jsonString = VALID_JSON_OBJECT.toString(); - JsonMessage.on(TestMessage.class, jsonString) + JsonRecord.on(TestMessage.class, jsonString) .onSuccess(message -> assertThat(message, is(VALID_TEST_MESSAGE))) .onFailure(err -> fail()); - JsonMessage.on(AnotherTestMessage.class, jsonString) + JsonRecord.on(AnotherTestMessage.class, jsonString) .onSuccess(message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))) .onFailure(err -> fail()); } @@ -315,70 +315,70 @@ void shouldSucceedOnValidJsonString() { void shouldFailOnInvalidJsonString() { var jsonString = INVALID_JSON_OBJECT.toString(); - JsonMessage.on(TestMessage.class, jsonString) + JsonRecord.on(TestMessage.class, jsonString) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); - JsonMessage.on(AnotherTestMessage.class, jsonString) + JsonRecord.on(AnotherTestMessage.class, jsonString) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); } @Test void shouldSucceedOnValidPOJO() { - JsonMessage.on(TestMessage.class, VALID_POJO) + JsonRecord.on(TestMessage.class, VALID_POJO) .onSuccess(message -> assertThat(message, is(VALID_TEST_MESSAGE))) .onFailure(err -> fail()); - JsonMessage.on(AnotherTestMessage.class, VALID_POJO) + JsonRecord.on(AnotherTestMessage.class, VALID_POJO) .onSuccess(message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))) .onFailure(err -> fail()); } @Test void shouldFailOnInvalidPOJO() { - JsonMessage.on(TestMessage.class, INVALID_POJO) + JsonRecord.on(TestMessage.class, INVALID_POJO) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); - JsonMessage.on(AnotherTestMessage.class, INVALID_POJO) + JsonRecord.on(AnotherTestMessage.class, INVALID_POJO) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); } @Test void shouldSucceedOnValidJsonObject() { - JsonMessage.on(TestMessage.class, VALID_JSON_OBJECT) + JsonRecord.on(TestMessage.class, VALID_JSON_OBJECT) .onSuccess(message -> assertThat(message, is(VALID_TEST_MESSAGE))) .onFailure(err -> fail()); - JsonMessage.on(AnotherTestMessage.class, VALID_JSON_OBJECT) + JsonRecord.on(AnotherTestMessage.class, VALID_JSON_OBJECT) .onSuccess(message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))) .onFailure(err -> fail()); } @Test void shouldFailOnInvalidJsonObject() { - JsonMessage.on(TestMessage.class, INVALID_JSON_OBJECT) + JsonRecord.on(TestMessage.class, INVALID_JSON_OBJECT) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); - JsonMessage.on(AnotherTestMessage.class, INVALID_JSON_OBJECT) + JsonRecord.on(AnotherTestMessage.class, INVALID_JSON_OBJECT) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); } @Test void shouldSucceedOnValidEventBusMessage() { - JsonMessage.on(TestMessage.class, VALID_EVENTBUS_MESSAGE) + JsonRecord.on(TestMessage.class, VALID_EVENTBUS_MESSAGE) .onSuccess(message -> assertThat(message, is(VALID_TEST_MESSAGE))) .onFailure(err -> fail()); - JsonMessage.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE) + JsonRecord.on(AnotherTestMessage.class, VALID_EVENTBUS_MESSAGE) .onSuccess(message -> assertThat(message, is(VALID_ANOTHER_TEST_MESSAGE))) .onFailure(err -> fail()); } @Test void shouldFailOnInvalidEventBusMessage() { - JsonMessage.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE) + JsonRecord.on(TestMessage.class, INVALID_EVENTBUS_MESSAGE) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); - JsonMessage.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE) + JsonRecord.on(AnotherTestMessage.class, INVALID_EVENTBUS_MESSAGE) .onSuccess(message -> fail()) .onFailure(err -> assertThat(err, isA(RuntimeException.class))); } @@ -392,8 +392,8 @@ public class SynchronousDecodingTest { void shouldDecodeAValidBuffer() { var buffer = VALID_JSON_OBJECT.toBuffer(); - var testMessage = JsonMessage.from(buffer, TestMessage.class); - var anotherTestMessage = JsonMessage.from(buffer, AnotherTestMessage.class); + var testMessage = JsonRecord.from(buffer, TestMessage.class); + var anotherTestMessage = JsonRecord.from(buffer, AnotherTestMessage.class); assertThat(testMessage, is(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, is(VALID_ANOTHER_TEST_MESSAGE)); @@ -405,8 +405,8 @@ void shouldNotDecodeAnInvalidBuffer() { // capture both DecodeException and IllegalArgumentException assertThrows(RuntimeException.class, () -> { - var testMessage = JsonMessage.from(buffer, TestMessage.class); - var anotherTestMessage = JsonMessage.from(buffer, AnotherTestMessage.class); + var testMessage = JsonRecord.from(buffer, TestMessage.class); + var anotherTestMessage = JsonRecord.from(buffer, AnotherTestMessage.class); assertThat(testMessage, not(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, not(VALID_ANOTHER_TEST_MESSAGE)); @@ -417,8 +417,8 @@ void shouldNotDecodeAnInvalidBuffer() { void shouldDecodeAValidJsonString() { var jsonString = VALID_JSON_OBJECT.toString(); - var testMessage = JsonMessage.from(jsonString, TestMessage.class); - var anotherTestMessage = JsonMessage.from(jsonString, AnotherTestMessage.class); + var testMessage = JsonRecord.from(jsonString, TestMessage.class); + var anotherTestMessage = JsonRecord.from(jsonString, AnotherTestMessage.class); assertThat(testMessage, is(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, is(VALID_ANOTHER_TEST_MESSAGE)); @@ -430,8 +430,8 @@ void shouldNotDecodeAnInvalidJsonString() { // capture both DecodeException and IllegalArgumentException assertThrows(RuntimeException.class, () -> { - var testMessage = JsonMessage.from(jsonString, TestMessage.class); - var anotherTestMessage = JsonMessage.from(jsonString, AnotherTestMessage.class); + var testMessage = JsonRecord.from(jsonString, TestMessage.class); + var anotherTestMessage = JsonRecord.from(jsonString, AnotherTestMessage.class); assertThat(testMessage, not(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, not(VALID_ANOTHER_TEST_MESSAGE)); @@ -440,8 +440,8 @@ void shouldNotDecodeAnInvalidJsonString() { @Test void shouldDecodeAValidPOJO() { - var testMessage = JsonMessage.from(VALID_POJO, TestMessage.class); - var anotherTestMessage = JsonMessage.from(VALID_POJO, AnotherTestMessage.class); + var testMessage = JsonRecord.from(VALID_POJO, TestMessage.class); + var anotherTestMessage = JsonRecord.from(VALID_POJO, AnotherTestMessage.class); assertThat(testMessage, is(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, is(VALID_ANOTHER_TEST_MESSAGE)); @@ -451,8 +451,8 @@ void shouldDecodeAValidPOJO() { void shouldNotDecodeAnInvalidPOJO() { // capture both DecodeException and IllegalArgumentException assertThrows(RuntimeException.class, () -> { - var testMessage = JsonMessage.from(INVALID_POJO, TestMessage.class); - var anotherTestMessage = JsonMessage.from(INVALID_POJO, AnotherTestMessage.class); + var testMessage = JsonRecord.from(INVALID_POJO, TestMessage.class); + var anotherTestMessage = JsonRecord.from(INVALID_POJO, AnotherTestMessage.class); assertThat(testMessage, not(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, not(VALID_ANOTHER_TEST_MESSAGE)); @@ -461,8 +461,8 @@ void shouldNotDecodeAnInvalidPOJO() { @Test void shouldDecodeAValidJsonObject() { - var testMessage = JsonMessage.from(VALID_JSON_OBJECT, TestMessage.class); - var anotherTestMessage = JsonMessage.from(VALID_JSON_OBJECT, AnotherTestMessage.class); + var testMessage = JsonRecord.from(VALID_JSON_OBJECT, TestMessage.class); + var anotherTestMessage = JsonRecord.from(VALID_JSON_OBJECT, AnotherTestMessage.class); assertThat(testMessage, is(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, is(VALID_ANOTHER_TEST_MESSAGE)); @@ -472,8 +472,8 @@ void shouldDecodeAValidJsonObject() { void shouldNotDecodeAnInvalidJsonObject() { // capture both DecodeException and IllegalArgumentException assertThrows(RuntimeException.class, () -> { - var testMessage = JsonMessage.from(INVALID_JSON_OBJECT, TestMessage.class); - var anotherTestMessage = JsonMessage.from(INVALID_JSON_OBJECT, AnotherTestMessage.class); + var testMessage = JsonRecord.from(INVALID_JSON_OBJECT, TestMessage.class); + var anotherTestMessage = JsonRecord.from(INVALID_JSON_OBJECT, AnotherTestMessage.class); assertThat(testMessage, not(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, not(VALID_ANOTHER_TEST_MESSAGE)); @@ -482,8 +482,8 @@ void shouldNotDecodeAnInvalidJsonObject() { @Test void shouldDecodeAValidEventBusMessage() { - var testMessage = JsonMessage.from(VALID_EVENTBUS_MESSAGE, TestMessage.class); - var anotherTestMessage = JsonMessage.from(VALID_EVENTBUS_MESSAGE, AnotherTestMessage.class); + var testMessage = JsonRecord.from(VALID_EVENTBUS_MESSAGE, TestMessage.class); + var anotherTestMessage = JsonRecord.from(VALID_EVENTBUS_MESSAGE, AnotherTestMessage.class); assertThat(testMessage, is(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, is(VALID_ANOTHER_TEST_MESSAGE)); @@ -493,8 +493,8 @@ void shouldDecodeAValidEventBusMessage() { void shouldNotDecodeAnInvalidEventBusMessage() { // capture both DecodeException and IllegalArgumentException assertThrows(RuntimeException.class, () -> { - var testMessage = JsonMessage.from(INVALID_EVENTBUS_MESSAGE, TestMessage.class); - var anotherTestMessage = JsonMessage.from(INVALID_EVENTBUS_MESSAGE, AnotherTestMessage.class); + var testMessage = JsonRecord.from(INVALID_EVENTBUS_MESSAGE, TestMessage.class); + var anotherTestMessage = JsonRecord.from(INVALID_EVENTBUS_MESSAGE, AnotherTestMessage.class); assertThat(testMessage, not(VALID_TEST_MESSAGE)); assertThat(anotherTestMessage, not(VALID_ANOTHER_TEST_MESSAGE)); @@ -622,25 +622,25 @@ void shouldReturnTheClassNameOfAMessage() { @Test void shouldEncodeAndDecodeAMessageViaAJsonObject() { var encoded = VALID_TEST_MESSAGE.toJsonObject(); - assertThat(JsonMessage.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); // should also decode to another test message type with the same parameters - assertThat(JsonMessage.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); } @Test void shouldEncodeAndDecodeAMessageViaAJsonString() { var encoded = VALID_TEST_MESSAGE.toJsonString(); - assertThat(JsonMessage.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); // should also decode to another test message type with the same parameters - assertThat(JsonMessage.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); } @Test void shouldEncodeAndDecodeAMessageViaABuffer() { var encoded = VALID_TEST_MESSAGE.toJsonBuffer(); - assertThat(JsonMessage.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, TestMessage.class), is(VALID_TEST_MESSAGE)); // should also decode to another test message type with the same parameters - assertThat(JsonMessage.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); + assertThat(JsonRecord.from(encoded, AnotherTestMessage.class), is(VALID_ANOTHER_TEST_MESSAGE)); } // "Invalid" means the parsing should fail due to incompatible parameters types @@ -685,10 +685,10 @@ public int hashCode() { } } - public record TestMessage(@JsonProperty float param) implements JsonMessage { + public record TestMessage(@JsonProperty float param) implements JsonRecord { } - public record AnotherTestMessage(@JsonProperty float param) implements JsonMessage { + public record AnotherTestMessage(@JsonProperty float param) implements JsonRecord { } public final float VALID_PARAM = 0.0f;