Skip to content

Commit

Permalink
Used new builders from test utilies library
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquimvila committed Sep 3, 2020
1 parent 9333b25 commit 72eedb3
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions test/HttpLibWebServerAdapterTest/Tests/ServerTestData.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,85 @@
#include "stdafx.h"
#include "ServerTestData.h"

#include "WebServerAdapterTestUtilities/Builders/RequestBuilder.h"
#include "WebServerAdapterTestUtilities/Builders/ReplyBuilder.h"


using namespace systelab::web_server::test_utility;

namespace systelab { namespace web_server { namespace httplib { namespace test {

std::vector<ServerTestData> ServerTestDataBuilder::build()
{
return {
{
Request("GET", "/rest/api/health", {}, 1, 1, { {"Origin", "http://localhost:4200"} }, ""),
Reply(Reply::StatusType::OK, { {"Content-Type", "application/json"} }, "{ \"status\": \"running\" }")
RequestBuilder()
.setMethod("GET").setURI("/rest/api/health").setURIFull("/rest/api/health")
.addHeader("Origin", "http://localhost:4200")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::OK)
.addHeader("Content-Type", "application/json")
.setContent("{ \"status\": \"running\" }")
.getEntity()
},
{
Request("POST", "/rest/api/users/login", {}, 1, 1,{ { "Content-Length", "25" },{ "Content-Type", "text/plain" } }, "Request content goes here"),
Reply(Reply::StatusType::CREATED,{ { "Content-Type", "text/plain" },{ "Authorization", "Bearer 12345679012345689" } }, "Reply goes here")
RequestBuilder()
.setMethod("POST").setURI("/rest/api/users/login").setURIFull("/rest/api/users/login")
.addHeader("Content-Length", "25").addHeader("Content-Type", "text/plain")
.setContent("Request content goes here")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::CREATED)
.addHeader("Content-Type", "text/plain").addHeader("Authorization", "Bearer 12345679012345689")
.setContent("Reply goes here")
.getEntity()
},
{
Request("PUT", "/custom/url/here", {}, 1, 1,{ {"Authorization", "Bearer xxx.yyy.zzz"} }, ""),
Reply(Reply::StatusType::NOT_FOUND,{ { "Content-Type", "application/json" },{ "Authorization", "Bearer 12345679012345689" } }, "{}")
RequestBuilder()
.setMethod("PUT").setURI("/custom/url/here").setURIFull("/custom/url/here")
.addHeader("Authorization", "Bearer xxx.yyy.zzz")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::NOT_FOUND)
.addHeader("Content-Type", "application/json").addHeader("Authorization", "Bearer 12345679012345689")
.setContent("{}")
.getEntity()
},
{
Request("PATCH", "/rest/api/patch/method", {}, 1, 1,{ {"Content-Type", "application/json"} }, "{ \"aaa\": \"bbb\" }"),
Reply(Reply::StatusType::BAD_REQUEST,{ { "Content-Type", "application/json" },{ "Authorization", "Bearer 12345679012345689" } }, "{ \"ccc\": [1,2,3,4,5,6,7,8,9] }")
RequestBuilder()
.setMethod("PATCH").setURI("/rest/api/patch/method").setURIFull("/rest/api/patch/method")
.addHeader("Content-Type", "application/json")
.setContent("{ \"aaa\": \"bbb\" }")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::BAD_REQUEST)
.addHeader("Content-Type", "application/json").addHeader("Authorization", "Bearer 12345679012345689")
.setContent("{ \"ccc\": [1,2,3,4,5,6,7,8,9] }")
.getEntity()
},
{
Request("DELETE", "/rest/api/users/john",{}, 1, 1,{ { "CustomHeader", "CustomValue" } }, "Request content goes here"),
Reply(Reply::StatusType::NO_CONTENT, {}, "")
RequestBuilder()
.setMethod("DELETE")
.setURI("/rest/api/users/john").setURIFull("/rest/api/users/john")
.addHeader("CustomHeader", "CustomValue")
.setContent("Request content goes here")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::NO_CONTENT)
.getEntity()
},
{
Request("OPTIONS", "/rest/api/users",{}, 1, 1,{ { "Origin", "http://localhost:4200" } }, ""),
Reply(Reply::StatusType::INTERNAL_SERVER_ERROR,{ {"Access-Control-Allow-Origin", "http://localhost:4200"} }, "CORS reply")
RequestBuilder()
.setMethod("OPTIONS")
.setURI("/rest/api/users").setURIFull("/rest/api/users")
.addHeader("Origin", "http://localhost:4200")
.getEntity(),
ReplyBuilder()
.setStatus(Reply::StatusType::INTERNAL_SERVER_ERROR)
.addHeader("Access-Control-Allow-Origin", "http://localhost:4200")
.setContent("CORS reply")
.getEntity()
}
};
}
Expand Down

0 comments on commit 72eedb3

Please sign in to comment.