Esempio n. 1
0
/**
 * @test the current behaviour is, that a first update to a subscription is delivered with the a second
 *       http request. Delivering the initial version of the data with the first http request would be
 *       fine too.
 */
BOOST_FIXTURE_TEST_CASE( response_to_subscription, context )
{
    answer_validation_request( node1, true );
    answer_authorization_request( node1, true );
    answer_initialization_request( node1, json::number( 42 ) );

    tools::run( *this );
    const json::array response = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( response.length(), 2u );
    json::array updates = response.at( 1 ).upcast< json::object >().at( json::string( "update" ) ).upcast< json::array >();

    BOOST_REQUIRE_EQUAL( updates.length(), 1u );
    json::object update = updates.at( 0 ).upcast< json::object >();

    BOOST_CHECK_EQUAL(
        update.at( json::string( "key" ) ),
        json::parse_single_quoted( "{ 'a':'1' ,'b':'1' }" ));

    BOOST_CHECK_EQUAL( update.at( json::string( "data" ) ), json::number( 42 ) );
}
Esempio n. 2
0
// durring tests, there was a situation, where after a browser refresh, the server did not respond to a subscription
BOOST_FIXTURE_TEST_CASE( second_subscription_to_invalid_node_must_be_communicated, context )
{
    data_.add_configuration( pubsub::node_group(), pubsub::configurator().authorization_not_required() );

    answer_validation_request( node1, false );

    // create a subscriber, subscribe to node1
    const boost::shared_ptr< pubsub::test::subscriber > first_subscriber( new pubsub::test::subscriber );
    data_.subscribe( first_subscriber, node1 );
    tools::run( *this );

    // make sure, that the subscriber is subscribed
    BOOST_REQUIRE( first_subscriber->on_invalid_node_subscription_called( node1 ) );

    const json::array response = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_GE( response.length(), 2u );

    // in the first, or the second response, there should be an update of node1
    BOOST_CHECK_NE( response.find( json::parse_single_quoted( "{ "
        "'id'     : '192.168.210.1:9999/0',"
        "'resp'   : [ { "
        "   'subscribe': {'a': '1', 'b': '1'},"
        "   'error'    : 'invalid node' } ]"
    "}" ) ), -1 );
}
Esempio n. 3
0
BOOST_FIXTURE_TEST_CASE( defered_response_to_subscription_if_validation_was_asynchronous, context )
{
    const json::array responses = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << boost::bind( update_node1_to_42, boost::ref( static_cast< pubsub::test::adapter&>( *this ) ), node1 )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( responses.length(), 2u );
    BOOST_CHECK( find_update( responses.at( 1u ).upcast< json::object >(), "{ 'a':'1' ,'b':'1' }", "42" ) );
}
Esempio n. 4
0
BOOST_FIXTURE_TEST_CASE( defered_error_message_if_not_authorized, context )
{
    const json::array response = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << boost::bind( unauthorized_node_subject, boost::ref( static_cast< pubsub::test::adapter&>( *this ) ), node1 )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( response.length(), 2u );
    json::array resp = response.at( 1 ).upcast< json::object >().at( json::string( "resp" ) ).upcast< json::array >();

    BOOST_REQUIRE_EQUAL( resp.length(), 1u );

    BOOST_CHECK_EQUAL(
        resp.at( 0 ),
        json::parse_single_quoted( "{"
            "'error': 'not allowed'"
            "'subscribe' :{ 'a':'1' ,'b':'1' } }" ) );
}
Esempio n. 5
0
BOOST_FIXTURE_TEST_CASE( error_message_if_subscription_subject_is_invalid, context )
{
    answer_validation_request( node1, false );

    const json::array response = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( response.length(), 2u );
    json::array resp = response.at( 1 ).upcast< json::object >().at( json::string( "resp" ) ).upcast< json::array >();

    BOOST_REQUIRE_EQUAL( resp.length(), 1u );

    BOOST_CHECK_EQUAL(
        resp.at( 0 ),
        json::parse_single_quoted( "{"
            "'error': 'invalid node'"
            "'subscribe' :{ 'a':'1' ,'b':'1' } }" ) );
}
Esempio n. 6
0
BOOST_FIXTURE_TEST_CASE( failed_initialization, context )
{
    answer_validation_request( node1, true );
    answer_authorization_request( node1, true );
    skip_initialization_request( node1 );

    const json::array response = json_multiple_post(
           asio_mocks::read_plan()
        << asio_mocks::json_msg( "{ 'cmd': [ { 'subscribe': { 'a':'1' ,'b':'1' } } ] }" )
        << asio_mocks::json_msg( "{ 'id': '192.168.210.1:9999/0' }" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( response.length(), 2u );
    json::array resp = response.at( 1 ).upcast< json::object >().at( json::string( "resp" ) ).upcast< json::array >();

    BOOST_REQUIRE_EQUAL( resp.length(), 1u );

    BOOST_CHECK_EQUAL(
        resp.at( 0 ),
        json::parse_single_quoted( "{"
            "'error': 'node initialization failed'"
            "'subscribe' :{ 'a':'1' ,'b':'1' } }" ) );
}
Esempio n. 7
0
BOOST_FIXTURE_TEST_CASE( unsubscribe_from_not_subscribed_node_http, context )
{
    const json::array response = json_multiple_post(
           subscribe_to_node1()
        << asio_mocks::json_msg( "{"
            "   'id': '192.168.210.1:9999/0',  "
            "   'cmd': [ "
            "       { 'unsubscribe': { 'a': '1', 'b': '2' } } "
            "   ]"
            "}" )
        << asio_mocks::disconnect_read() );

    BOOST_REQUIRE_EQUAL( response.length(), 2u );
    BOOST_CHECK_EQUAL(
        response.at( 1u ),
        json::parse_single_quoted(""
            "{"
            "   'id': '192.168.210.1:9999/0',"
            "   'resp': [{"
            "       'unsubscribe': { 'a': '1', 'b': '2' },"
            "       'error': 'not subscribed'"
            "   }]"
            "}" ) );
}