@ -13,36 +13,36 @@ const std::string bad_request ="HTTP/1.1 400 Bad Request\r\nContent-
using namespace session ;
SCENARIO ( " test of responses by session_manager on /v1/session " ) {
session : : resource sr ;
session : : resource sut ;
std : : stringstream ss ;
GIVEN ( " the session is invalid " ) {
WHEN ( " we receive a GET request " ) {
sr . get ( ) ;
ss < < sr ;
sut . get ( ) ;
ss < < sut ;
THEN ( " the response is a 503 Service Unavailable JSON object " )
REQUIRE ( ss . str ( ) = = service_unavailable_json ) ;
}
WHEN ( " we receive a PATCH request " ) {
sr . patch ( ) ;
ss < < sr ;
sut . patch ( ) ;
ss < < sut ;
THEN ( " the response is a 503 Service Unavailable JSON object " )
REQUIRE ( ss . str ( ) = = service_unavailable_json ) ;
}
WHEN ( " we receive a POST request " ) {
sr . post ( ) ;
ss < < sr ;
sut . post ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}
WHEN ( " we receive a DELETE request " ) {
sr . del ( ) ;
ss < < sr ;
sut . del ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}
WHEN ( " we receive a PUT request " ) {
sr . put ( ) ;
ss < < sr ;
sut . put ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}
@ -52,64 +52,62 @@ SCENARIO("test of responses by session_manager on /v1/session"){
When ( Method ( mock_session , basic_manager : : is_valid ) ) . AlwaysReturn ( true ) ;
When ( Method ( mock_session , basic_manager : : get_json ) ) . AlwaysReturn ( nullptr ) ;
auto session = std : : shared_ptr < basic_manager > ( & ( mock_session . get ( ) ) , [ ] ( . . . ) { } ) ;
sr . set_session ( session ) ;
sut . set_session ( session ) ;
WHEN ( " we receive a GET request " ) {
sr . get ( ) ;
ss < < sr ;
sut . get ( ) ;
ss < < sut ;
THEN ( " the response is a 200 OK JSON object " )
REQUIRE ( ss . str ( ) = = ok_nullptr_json ) ;
}
WHEN ( " we receive a PATCH request with invalid data " ) {
GIVEN ( " the JSON is invalid " ) {
sr . patch ( nullptr ) ;
ss < < sr ;
sut . patch ( nullptr ) ;
ss < < sut ;
THEN ( " the response is a 400 Bad Request JSON object " )
REQUIRE ( ss . str ( ) = = bad_request ) ;
}
GIVEN ( " the JSON is valid, but contains no data " ) {
sr . patch ( { } ) ;
ss < < sr ;
sut . patch ( { } ) ;
ss < < sut ;
THEN ( " the response is a 400 Bad Request JSON object " )
REQUIRE ( ss . str ( ) = = bad_request ) ;
}
GIVEN ( " the JSON is valid, but the port number is to low " ) {
When ( Method ( mock_session , basic_manager : : patch ) ) . AlwaysReturn ( false ) ;
sr . patch ( { { " listen_port " , 1 } } ) ;
ss < < sr ;
sut . patch ( { { " listen_port " , 1 } } ) ;
ss < < sut ;
THEN ( " the response is a 500 Internal Server Error JSON object " )
REQUIRE ( ss . str ( ) = = internal_server_error_json ) ;
}
GIVEN ( " the JSON is valid, but listen_port is a string " ) {
sr . patch ( { { " listen_port " , " 1 " } } ) ;
ss < < sr ;
sut . patch ( { { " listen_port " , " 1 " } } ) ;
ss < < sut ;
THEN ( " the response is a 400 Bad Request JSON object " )
REQUIRE ( ss . str ( ) = = bad_request ) ;
}
GIVEN ( " the JSON is valid, but is_paused is a string " ) {
sr . patch ( { { " is_paused " , " 1 " } } ) ;
ss < < sr ;
sut . patch ( { { " is_paused " , " 1 " } } ) ;
ss < < sut ;
THEN ( " the response is a 400 Bad Request JSON object " )
REQUIRE ( ss . str ( ) = = bad_request ) ;
}
WHEN ( " we receive a POST request " ) {
sr . post ( ) ;
ss < < sr ;
sut . post ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}
WHEN ( " we receive a DELETE request " ) {
sr . del ( ) ;
ss < < sr ;
sut . del ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}
WHEN ( " we receive a PUT request " ) {
sr . put ( ) ;
ss < < sr ;
sut . put ( ) ;
ss < < sut ;
THEN ( " the response is a 405 Method Not Allowed JSON object " )
REQUIRE ( ss . str ( ) = = method_not_allowed_json ) ;
}