@Test void testMessageCreationBasedOnResultMessage() { Map<String, String> metaData = Collections.singletonMap("k1", "v1"); CommandResultMessage<String> resultMessage = GenericCommandResultMessage.asCommandResultMessage( new GenericResultMessage<>("result", metaData)); SubscriptionQueryUpdateMessage<Object> result = GenericSubscriptionQueryUpdateMessage.asUpdateMessage( resultMessage); assertEquals(result.getPayload(), resultMessage.getPayload()); assertEquals(result.getMetaData(), resultMessage.getMetaData()); }
@SuppressWarnings("unchecked") public static <T> SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload) { if (payload instanceof SubscriptionQueryUpdateMessage) { return (SubscriptionQueryUpdateMessage<T>) payload; } else if (payload instanceof ResultMessage) { ResultMessage<T> resultMessage = (ResultMessage<T>) payload; if (resultMessage.isExceptional()) { Throwable cause = resultMessage.exceptionResult(); return new GenericSubscriptionQueryUpdateMessage<>(resultMessage.getPayloadType(), cause, resultMessage.getMetaData()); } return new GenericSubscriptionQueryUpdateMessage<>(resultMessage); } else if (payload instanceof Message) { return new GenericSubscriptionQueryUpdateMessage<>((Message<T>) payload); } return new GenericSubscriptionQueryUpdateMessage<>((T) payload); }
GenericSubscriptionQueryUpdateMessage extends GenericResultMessage<U> implements SubscriptionQueryUpdateMessage<U> { @SuppressWarnings("unchecked") public static <T> SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload) { if (payload instanceof SubscriptionQueryUpdateMessage) { return (SubscriptionQueryUpdateMessage<T>) payload; } else if (payload instanceof ResultMessage) { ResultMessage<T> resultMessage = (ResultMessage<T>) payload; if (resultMessage.isExceptional()) { Throwable cause = resultMessage.exceptionResult(); return new GenericSubscriptionQueryUpdateMessage<>(resultMessage.getPayloadType(), cause, resultMessage.getMetaData()); } return new GenericSubscriptionQueryUpdateMessage<>(resultMessage); } else if (payload instanceof Message) { return new GenericSubscriptionQueryUpdateMessage<>((Message<T>) payload); } return new GenericSubscriptionQueryUpdateMessage<>((T) payload); } }
GenericSubscriptionQueryUpdateMessage extends GenericResultMessage<U> implements SubscriptionQueryUpdateMessage<U> { @SuppressWarnings("unchecked") public static <T> SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload) { if (payload instanceof SubscriptionQueryUpdateMessage) { return (SubscriptionQueryUpdateMessage<T>) payload; } else if (payload instanceof ResultMessage) { ResultMessage<T> resultMessage = (ResultMessage<T>) payload; if (resultMessage.isExceptional()) { Throwable cause = resultMessage.exceptionResult(); return new GenericSubscriptionQueryUpdateMessage<>(resultMessage.getPayloadType(), cause, resultMessage.getMetaData()); } return new GenericSubscriptionQueryUpdateMessage<>(resultMessage); } else if (payload instanceof Message) { return new GenericSubscriptionQueryUpdateMessage<>((Message<T>) payload); } return new GenericSubscriptionQueryUpdateMessage<>((T) payload); } GenericSubscriptionQueryUpdateMessage(U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload, Map<String, ?> metaData);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, Throwable exception, Map<String, ?> metaData); protected  GenericSubscriptionQueryUpdateMessage(Message<U> delegate); }
GenericSubscriptionQueryUpdateMessage extends GenericResultMessage<U> implements SubscriptionQueryUpdateMessage<U> { @SuppressWarnings("unchecked") public static <T> SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload) { if (payload instanceof SubscriptionQueryUpdateMessage) { return (SubscriptionQueryUpdateMessage<T>) payload; } else if (payload instanceof ResultMessage) { ResultMessage<T> resultMessage = (ResultMessage<T>) payload; if (resultMessage.isExceptional()) { Throwable cause = resultMessage.exceptionResult(); return new GenericSubscriptionQueryUpdateMessage<>(resultMessage.getPayloadType(), cause, resultMessage.getMetaData()); } return new GenericSubscriptionQueryUpdateMessage<>(resultMessage); } else if (payload instanceof Message) { return new GenericSubscriptionQueryUpdateMessage<>((Message<T>) payload); } return new GenericSubscriptionQueryUpdateMessage<>((T) payload); } GenericSubscriptionQueryUpdateMessage(U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload, Map<String, ?> metaData);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, Throwable exception, Map<String, ?> metaData); protected  GenericSubscriptionQueryUpdateMessage(Message<U> delegate); @SuppressWarnings("unchecked") static SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload); static SubscriptionQueryUpdateMessage<T> asUpdateMessage(Class<T> declaredType, Throwable exception); @Override GenericSubscriptionQueryUpdateMessage<U> withMetaData(Map<String, ?> metaData); @Override GenericSubscriptionQueryUpdateMessage<U> andMetaData(Map<String, ?> metaData); }
GenericSubscriptionQueryUpdateMessage extends GenericResultMessage<U> implements SubscriptionQueryUpdateMessage<U> { @SuppressWarnings("unchecked") public static <T> SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload) { if (payload instanceof SubscriptionQueryUpdateMessage) { return (SubscriptionQueryUpdateMessage<T>) payload; } else if (payload instanceof ResultMessage) { ResultMessage<T> resultMessage = (ResultMessage<T>) payload; if (resultMessage.isExceptional()) { Throwable cause = resultMessage.exceptionResult(); return new GenericSubscriptionQueryUpdateMessage<>(resultMessage.getPayloadType(), cause, resultMessage.getMetaData()); } return new GenericSubscriptionQueryUpdateMessage<>(resultMessage); } else if (payload instanceof Message) { return new GenericSubscriptionQueryUpdateMessage<>((Message<T>) payload); } return new GenericSubscriptionQueryUpdateMessage<>((T) payload); } GenericSubscriptionQueryUpdateMessage(U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload, Map<String, ?> metaData);  GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, Throwable exception, Map<String, ?> metaData); protected  GenericSubscriptionQueryUpdateMessage(Message<U> delegate); @SuppressWarnings("unchecked") static SubscriptionQueryUpdateMessage<T> asUpdateMessage(Object payload); static SubscriptionQueryUpdateMessage<T> asUpdateMessage(Class<T> declaredType, Throwable exception); @Override GenericSubscriptionQueryUpdateMessage<U> withMetaData(Map<String, ?> metaData); @Override GenericSubscriptionQueryUpdateMessage<U> andMetaData(Map<String, ?> metaData);  }