Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
fd9b2b9d
Commit
fd9b2b9d
authored
Jan 06, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(REST): накидал скелет теста для проверки REST API (через RPC)
parent
6f8dfd03
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
6 deletions
+93
-6
SMInterface.h
extensions/include/SMInterface.h
+8
-4
SMInterface.cc
extensions/lib/SMInterface.cc
+18
-0
Makefile.am
extensions/tests/Makefile.am
+1
-1
test_restapi_uniset.cc
extensions/tests/test_restapi_uniset.cc
+63
-0
UniSetObject.cc
src/ObjectRepository/UniSetObject.cc
+1
-1
uniset2.files
uniset2.files
+1
-0
uniset2.includes
uniset2.includes
+1
-0
No files found.
extensions/include/SMInterface.h
View file @
fd9b2b9d
...
...
@@ -68,23 +68,27 @@ namespace uniset
bool
waitSMready
(
int
msec
,
int
pause
=
5000
);
bool
waitSMworking
(
uniset
::
ObjectId
,
int
msec
,
int
pause
=
3000
);
inline
bool
isLocalwork
()
inline
bool
isLocalwork
()
const
noexcept
{
return
(
ic
==
NULL
);
}
inline
uniset
::
ObjectId
ID
()
inline
uniset
::
ObjectId
ID
()
const
noexcept
{
return
myid
;
}
inline
const
std
::
shared_ptr
<
IONotifyController
>
SM
()
inline
const
std
::
shared_ptr
<
IONotifyController
>
SM
()
noexcept
{
return
ic
;
}
inline
uniset
::
ObjectId
getSMID
()
inline
uniset
::
ObjectId
getSMID
()
const
noexcept
{
return
shmID
;
}
#ifndef DISABLE_REST_API
std
::
string
apiRequest
(
const
std
::
string
&
query
);
#endif
protected
:
const
std
::
shared_ptr
<
IONotifyController
>
ic
;
const
std
::
shared_ptr
<
UInterface
>
ui
;
...
...
extensions/lib/SMInterface.cc
View file @
fd9b2b9d
...
...
@@ -314,3 +314,21 @@ using namespace uniset;
return
sm_ready
;
}
// --------------------------------------------------------------------------
#ifndef DISABLE_REST_API
std
::
string
SMInterface
::
apiRequest
(
const
std
::
string
&
query
)
{
if
(
ic
)
{
BEG_FUNC1
(
SMInterface
::
apiRequest
)
SimpleInfo_var
i
=
ic
->
apiRequest
(
query
.
c_str
());
return
std
::
string
(
i
->
info
);
END_FUNC
(
SMInterface
::
apiRequest
)
}
BEG_FUNC
(
SMInterface
::
apiRequest
)
SimpleInfo_var
i
=
shm
->
apiRequest
(
query
.
c_str
());
return
std
::
string
(
i
->
info
);
END_FUNC
(
SMInterface
::
apiRequest
)
}
#endif
// --------------------------------------------------------------------------
extensions/tests/Makefile.am
View file @
fd9b2b9d
...
...
@@ -11,7 +11,7 @@ tests_with_conf_SOURCES = tests_with_conf.cc test_calibration.cc test_iobase.c
tests_with_conf_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
tests_with_conf_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
tests_with_sm_SOURCES
=
tests_with_sm.cc test_ui.cc test_iobase_with_sm.cc
tests_with_sm_SOURCES
=
tests_with_sm.cc test_ui.cc test_iobase_with_sm.cc
test_restapi_uniset.cc
tests_with_sm_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
$(SIGC_LIBS)
$(POCO_LIBS)
tests_with_sm_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
...
...
extensions/tests/test_restapi_uniset.cc
0 → 100644
View file @
fd9b2b9d
#ifndef DISABLE_REST_API
// -----------------------------------------------------------------------------
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <memory>
#include <Poco/JSON/Parser.h>
#include "Exceptions.h"
#include "Extensions.h"
#include "tests_with_sm.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
uniset
;
using
namespace
uniset
::
extensions
;
// -----------------------------------------------------------------------------
static
std
::
shared_ptr
<
SMInterface
>
shm
;
static
void
init_test
()
{
shm
=
smiInstance
();
REQUIRE
(
shm
!=
nullptr
);
REQUIRE
(
uniset_conf
()
!=
nullptr
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[RESTAPI]: "
,
"[restapi]"
)
{
init_test
();
auto
conf
=
uniset_conf
();
std
::
string
s
=
shm
->
apiRequest
(
"/conf/get?2,Input5_S¶ms=iotype"
);
Poco
::
JSON
::
Parser
parser
;
auto
result
=
parser
.
parse
(
s
);
// Ожидаемый формат ответа:
// {"conf": [
// {"id":"2","iotype":"DI","mbaddr":"0x01","mbfunc":"0x06","mbreg":"0x02","mbtype":"rtu","name":"Input2_S","nbit":"11","priority":"Medium","rs":"4","textname":"Команда 2"}
// ],
// "object":
// {"id":5003,"isActive":true,"lostMessages":0,"maxSizeOfMessageQueue":1000,"msgCount":0,"name":"SharedMemory","objectType":"IONotifyController"}
// }
//
Poco
::
JSON
::
Object
::
Ptr
json
=
result
.
extract
<
Poco
::
JSON
::
Object
::
Ptr
>
();
REQUIRE
(
json
);
auto
jconf
=
json
->
get
(
"conf"
).
extract
<
Poco
::
JSON
::
Array
::
Ptr
>
();
REQUIRE
(
jconf
);
Poco
::
JSON
::
Object
::
Ptr
jret
=
jconf
->
getObject
(
0
);
REQUIRE
(
jret
);
REQUIRE
(
jret
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"DI"
);
REQUIRE
(
jret
->
get
(
"id"
).
convert
<
ObjectId
>
()
==
2
);
Poco
::
JSON
::
Object
::
Ptr
jret2
=
jconf
->
getObject
(
1
);
REQUIRE
(
jret2
);
REQUIRE
(
jret2
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"DI"
);
REQUIRE
(
jret2
->
get
(
"name"
).
convert
<
std
::
string
>
()
==
"Input5_S"
);
REQUIRE
(
jret2
->
get
(
"id"
).
convert
<
ObjectId
>
()
==
5
);
}
// -----------------------------------------------------------------------------
#endif // ifndef DISABLE_REST_API
// -----------------------------------------------------------------------------
src/ObjectRepository/UniSetObject.cc
View file @
fd9b2b9d
...
...
@@ -989,7 +989,7 @@ namespace uniset
}
else
if
(
query
==
"conf"
)
{
// запрос вида: /conf/q
conf
?params
// запрос вида: /conf/q
uery
?params
string
qconf
=
(
seg
.
size
()
>
(
qind
+
1
)
)
?
seg
[
qind
+
1
]
:
""
;
auto
reply
=
request_conf
(
qconf
,
uri
.
getQueryParameters
());
reply
->
stringify
(
out
);
...
...
uniset2.files
View file @
fd9b2b9d
...
...
@@ -212,6 +212,7 @@ extensions/tests/test_iobase.cc
extensions/tests/test_iobase_with_sm.cc
extensions/tests/test_ui.cc
extensions/tests/test_vtypes.cc
extensions/tests/test_restapi_uniset.cc
extensions/tests/tests.cc
extensions/tests/tests_with_conf.cc
extensions/tests/tests_with_conf.xml
...
...
uniset2.includes
View file @
fd9b2b9d
...
...
@@ -26,3 +26,4 @@ Utilities/MBTester
Utilities/NullController
/usr/include/sigc++-2.0
/usr/include/omniORB4
/usr/include/Poco
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment