Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
30522f1d
Commit
30522f1d
authored
Aug 21, 2020
by
Piotr Gawron
Browse files
documentation for plugin api calls
parent
f10b492e
Changes
2
Hide whitespace changes
Inline
Side-by-side
web/src/main/asciidoc/plugin.adoc
0 → 100644
View file @
30522f1d
= Rest API Documentation - Plugins
Piotr Gawron
v{project-version} {build-time}
:toc: left
:sectnums:
== List registered plugins on the server
=== CURL sample
include::{snippets}/plugin/list_plugins/curl-request.adoc[]
=== Response Fields
include::{snippets}/plugin/list_plugins/response-fields.adoc[]
=== Sample Response
include::{snippets}/plugin/list_plugins/response-body.adoc[]
== Register new plugin on the server
=== CURL sample
include::{snippets}/plugin/create_plugin/curl-request.adoc[]
=== Request Parameters
include::{snippets}/plugin/create_plugin/request-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/create_plugin/response-fields.adoc[]
=== Sample Response
include::{snippets}/plugin/create_plugin/response-body.adoc[]
== Access information about plugin
=== CURL sample
include::{snippets}/plugin/get_plugin/curl-request.adoc[]
=== Path Parameters
include::{snippets}/plugin/get_plugin/path-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/get_plugin/response-fields.adoc[]
=== Sample Response
include::{snippets}/plugin/get_plugin/response-body.adoc[]
== Set global plugin parameter
=== CURL sample
include::{snippets}/plugin/set_plugin_data/curl-request.adoc[]
=== Path Parameters
include::{snippets}/plugin/set_plugin_data/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/plugin/set_plugin_data/request-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/set_plugin_data/response-fields.adoc[]
=== Sample Response
include::{snippets}/plugin/set_plugin_data/response-body.adoc[]
== Get global plugin parameter
=== Path Parameters
include::{snippets}/plugin/get_plugin_data/path-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/get_plugin_data/response-fields.adoc[]
=== CURL sample
include::{snippets}/plugin/get_plugin_data/curl-request.adoc[]
=== Sample Response
include::{snippets}/plugin/get_plugin_data/response-body.adoc[]
== Set user plugin parameter
=== CURL sample
include::{snippets}/plugin/set_user_plugin_data/curl-request.adoc[]
=== Path Parameters
include::{snippets}/plugin/set_user_plugin_data/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/plugin/set_user_plugin_data/request-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/set_user_plugin_data/response-fields.adoc[]
=== Sample Response
include::{snippets}/plugin/set_user_plugin_data/response-body.adoc[]
== Get user plugin parameter
=== Path Parameters
include::{snippets}/plugin/get_user_plugin_data/path-parameters.adoc[]
=== Response Fields
include::{snippets}/plugin/get_user_plugin_data/response-fields.adoc[]
=== CURL sample
include::{snippets}/plugin/get_user_plugin_data/curl-request.adoc[]
=== Sample Response
include::{snippets}/plugin/get_user_plugin_data/response-body.adoc[]
web/src/test/java/lcsb/mapviewer/web/PluginControllerIntegrationTest.java
View file @
30522f1d
...
...
@@ -2,11 +2,14 @@ package lcsb.mapviewer.web;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.*;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
fieldWithPath
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
responseFields
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.util.Arrays
;
import
java.util.Map
;
import
java.util.*
;
import
org.apache.commons.collections4.map.HashedMap
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
...
...
@@ -20,6 +23,8 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpSession
;
import
org.springframework.restdocs.payload.FieldDescriptor
;
import
org.springframework.restdocs.request.PathParametersSnippet
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
...
...
@@ -59,6 +64,20 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
user
=
createUser
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
}
@Test
public
void
listPlugins
()
throws
Exception
{
createPlugin
();
RequestBuilder
request
=
get
(
"/plugins/"
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/list_plugins"
,
responseFields
(
fieldWithPath
(
"[]"
)
.
description
(
"list of plugins"
)
.
type
(
"String"
)).
andWithPrefix
(
"[]."
,
pluginResponseFields
())))
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
createPublicPluginWithoutPrivileges
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
...
...
@@ -81,8 +100,7 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
@Test
public
void
createPublicPluginWithPrivileges
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
userService
.
grantUserPrivilege
(
user
,
PrivilegeType
.
IS_ADMIN
);
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
String
body
=
EntityUtils
.
toString
(
new
UrlEncodedFormEntity
(
Arrays
.
asList
(
new
BasicNameValuePair
(
"hash"
,
"x"
),
...
...
@@ -97,10 +115,67 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/create_plugin"
,
requestParameters
(
parameterWithName
(
"hash"
)
.
description
(
"md5 sum of javascript file"
),
parameterWithName
(
"name"
)
.
description
(
"name"
),
parameterWithName
(
"version"
)
.
description
(
"version"
),
parameterWithName
(
"isDefault"
)
.
optional
()
.
description
(
"should be opened automatically whem map is browsed"
),
parameterWithName
(
"isPublic"
)
.
description
(
"should the plugin be visible by all users"
),
parameterWithName
(
"url"
)
.
description
(
"url to the javascript file with plugin source code"
)),
responseFields
(
pluginResponseFields
())))
.
andExpect
(
status
().
is2xxSuccessful
());
assertEquals
(
1
,
pluginDao
.
getAll
().
size
());
}
@Test
public
void
getPluginInfo
()
throws
Exception
{
Plugin
plugin
=
createPlugin
();
RequestBuilder
request
=
get
(
"/plugins/{hash}"
,
plugin
.
getHash
());
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/get_plugin"
,
pluginPathParameters
(),
responseFields
(
pluginResponseFields
())))
.
andExpect
(
status
().
is2xxSuccessful
());
}
private
PathParametersSnippet
pluginPathParameters
()
{
return
pathParameters
(
parameterWithName
(
"hash"
)
.
description
(
"plugin md5 checksum"
));
}
private
List
<
FieldDescriptor
>
pluginResponseFields
()
{
return
Arrays
.
asList
(
fieldWithPath
(
"hash"
)
.
description
(
"md5 checksum of the source file"
)
.
type
(
"String"
),
fieldWithPath
(
"isDefault"
)
.
description
(
"should be opened automatically whem map is browsed"
)
.
type
(
"Boolean"
),
fieldWithPath
(
"isPublic"
)
.
description
(
"should be visible on plugin list to all users"
)
.
type
(
"Boolean"
),
fieldWithPath
(
"name"
)
.
description
(
"name"
)
.
type
(
"String"
),
fieldWithPath
(
"urls"
)
.
description
(
"list of urls where source can be found"
)
.
type
(
"String"
),
fieldWithPath
(
"version"
)
.
description
(
"plugin version"
)
.
type
(
"String"
));
}
@Test
public
void
createPublicPluginWithInvalidUrl
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
...
...
@@ -167,20 +242,68 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
String
body
=
"value=xxx"
;
Plugin
plugin
=
createPlugin
();
RequestBuilder
request
=
post
(
"/plugins/
"
+
plugin
.
getHash
()
+
"/data/global/
key
/
"
)
RequestBuilder
request
=
post
(
"/plugins/
{hash}/data/global/{key}/"
,
plugin
.
getHash
(),
"my_
key"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
content
(
body
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/set_plugin_data"
,
pluginPathParameters
().
and
(
parameterWithName
(
"key"
).
description
(
"id of the entry"
)),
requestParameters
(
parameterWithName
(
"value"
).
description
(
"value of the entry"
)),
responseFields
(
fieldWithPath
(
"key"
).
description
(
"id"
),
fieldWithPath
(
"value"
).
description
(
"value of the entry"
))))
.
andExpect
(
status
().
is2xxSuccessful
());
request
=
get
(
"/plugins/{hash}/data/global/{key}/"
,
plugin
.
getHash
(),
"my_key"
);
String
response
=
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/get_plugin_data"
,
pluginPathParameters
().
and
(
parameterWithName
(
"key"
).
description
(
"id of the entry"
)),
responseFields
(
fieldWithPath
(
"key"
).
description
(
"id"
),
fieldWithPath
(
"value"
).
description
(
"value of the entry"
))))
.
andExpect
(
status
().
is2xxSuccessful
())
.
andReturn
().
getResponse
().
getContentAsString
();
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
request
=
get
(
"/plugins/"
+
plugin
.
getHash
()
+
"/data/global/key/"
)
String
result
=
new
JsonParser
()
.
parse
(
response
)
.
getAsJsonObject
()
.
get
(
"value"
)
.
getAsString
();
assertEquals
(
"xxx"
,
result
);
}
@Test
public
void
setAndGetUserPluginData
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_LOGIN
);
String
body
=
"value=xxx"
;
Plugin
plugin
=
createPlugin
();
RequestBuilder
request
=
post
(
"/plugins/{hash}/data/users/{key}/"
,
plugin
.
getHash
(),
"my_key"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
)
.
content
(
body
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/set_user_plugin_data"
,
pluginPathParameters
().
and
(
parameterWithName
(
"key"
).
description
(
"id of the entry"
)),
requestParameters
(
parameterWithName
(
"value"
).
description
(
"value of the entry"
)),
responseFields
(
fieldWithPath
(
"key"
).
description
(
"id"
),
fieldWithPath
(
"value"
).
description
(
"value of the entry"
),
fieldWithPath
(
"user"
).
description
(
"owner of the entry"
)
)))
.
andExpect
(
status
().
is2xxSuccessful
());
request
=
get
(
"/plugins/{hash}/data/users/{key}/"
,
plugin
.
getHash
(),
"my_key"
)
.
session
(
session
);
String
response
=
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"plugin/get_user_plugin_data"
,
pluginPathParameters
().
and
(
parameterWithName
(
"key"
).
description
(
"id of the entry"
)),
responseFields
(
fieldWithPath
(
"key"
).
description
(
"id"
),
fieldWithPath
(
"value"
).
description
(
"value of the entry"
),
fieldWithPath
(
"user"
).
description
(
"owner of the entry"
))))
.
andExpect
(
status
().
is2xxSuccessful
())
.
andReturn
().
getResponse
().
getContentAsString
();
...
...
@@ -207,9 +330,9 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
());
assertNull
(
pluginDataEntryDao
.
getByKey
(
plugin
,
entry
.
getKey
(),
null
));
}
@Test
...
...
@@ -244,9 +367,10 @@ public class PluginControllerIntegrationTest extends ControllerIntegrationTest {
private
Plugin
createPlugin
()
{
Plugin
plugin
=
new
Plugin
();
plugin
.
setHash
(
"
XYZ
"
);
plugin
.
setName
(
"
a
"
);
plugin
.
setHash
(
"
520e2c4c687047d78a7fd7355b9e215d
"
);
plugin
.
setName
(
"
starter-kit
"
);
plugin
.
setVersion
(
"0.0.1"
);
plugin
.
addUrl
(
"https://minerva-dev.lcsb.uni.lu/plugins/starter-kit/plugin.js"
);
pluginDao
.
add
(
plugin
);
return
plugin
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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