NebulaStream  0.6.213
NebulaStream is a data and application management framework for the internet of things
NES::Runtime::JsonFormatTest Class Reference

Testing the functionality of the iterating over the json format. Since the created json objects may store the key-value-pairs in a different order, compared to our schema, we just check if the results contain the expected strings. More...

Collaboration diagram for NES::Runtime::JsonFormatTest:
[legend]

Public Member Functions

void SetUp () override
 
auto createJsonKVPairLambda ()
 Wraps createJsonKVPair, making it possible to pass it through functions until it is used. More...
 
template<typename T >
bool isInJsonObject (T value, const nlohmann::basic_json<> &jsonObject, const std::string &key) const
 Checks if given value is contained in json object using the string value. More...
 
auto checkExpectedValue (const nlohmann::basic_json<> &jsonObject, const std::string &key) const
 Wraps isInJsonObject, making it possible to pass it to the FormatIteratorTestUtil before it is used. More...
 
bool validateJsonIterator (SchemaPtr schema, NES::Runtime::MemoryLayouts::TestTupleBuffer *testTupleBuffer, const std::vector< std::vector< JsonKVPair >> &expectedKVPairs)
 Uses the json format iterator to read all test tuples and checks that they match the expected KV pairs. More...
 
- Public Member Functions inherited from NES::Testing::BaseUnitTest
void SetUp () override
 
void TearDown () override
 
virtual void onFatalError (int signalNumber, std::string callstack) override
 onFatalError shall be called when a signal is caught More...
 
virtual void onFatalException (std::shared_ptr< std::exception > exception, std::string callstack) override
 onFatalException shall be called when an exception is caught More...
 
- Public Member Functions inherited from NES::detail::virtual_enable_shared_from_this< ErrorListener >
 ~virtual_enable_shared_from_this () NES_NOEXCEPT(true) override=default
 
std::shared_ptr< T1 > shared_from_this ()
 
std::weak_ptr< T1 > weak_from_this ()
 
- Public Member Functions inherited from NES::detail::virtual_enable_shared_from_this_base< true >
virtual ~virtual_enable_shared_from_this_base () NES_NOEXCEPT(isNoexceptDestructible)=default
 
- Public Member Functions inherited from NES::Testing::detail::TestWaitingHelper
 TestWaitingHelper ()
 
void startWaitingThread (std::string testName)
 
void completeTest ()
 
void failTest ()
 
- Public Member Functions inherited from NES::Runtime::FormatIteratorTestUtil< JsonKVPair >
auto createTestTupleBuffer (SchemaPtr schema) const
 
auto setExpectedValue (T value, const SchemaPtr &schema, std::vector< JsonKVPair > &expectedKVPairs, CreateExpectedTypeFunc createExpectedType)
 Emplaces the field name and the value for the current field in the current expected KV pairs vector. More...
 
auto processTuple (SchemaPtr schema, NES::Runtime::MemoryLayouts::TestTupleBuffer *testTupleBuffer, std::vector< std::vector< JsonKVPair >> &expectedKVPairs, CreateExpectedTypeFunc createExpectedType, const Values &... values)
 Process a single tuple containing Values, inserting it into the testTupleBuffer. More...
 
auto processTuples (SchemaPtr schema, std::vector< std::vector< JsonKVPair >> &expectedKVPairs, CreateExpectedTypeFunc createExpectedType, const Tuples &... tuples)
 Calls processTuple for every tuple supplied by the current test. More...
 
auto processTupleWithString (SchemaPtr schema, NES::Runtime::MemoryLayouts::TestTupleBuffer *testTupleBuffer, std::vector< std::vector< JsonKVPair >> &expectedKVPairs, CreateExpectedTypeFunc createExpectedType, const Values &... values)
 Process a single tuple containing Values with Text, inserting it into the testTupleBuffer. More...
 
auto processTuplesWithString (SchemaPtr schema, std::vector< std::vector< JsonKVPair >> &expectedKVPairs, CreateExpectedTypeFunc createExpectedType, const Tuples &... tuples)
 Calls processTupleWithString for every tuple supplied by the current test. More...
 
auto validateExpectedKVPairForVariant (const JsonKVPair &expectedKVPair, CheckExpectedValueFunc checkExpectedValueFunc) const
 Gets the a value from std::variant with the correct type and validates if it is in the expected values. Expects ExpectedType to have a value member of type std::variant. More...
 

Static Public Member Functions

static void SetUpTestCase ()
 
template<typename T >
static auto createJsonKVPair (const std::pair< std::string, T > &kvPair)
 Create a json key value pair. More...
 

Additional Inherited Members

- Public Attributes inherited from NES::Testing::BaseUnitTest
detail::TestSourceNameHelper srcName
 
- Public Attributes inherited from NES::Runtime::FormatIteratorTestUtil< JsonKVPair >
BufferManagerPtr bufferManager
 

Detailed Description

Testing the functionality of the iterating over the json format. Since the created json objects may store the key-value-pairs in a different order, compared to our schema, we just check if the results contain the expected strings.

Member Function Documentation

◆ checkExpectedValue()

auto NES::Runtime::JsonFormatTest::checkExpectedValue ( const nlohmann::basic_json<> &  jsonObject,
const std::string &  key 
) const
inline

Wraps isInJsonObject, making it possible to pass it to the FormatIteratorTestUtil before it is used.

Returns
auto: A lambda function that calls isInJsonObject (avoids the need to specify a return type).

References isInJsonObject(), and magic_enum::detail::value().

Referenced by validateJsonIterator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createJsonKVPair()

template<typename T >
static auto NES::Runtime::JsonFormatTest::createJsonKVPair ( const std::pair< std::string, T > &  kvPair)
inlinestatic

Create a json key value pair.

References NES::Runtime::JsonKVPair::key.

Referenced by createJsonKVPairLambda().

Here is the caller graph for this function:

◆ createJsonKVPairLambda()

auto NES::Runtime::JsonFormatTest::createJsonKVPairLambda ( )
inline

Wraps createJsonKVPair, making it possible to pass it through functions until it is used.

Returns
auto: A lambda function that calls createJsonKVPair (avoids the need to specify a return type)

References createJsonKVPair().

Here is the call graph for this function:

◆ isInJsonObject()

template<typename T >
bool NES::Runtime::JsonFormatTest::isInJsonObject ( value,
const nlohmann::basic_json<> &  jsonObject,
const std::string &  key 
) const
inline

Checks if given value is contained in json object using the string value.

Parameters
valueThe value that must be contained in the json object.
jsonObjectThe json object for the current tuple.
keyThe specific key that must map to the expected value.
Returns
true, if value is contained in json object with given key, else false.

References NES_ERROR, and magic_enum::detail::value().

Referenced by checkExpectedValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetUp()

void NES::Runtime::JsonFormatTest::SetUp ( )
inlineoverride

References NES::Runtime::FormatIteratorTestUtil< JsonKVPair >::bufferManager, and NES::Testing::BaseUnitTest::SetUp().

Here is the call graph for this function:

◆ SetUpTestCase()

static void NES::Runtime::JsonFormatTest::SetUpTestCase ( )
inlinestatic

References NES::LOG_DEBUG, NES_INFO, and NES::Logger::setupLogging().

Here is the call graph for this function:

◆ validateJsonIterator()

bool NES::Runtime::JsonFormatTest::validateJsonIterator ( SchemaPtr  schema,
NES::Runtime::MemoryLayouts::TestTupleBuffer testTupleBuffer,
const std::vector< std::vector< JsonKVPair >> &  expectedKVPairs 
)
inline

Uses the json format iterator to read all test tuples and checks that they match the expected KV pairs.

Parameters
schemaThe schema used in the current test.
expectedKVPairsThe vector in which all vectors for the expected output are stored.
Returns
A json string, obtained by reading a tuple buffer using a json format iterator.

References NES::Runtime::FormatIteratorTestUtil< JsonKVPair >::bufferManager, checkExpectedValue(), NES::Runtime::MemoryLayouts::TestTupleBuffer::getBuffer(), and NES::Runtime::FormatIteratorTestUtil< JsonKVPair >::validateExpectedKVPairForVariant().

Here is the call graph for this function:

The documentation for this class was generated from the following file: