public class TestSubscriberJsonIntegration
extends java.lang.Object
implements io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>, io.reactivex.Observer<io.vertx.core.json.JsonObject>
Helper class as subscriber to the request methods allows to specify what behavior is expected by fluently add properties to the constructor e.g.
java TestSubscriberJson sub = new TestSubscriberJson()
.expectFailure()
.errorClass(SomeError.class)
.errorMessage(String message)
.expectedOnNextCount(42)
.minimumOnNextCount(3)
.maximumOnNextCount(100)
.expectEmpty(true)
.failOnAdditionalFieldsInActual(true)
.addfieldToExist("SomeName")
.setIgnoreMissingFieldsInActual(false);
When you specify an exact number, maximum and minimum don’t make sense, but will still get reported. Class takes a VertxTestContext as parameter to allow for asynchronous testing. Implemented only for JsonObjects
Constructor and Description |
---|
TestSubscriberJsonIntegration(io.vertx.junit5.VertxTestContext context)
Constructor with test context
|
Modifier and Type | Method and Description |
---|---|
TestSubscriberJsonIntegration |
addExpectedValue(io.vertx.core.json.JsonObject expected)
Add an expected entry onto a queue, expectation is a strict sequence in return
|
TestSubscriberJsonIntegration |
addExpectedValues(java.util.Collection<io.vertx.core.json.JsonObject> expected)
Add an expected entries onto a queue, expectation is a strict sequence in return
|
TestSubscriberJsonIntegration |
addExpectedValues(io.vertx.core.json.JsonArray expected)
Add an expected entries onto a queue, expectation is a strict sequence in return
|
TestSubscriberJsonIntegration |
addfieldsToExist(java.util.Collection<java.lang.String> fieldNames)
Checks for the existence of a set of fields in JSON without checking type or content, Just the bare existence
|
TestSubscriberJsonIntegration |
addfieldToExist(java.lang.String fieldName)
Checks for the existence of a field in JSON without checking type or content, Just the bare existence
|
void |
close()
Close connection to check if results are OK
|
TestSubscriberJsonIntegration |
errorClass(java.lang.Class<? extends java.lang.Throwable> errorClass)
Specify what class of error to expect, we use ExceptionClasses extensively if not null, _expectFailure is set too
|
TestSubscriberJsonIntegration |
errorMessage(java.lang.String errorMessage)
We can look for a very specific error message
|
TestSubscriberJsonIntegration |
expectedOnNextCount(int expectedOnNextCount)
Sets the exact number of returned items we expect default is -1 = no expectations
|
TestSubscriberJsonIntegration |
expectEmpty(boolean expectEmpty)
When set to true, an empty {} is acceptable in JSON default is false
|
TestSubscriberJsonIntegration |
expectFailure(boolean expectFailure)
Specify if we expect the listener to succeed
|
TestSubscriberJsonIntegration |
failOnAdditionalFieldsInActual(boolean failOnAdditionalFieldsInActual)
If we compare Json elements, actual might have more elements than expected, if we need to ensure that, we can set this property to true, default is false, additional fields get ignored
|
int |
getDataCount() |
io.vertx.core.json.JsonObject |
getResult(int pos)
Return one result
|
io.vertx.core.json.JsonArray |
getResults()
Array with results, might be empty, never null
|
TestSubscriberJsonIntegration |
ignoreMissingFieldsInActual(boolean ignoreMissingFieldsInActual)
By default missing fields in actual throw an error, setting this to true will only compared fields found.
|
boolean |
isDisposed() |
TestSubscriberJsonIntegration |
maximumOnNextCount(int maximumOnNextCount)
Sets the maximum of returned items we expect, default is -1 = no expectations
|
TestSubscriberJsonIntegration |
minimumOnNextCount(int minimumOnNextCount)
Sets the minimum of returned items we expect, default is -1 = no expectations
|
void |
onComplete() |
void |
onError(java.lang.Throwable error) |
void |
onNext(io.vertx.core.json.JsonObject actual) |
void |
onSubscribe(io.reactivex.disposables.Disposable d1) |
io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject> |
serialize() |
TestSubscriberJsonIntegration |
setAdditionalTests(java.lang.String errorMessage,
java.util.function.Predicate<io.vertx.core.json.JsonObject> additionalTests)
Callback to hook additional tests into the onNext phase of the Subscriber
|
void |
setCancellable(io.reactivex.functions.Cancellable c) |
void |
setDisposable(io.reactivex.disposables.Disposable d) |
boolean |
tryOnError(java.lang.Throwable t) |
public TestSubscriberJsonIntegration(io.vertx.junit5.VertxTestContext context)
Constructor with test context
context
- TestContext for async operationspublic TestSubscriberJsonIntegration addExpectedValue(@Nonnull io.vertx.core.json.JsonObject expected)
Add an expected entry onto a queue, expectation is a strict sequence in return
expected
- public TestSubscriberJsonIntegration addExpectedValues(@Nonnull java.util.Collection<io.vertx.core.json.JsonObject> expected)
Add an expected entries onto a queue, expectation is a strict sequence in return
expected
- public TestSubscriberJsonIntegration addExpectedValues(@Nonnull io.vertx.core.json.JsonArray expected)
Add an expected entries onto a queue, expectation is a strict sequence in return
expected
- public TestSubscriberJsonIntegration addfieldsToExist(java.util.Collection<java.lang.String> fieldNames)
Checks for the existence of a set of fields in JSON without checking type or content, Just the bare existence
fieldNames
- public TestSubscriberJsonIntegration addfieldToExist(java.lang.String fieldName)
Checks for the existence of a field in JSON without checking type or content, Just the bare existence
fieldName
- public void close()
Close connection to check if results are OK
public TestSubscriberJsonIntegration errorClass(java.lang.Class<? extends java.lang.Throwable> errorClass)
Specify what class of error to expect, we use ExceptionClasses extensively if not null, _expectFailure is set too
errorClass
- public TestSubscriberJsonIntegration errorMessage(java.lang.String errorMessage)
We can look for a very specific error message
errorMessage
- Expected error message as Stringpublic TestSubscriberJsonIntegration expectedOnNextCount(int expectedOnNextCount)
Sets the exact number of returned items we expect default is -1 = no expectations
expectedOnNextCount
- public TestSubscriberJsonIntegration expectEmpty(boolean expectEmpty)
When set to true, an empty {} is acceptable in JSON default is false
expectEmpty
- true = accept {}, false = complaintpublic TestSubscriberJsonIntegration expectFailure(boolean expectFailure)
Specify if we expect the listener to succeed
expectFailure
- true if we expect onError but not onNextpublic TestSubscriberJsonIntegration failOnAdditionalFieldsInActual(boolean failOnAdditionalFieldsInActual)
If we compare Json elements, actual might have more elements than expected, if we need to ensure that, we can set this property to true, default is false, additional fields get ignored
failOnAdditionalFieldsInActual
- true for no extra fields, false for ignore extra fieldspublic int getDataCount()
public io.vertx.core.json.JsonObject getResult(int pos)
Return one result
pos
- Position starting with 0public io.vertx.core.json.JsonArray getResults()
Array with results, might be empty, never null
public TestSubscriberJsonIntegration ignoreMissingFieldsInActual(boolean ignoreMissingFieldsInActual)
By default missing fields in actual throw an error, setting this to true will only compared fields found. Default = false
ignoreMissingFieldsInActual
- true: only fields in actual are compared, false throws and errorpublic boolean isDisposed()
isDisposed
in interface io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>
public TestSubscriberJsonIntegration maximumOnNextCount(int maximumOnNextCount)
Sets the maximum of returned items we expect, default is -1 = no expectations
maximumOnNextCount
- public TestSubscriberJsonIntegration minimumOnNextCount(int minimumOnNextCount)
Sets the minimum of returned items we expect, default is -1 = no expectations
minimumOnNextCount
- public void onComplete()
onComplete
in interface io.reactivex.Emitter<io.vertx.core.json.JsonObject>
onComplete
in interface io.reactivex.Observer<io.vertx.core.json.JsonObject>
public void onError(java.lang.Throwable error)
onError
in interface io.reactivex.Emitter<io.vertx.core.json.JsonObject>
onError
in interface io.reactivex.Observer<io.vertx.core.json.JsonObject>
public void onNext(io.vertx.core.json.JsonObject actual)
onNext
in interface io.reactivex.Emitter<io.vertx.core.json.JsonObject>
onNext
in interface io.reactivex.Observer<io.vertx.core.json.JsonObject>
public void onSubscribe(io.reactivex.disposables.Disposable d1)
onSubscribe
in interface io.reactivex.Observer<io.vertx.core.json.JsonObject>
public io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject> serialize()
serialize
in interface io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>
public TestSubscriberJsonIntegration setAdditionalTests(java.lang.String errorMessage, java.util.function.Predicate<io.vertx.core.json.JsonObject> additionalTests)
Callback to hook additional tests into the onNext phase of the Subscriber
errorMessage
- additionalTests
- additional tests and assertions to runpublic void setCancellable(io.reactivex.functions.Cancellable c)
setCancellable
in interface io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>
public void setDisposable(io.reactivex.disposables.Disposable d)
setDisposable
in interface io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>
public boolean tryOnError(java.lang.Throwable t)
tryOnError
in interface io.reactivex.ObservableEmitter<io.vertx.core.json.JsonObject>