summaryrefslogtreecommitdiff
path: root/icespider/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'icespider/unittests')
-rw-r--r--icespider/unittests/testApp.cpp25
-rw-r--r--icespider/unittests/testCompile.cpp4
-rw-r--r--icespider/unittests/testRoutes.json24
3 files changed, 47 insertions, 6 deletions
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index 1e9562b..b5af516 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -12,7 +12,7 @@ using namespace UserIceSpider;
BOOST_AUTO_TEST_CASE( testLoadConfiguration )
{
- BOOST_REQUIRE_EQUAL(4, AdHoc::PluginManager::getDefault()->getAll<IceSpider::IRouteHandler>().size());
+ BOOST_REQUIRE_EQUAL(6, AdHoc::PluginManager::getDefault()->getAll<IceSpider::IRouteHandler>().size());
}
BOOST_FIXTURE_TEST_SUITE(c, IceSpider::Core);
@@ -23,8 +23,8 @@ BOOST_AUTO_TEST_CASE( testCoreSettings )
BOOST_REQUIRE_EQUAL(4, routes[HttpMethod::GET].size());
BOOST_REQUIRE_EQUAL(1, routes[HttpMethod::GET][0].size());
BOOST_REQUIRE_EQUAL(0, routes[HttpMethod::GET][1].size());
- BOOST_REQUIRE_EQUAL(0, routes[HttpMethod::GET][2].size());
- BOOST_REQUIRE_EQUAL(1, routes[HttpMethod::GET][3].size());
+ BOOST_REQUIRE_EQUAL(1, routes[HttpMethod::GET][2].size());
+ BOOST_REQUIRE_EQUAL(2, routes[HttpMethod::GET][3].size());
BOOST_REQUIRE_EQUAL(1, routes[HttpMethod::HEAD].size());
BOOST_REQUIRE_EQUAL(2, routes[HttpMethod::POST].size());
BOOST_REQUIRE_EQUAL(0, routes[HttpMethod::POST][0].size());
@@ -44,7 +44,7 @@ class TestRequest : public IceSpider::IHttpRequest {
path(p)
{
}
-
+
std::string getRequestPath() const override
{
return path;
@@ -108,6 +108,12 @@ BOOST_AUTO_TEST_CASE( testFindRoutes )
TestRequest requestGetItem(this, HttpMethod::GET, "/view/something/something");
BOOST_REQUIRE(findRoute(&requestGetItem));
+ TestRequest requestGetItemParam(this, HttpMethod::GET, "/item/something/1234");
+ BOOST_REQUIRE(findRoute(&requestGetItemParam));
+
+ TestRequest requestGetItemDefault(this, HttpMethod::GET, "/item/something");
+ BOOST_REQUIRE(findRoute(&requestGetItemDefault));
+
TestRequest requestGetItemLong(this, HttpMethod::GET, "/view/something/something/extra");
BOOST_REQUIRE(!findRoute(&requestGetItemLong));
@@ -167,6 +173,17 @@ BOOST_AUTO_TEST_CASE( testCallMethods )
process(&requestGetItem);
BOOST_REQUIRE_EQUAL(requestGetItem.output.str(), "200 OK\r\n\r\n{\"value\":\"withParams\"}");
+ TestRequest requestGetItemGiven(this, HttpMethod::GET, "/item/something/1234");
+ requestGetItemGiven.url["s"] = "something";
+ requestGetItemGiven.url["i"] = "1234";
+ process(&requestGetItemGiven);
+ BOOST_REQUIRE_EQUAL(requestGetItemGiven.output.str(), "200 OK\r\n\r\n{\"value\":\"withParams\"}");
+
+ TestRequest requestGetItemDefault(this, HttpMethod::GET, "/item/something");
+ requestGetItemDefault.url["s"] = "something";
+ process(&requestGetItemDefault);
+ BOOST_REQUIRE_EQUAL(requestGetItemDefault.output.str(), "200 OK\r\n\r\n{\"value\":\"withParams\"}");
+
TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/some value");
requestDeleteItem.url["s"] = "some value";
process(&requestDeleteItem);
diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp
index 4325c16..26fc458 100644
--- a/icespider/unittests/testCompile.cpp
+++ b/icespider/unittests/testCompile.cpp
@@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE( testLoadConfiguration )
rc.applyDefaults(cfg, u);
BOOST_REQUIRE_EQUAL("common", cfg->name);
- BOOST_REQUIRE_EQUAL(4, cfg->routes.size());
+ BOOST_REQUIRE_EQUAL(6, cfg->routes.size());
BOOST_REQUIRE_EQUAL("index", cfg->routes[0]->name);
BOOST_REQUIRE_EQUAL("/", cfg->routes[0]->path);
@@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE( testLoad )
BOOST_TEST_INFO(dlerror());
BOOST_REQUIRE(lib);
- BOOST_REQUIRE_EQUAL(4, AdHoc::PluginManager::getDefault()->getAll<IceSpider::IRouteHandler>().size());
+ BOOST_REQUIRE_EQUAL(6, AdHoc::PluginManager::getDefault()->getAll<IceSpider::IRouteHandler>().size());
// smoke test (block ensure dlclose dones't cause segfault)
{
auto route = AdHoc::PluginManager::getDefault()->get<IceSpider::IRouteHandler>("common::index");
diff --git a/icespider/unittests/testRoutes.json b/icespider/unittests/testRoutes.json
index b766f31..4ad8cc3 100644
--- a/icespider/unittests/testRoutes.json
+++ b/icespider/unittests/testRoutes.json
@@ -36,6 +36,30 @@
"source": "Body"
}
]
+ },
+ {
+ "name": "defaultItem",
+ "path": "/item/{s}",
+ "method": "GET",
+ "operation": "TestIceSpider.TestApi.withParams",
+ "params": [
+ {
+ "name": "i",
+ "default": "1234"
+ }
+ ]
+ },
+ {
+ "name": "itemWithDefault",
+ "path": "/item/{s}/{i}",
+ "method": "GET",
+ "operation": "TestIceSpider.TestApi.withParams",
+ "params": [
+ {
+ "name": "i",
+ "default": "1234"
+ }
+ ]
}
],
"slices": [