Mercurial > hg > orthanc
annotate UnitTests/RestApi.cpp @ 223:6f0e4a8ebb0f
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 18:07:50 +0100 |
parents | bd934af46ba4 |
children | e5402c368b21 |
rev | line source |
---|---|
209 | 1 #include "gtest/gtest.h" |
2 | |
3 #include <ctype.h> | |
4 #include <glog/logging.h> | |
5 | |
6 #include "../Core/RestApi/RestApi.h" | |
221
e7432706b354
accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
7 #include "../Core/Uuid.h" |
e7432706b354
accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
8 #include "../Core/OrthancException.h" |
e7432706b354
accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
9 #include "../Core/Compression/ZlibCompressor.h" |
209 | 10 |
11 using namespace Orthanc; | |
12 | |
13 TEST(RestApi, RestApiPath) | |
14 { | |
15 RestApiPath::Components args; | |
16 UriComponents trail; | |
17 | |
18 { | |
19 RestApiPath uri("/coucou/{abc}/d/*"); | |
20 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
21 ASSERT_EQ(1u, args.size()); | |
22 ASSERT_EQ(3u, trail.size()); | |
23 ASSERT_EQ("moi", args["abc"]); | |
24 ASSERT_EQ("e", trail[0]); | |
25 ASSERT_EQ("f", trail[1]); | |
26 ASSERT_EQ("g", trail[2]); | |
27 | |
28 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f")); | |
29 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/")); | |
30 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d")); | |
31 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi")); | |
32 } | |
33 | |
34 { | |
35 RestApiPath uri("/coucou/{abc}/d"); | |
36 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
37 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d")); | |
38 ASSERT_EQ(1u, args.size()); | |
39 ASSERT_EQ(0u, trail.size()); | |
40 ASSERT_EQ("moi", args["abc"]); | |
41 } | |
42 | |
43 { | |
44 RestApiPath uri("/*"); | |
45 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c")); | |
46 ASSERT_EQ(0u, args.size()); | |
47 ASSERT_EQ(3u, trail.size()); | |
48 ASSERT_EQ("a", trail[0]); | |
49 ASSERT_EQ("b", trail[1]); | |
50 ASSERT_EQ("c", trail[2]); | |
51 } | |
52 } | |
53 | |
54 | |
55 | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
56 #if 0 |
209 | 57 |
58 #include "../Core/HttpServer/MongooseServer.h" | |
59 | |
60 struct Tutu : public IDynamicObject | |
61 { | |
62 static void Toto(RestApi::GetCall& call) | |
63 { | |
64 printf("DONE\n"); | |
65 Json::Value a = Json::objectValue; | |
66 a["Tutu"] = "Toto"; | |
67 a["Youpie"] = call.GetArgument("coucou", "nope"); | |
68 a["Toto"] = call.GetUriComponent("test", "nope"); | |
69 call.GetOutput().AnswerJson(a); | |
70 } | |
71 }; | |
72 | |
73 | |
74 | |
75 TEST(RestApi, Tutu) | |
76 { | |
77 MongooseServer httpServer; | |
78 httpServer.SetPortNumber(8042); | |
79 httpServer.Start(); | |
80 | |
81 RestApi* api = new RestApi; | |
82 httpServer.RegisterHandler(api); | |
83 api->Register("/coucou/{test}/a/*", Tutu::Toto); | |
84 | |
85 httpServer.Start(); | |
86 /*LOG(WARNING) << "REST has started"; | |
87 Toolbox::ServerBarrier();*/ | |
88 } | |
210
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
89 |
96b7918a6a18
start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
90 #endif |