Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qup42 committed Jan 27, 2025
1 parent b0ed847 commit 0aded7a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/ServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ TEST(ServerTest, parseHttpRequest) {
"/?query=SELECT+%2A%20WHERE%20%7B%7D&action=csv_export")),
ParsedRequestIs("/", {{"action", {"csv_export"}}},
Query{"SELECT * WHERE {}"}));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makeGetRequest("/?update=SELECT+%2A%20WHERE%20%7B%7D")),
testing::HasSubstr("SPARQL Update is not allowed as GET request."));
EXPECT_THAT(
parse(makeGetRequest("/?graph=%3Cfoo%3E")),
ParsedRequestIs("/", {{"graph", {"<foo>"}}}, GraphStoreOperation{}));
Expand All @@ -64,6 +67,14 @@ TEST(ServerTest, parseHttpRequest) {
parse(makeGetRequest("/?graph=%3Cfoo%3E&graph=%3Cbar%3E")),
testing::HasSubstr("Parameter \"graph\" must be "
"given exactly once. Is: 2"));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makeGetRequest("/?query=SELECT+%2A%20WHERE%20%7B%7D&graph=foo")),
testing::HasSubstr(
R"(Request contains parameters for both a SPARQL Query ("query") and a Graph Store Protocol operation ("graph" or "default").)"));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makeGetRequest("/?query=SELECT+%2A%20WHERE%20%7B%7D&default")),
testing::HasSubstr(
R"(Request contains parameters for both a SPARQL Query ("query") and a Graph Store Protocol operation ("graph" or "default").)"));
EXPECT_THAT(
parse(makePostRequest("/", URLENCODED,
"query=SELECT+%2A%20WHERE%20%7B%7D&send=100")),
Expand Down Expand Up @@ -114,11 +125,34 @@ TEST(ServerTest, parseHttpRequest) {
"parameters in the URL."));
EXPECT_THAT(parse(makePostRequest("/", URLENCODED, "cmd=clear-cache")),
ParsedRequestIs("/", {{"cmd", {"clear-cache"}}}, None{}));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/", URLENCODED, "query=a&update=b")),
testing::HasSubstr(
R"(Request must only contain one of "query" and "update".)"));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/", URLENCODED, "graph=foo")),
testing::HasSubstr(absl::StrCat("Unsupported Content type \"", URLENCODED,
"\" for "
"Graph Store protocol.")));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/", URLENCODED, "default")),
testing::HasSubstr(absl::StrCat("Unsupported Content type \"", URLENCODED,
"\" for Graph Store protocol.")));
EXPECT_THAT(parse(makePostRequest("/", QUERY, "SELECT * WHERE {}")),
ParsedRequestIs("/", {}, Query{"SELECT * WHERE {}"}));
EXPECT_THAT(
parse(makePostRequest("/?send=100", QUERY, "SELECT * WHERE {}")),
ParsedRequestIs("/", {{"send", {"100"}}}, Query{"SELECT * WHERE {}"}));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/?graph=foo", QUERY, "")),
testing::HasSubstr(
"Unsupported Content type \"application/sparql-query\" for "
"Graph Store protocol."));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/?default", QUERY, "")),
testing::HasSubstr(
"Unsupported Content type \"application/sparql-query\" for "
"Graph Store protocol."));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makeRequest(http::verb::patch, "/")),
testing::StrEq(
Expand All @@ -134,6 +168,16 @@ TEST(ServerTest, parseHttpRequest) {
testing::StrEq("SPARQL Update is not allowed as GET request."));
EXPECT_THAT(parse(makePostRequest("/", UPDATE, "DELETE * WHERE {}")),
ParsedRequestIs("/", {}, Update{"DELETE * WHERE {}"}));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/?graph=foo", UPDATE, "")),
testing::HasSubstr(
"Unsupported Content type \"application/sparql-update\" for "
"Graph Store protocol."));
AD_EXPECT_THROW_WITH_MESSAGE(
parse(makePostRequest("/?default", UPDATE, "")),
testing::HasSubstr(
"Unsupported Content type \"application/sparql-update\" for "
"Graph Store protocol."));
EXPECT_THAT(parse(makePostRequest("/", URLENCODED,
"update=DELETE%20%2A%20WHERE%20%7B%7D")),
ParsedRequestIs("/", {}, Update{"DELETE * WHERE {}"}));
Expand Down

0 comments on commit 0aded7a

Please sign in to comment.