Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
94df54b7
Commit
94df54b7
authored
Mar 02, 2020
by
Piotr Gawron
Browse files
documentation for drug API calls
parent
cb12e30f
Pipeline
#21882
passed with stage
in 16 minutes and 4 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
web/src/main/asciidoc/projects/project_drugs.adoc
0 → 100644
View file @
94df54b7
= Rest API Documentation - Project drugs
Piotr Gawron
v{project-version} {build-time}
:toc: left
:sectnums:
== Get drug
Returns drugs data with project related connections.
=== CURL sample
include::{snippets}/projects/project_drugs/search_by_query/curl-request.adoc[]
=== Path Parameters
include::{snippets}/projects/project_drugs/search_by_query/path-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_drugs/search_by_query/response-fields.adoc[]
=== Sample Response
include::{snippets}/projects/project_drugs/search_by_query/response-body.adoc[]
== Get suggested drug queries
Get list of suggested drug queries in the context of the project.
=== CURL sample
include::{snippets}/projects/project_drugs/suggested_query_list/curl-request.adoc[]
=== Path Parameters
include::{snippets}/projects/project_drugs/suggested_query_list/path-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_drugs/suggested_query_list/response-fields.adoc[]
=== Sample Response
include::{snippets}/projects/project_drugs/suggested_query_list/response-body.adoc[]
web/src/test/java/lcsb/mapviewer/web/ChemicalControllerIntegrationTest.java
View file @
94df54b7
...
...
@@ -5,11 +5,8 @@ import static org.junit.Assume.assumeTrue;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.*;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
parameterWithName
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
requestParameters
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.Before
;
...
...
@@ -18,7 +15,6 @@ import org.junit.runner.RunWith;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.mock.web.MockHttpSession
;
import
org.springframework.restdocs.payload.ResponseFieldsSnippet
;
import
org.springframework.restdocs.request.RequestParametersSnippet
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
...
...
@@ -27,7 +23,6 @@ import org.springframework.transaction.annotation.Transactional;
import
com.google.gson.JsonParser
;
import
lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
...
...
@@ -45,9 +40,6 @@ public class ChemicalControllerIntegrationTest extends ControllerIntegrationTest
@SuppressWarnings
(
"unused"
)
private
Logger
logger
=
LogManager
.
getLogger
();
@Autowired
private
ChemicalRestImpl
chemicalRestImpl
;
@Autowired
private
IProjectService
projectService
;
...
...
@@ -102,20 +94,6 @@ public class ChemicalControllerIntegrationTest extends ControllerIntegrationTest
}
private
RequestParametersSnippet
getChemicalFilter
()
{
return
requestParameters
(
parameterWithName
(
"columns"
)
.
description
(
"set of columns (all by default). Available options: "
+
StringUtils
.
join
(
chemicalRestImpl
.
getAvailableChemicalColumns
(),
", "
))
.
optional
(),
parameterWithName
(
"query"
)
.
description
(
"name of chemical that we are searching for"
)
.
optional
(),
parameterWithName
(
"target"
)
.
description
(
"target element that we are searching for in format TYPE:ID"
)
.
optional
());
}
private
ResponseFieldsSnippet
listOfChemicalsFields
()
{
return
responseFields
(
subsectionWithPath
(
"[].id"
)
...
...
web/src/test/java/lcsb/mapviewer/web/ControllerIntegrationTest.java
View file @
94df54b7
package
lcsb.mapviewer.web
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
documentationConfiguration
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
parameterWithName
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
pathParameters
;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
...
...
@@ -19,6 +18,7 @@ import javax.annotation.PostConstruct;
import
javax.annotation.PreDestroy
;
import
javax.servlet.Filter
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.core.LogEvent
;
...
...
@@ -28,6 +28,7 @@ import org.springframework.mock.web.MockHttpSession;
import
org.springframework.restdocs.JUnitRestDocumentation
;
import
org.springframework.restdocs.operation.preprocess.Preprocessors
;
import
org.springframework.restdocs.request.PathParametersSnippet
;
import
org.springframework.restdocs.request.RequestParametersSnippet
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.web.WebAppConfiguration
;
...
...
@@ -36,6 +37,7 @@ import org.springframework.test.web.servlet.RequestBuilder;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
import
lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl
;
import
lcsb.mapviewer.common.MinervaLoggerAppender
;
import
lcsb.mapviewer.common.UnitTestFailedWatcher
;
import
lcsb.mapviewer.model.*
;
...
...
@@ -113,6 +115,10 @@ abstract public class ControllerIntegrationTest {
private
String
dapiLogin
;
private
String
dapiPassword
;
@Autowired
private
ChemicalRestImpl
chemicalRestImpl
;
@PostConstruct
public
void
construct
()
{
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
)
...
...
@@ -532,4 +538,19 @@ abstract public class ControllerIntegrationTest {
return
getProjectPathParameters
().
and
(
parameterWithName
(
"mapId"
).
description
(
"map identifier"
));
}
protected
RequestParametersSnippet
getChemicalFilter
()
{
return
requestParameters
(
parameterWithName
(
"columns"
)
.
description
(
"set of columns (all by default). Available options: "
+
StringUtils
.
join
(
chemicalRestImpl
.
getAvailableChemicalColumns
(),
", "
))
.
optional
(),
parameterWithName
(
"query"
)
.
description
(
"name of chemical that we are searching for"
)
.
optional
(),
parameterWithName
(
"target"
)
.
description
(
"target element that we are searching for in format TYPE:ID"
)
.
optional
());
}
}
web/src/test/java/lcsb/mapviewer/web/DrugControllerIntegrationTest.java
View file @
94df54b7
package
lcsb.mapviewer.web
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -8,8 +10,8 @@ import org.apache.logging.log4j.Logger;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpSession
;
import
org.springframework.restdocs.payload.ResponseFieldsSnippet
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
...
...
@@ -20,21 +22,28 @@ import org.springframework.transaction.annotation.Transactional;
@Rollback
public
class
DrugControllerIntegrationTest
extends
ControllerIntegrationTest
{
private
static
String
TEST_PROJECT
=
"TEST_PROJECT"
;
Logger
logger
=
LogManager
.
getLogger
();
@Before
public
void
setup
()
{
createProject
(
TEST_PROJECT
);
}
@Test
public
void
testSearchDrugsInProjectUrl
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/
"
+
BUILT_IN_PROJECT
+
"/drugs:search"
)
RequestBuilder
request
=
get
(
"/projects/
{projectId}/drugs:search?query=aspirin"
,
TEST_PROJECT
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
());
.
andExpect
(
status
().
is2xxSuccessful
())
.
andDo
(
document
(
"projects/project_drugs/search_by_query"
,
getProjectPathParameters
(),
getChemicalFilter
(),
listOfDrugFields
()));
}
@Test
...
...
@@ -63,10 +72,16 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
public
void
testGetSuggestedList
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/
"
+
BUILT_IN_PROJECT
+
"
/drugs/suggestedQueryList"
)
RequestBuilder
request
=
get
(
"/projects/
{projectId}
/drugs/suggestedQueryList"
,
TEST_PROJECT
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"projects/project_drugs/suggested_query_list"
,
getProjectPathParameters
(),
responseFields
(
fieldWithPath
(
"[]"
)
.
description
(
"list of suggested drug queries"
)
.
type
(
"Array<String>"
))))
.
andExpect
(
status
().
is2xxSuccessful
());
}
...
...
@@ -81,4 +96,44 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
.
andExpect
(
status
().
isNotFound
());
}
private
ResponseFieldsSnippet
listOfDrugFields
()
{
return
responseFields
(
subsectionWithPath
(
"[].id"
)
.
description
(
"identifier of the chemical"
)
.
type
(
"Object"
),
fieldWithPath
(
"[].name"
)
.
description
(
"name"
)
.
type
(
"string"
),
fieldWithPath
(
"[].description"
)
.
description
(
"description"
)
.
type
(
"string"
),
fieldWithPath
(
"[].synonyms"
)
.
description
(
"list of synonyms"
)
.
type
(
"Array<String>"
),
fieldWithPath
(
"[].brandNames"
)
.
description
(
"list of brand names"
)
.
type
(
"Array<String>"
),
fieldWithPath
(
"[].bloodBrainBarrier"
)
.
description
(
"does drug cross blood brain barrier"
)
.
type
(
"String"
),
subsectionWithPath
(
"[].references"
)
.
description
(
"list of references"
)
.
type
(
"Array<Reference>"
),
fieldWithPath
(
"[].targets"
)
.
description
(
"list of targets"
)
.
type
(
"Array<Target>"
),
fieldWithPath
(
"[].targets[].name"
)
.
description
(
"target name"
)
.
type
(
"string"
),
subsectionWithPath
(
"[].targets[].references"
)
.
description
(
"list of target references"
)
.
type
(
"Array<Reference>"
),
subsectionWithPath
(
"[].targets[].targetElements"
)
.
description
(
"list of elements on the map associated with this target"
)
.
type
(
"Array<Object>"
),
subsectionWithPath
(
"[].targets[].targetParticipants"
)
.
description
(
"list of identifiers associated with this target"
)
.
type
(
"Array<Object>"
));
}
}
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