diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-08-16 22:30:03 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-08-16 22:30:03 +0100 |
commit | 09e33a20696b83d0367ebb6c9122d946173df6e8 (patch) | |
tree | b7255c8ecd6e2d1bf4236d3ca53ecbf9c3379a31 /icespider/unittests | |
parent | Demangle interface names for property lookup (diff) | |
download | icespider-09e33a20696b83d0367ebb6c9122d946173df6e8.tar.bz2 icespider-09e33a20696b83d0367ebb6c9122d946173df6e8.tar.xz icespider-09e33a20696b83d0367ebb6c9122d946173df6e8.zip |
Add basic content negotiation
Diffstat (limited to 'icespider/unittests')
-rw-r--r-- | icespider/unittests/Jamfile.jam | 2 | ||||
-rw-r--r-- | icespider/unittests/testApp.cpp | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/icespider/unittests/Jamfile.jam b/icespider/unittests/Jamfile.jam index a10d718..234e715 100644 --- a/icespider/unittests/Jamfile.jam +++ b/icespider/unittests/Jamfile.jam @@ -20,6 +20,7 @@ actions routes2cpp bind ICESPIDER lib adhocutil : : : : <include>/usr/include/adhocutil ; lib slicer : : : : <include>/usr/include/slicer ; lib slicer-json : : : : <include>/usr/include/slicer ; +lib slicer-xml : : : : <include>/usr/include/slicer ; lib boost_utf : : <name>boost_unit_test_framework ; lib dl ; path-constant me : . ; @@ -63,6 +64,7 @@ run <library>adhocutil <library>slicer <library>slicer-json + <library>slicer-xml <library>../common//icespider-common <library>../core//icespider-core <implicit-dependency>../common//icespider-common diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index 80dd6c1..1031eaf 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -68,7 +68,7 @@ class TestRequest : public IHttpRequest { IceUtil::Optional<std::string> getHeaderParam(const std::string & key) const override { - return AdHoc::safeMapLookup<std::runtime_error>(hdr, key); + return hdr.find(key) == hdr.end() ? IceUtil::Optional<std::string>() : hdr.find(key)->second; } std::istream & getInputStream() const override @@ -161,7 +161,6 @@ BOOST_AUTO_TEST_CASE( testCallMethods ) auto adp = communicator->createObjectAdapterWithEndpoints("test", "default"); auto obj = adp->addWithUUID(new TestSerice()); adp->activate(); - fprintf(stderr, "%s\n", obj->ice_id().c_str()); communicator->getProperties()->setProperty("TestIceSpider::TestApi", communicator->proxyToString(obj)); TestRequest requestGetIndex(this, HttpMethod::GET, "/"); @@ -190,6 +189,21 @@ BOOST_AUTO_TEST_CASE( testCallMethods ) process(&requestUpdateItem); BOOST_REQUIRE_EQUAL(requestDeleteItem.output.str(), "Status: 200 OK\r\n\r\n"); + TestRequest requestJson(this, HttpMethod::GET, "/"); + requestJson.hdr["Accept"] = "application/json"; + process(&requestJson); + BOOST_REQUIRE_EQUAL(requestJson.output.str(), "Status: 200 OK\r\n\r\n{\"value\":\"index\"}"); + + TestRequest requestXml(this, HttpMethod::GET, "/"); + requestXml.hdr["Accept"] = "application/xml"; + process(&requestXml); + BOOST_REQUIRE_EQUAL(requestXml.output.str(), "Status: 200 OK\r\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SomeModel><value>index</value></SomeModel>\n"); + + TestRequest requestBadAccept(this, HttpMethod::GET, "/"); + requestBadAccept.hdr["Accept"] = "not/supported"; + process(&requestBadAccept); + BOOST_REQUIRE_EQUAL(requestBadAccept.output.str(), "Status: 406 Unacceptable\r\n\r\n"); + adp->deactivate(); } |