Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
19
Issues
19
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
53fb86ef
Commit
53fb86ef
authored
Sep 02, 2018
by
Maxym Borodenko
Committed by
Matija Obreza
Sep 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for REST controller
parent
14bd7737
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
19 deletions
+91
-19
src/main/java/org/genesys2/server/service/impl/SubsetServiceImpl.java
...a/org/genesys2/server/service/impl/SubsetServiceImpl.java
+5
-1
src/test/java/org/genesys/test/server/api/v1/SubsetRestControllerTest.java
.../genesys/test/server/api/v1/SubsetRestControllerTest.java
+86
-18
No files found.
src/main/java/org/genesys2/server/service/impl/SubsetServiceImpl.java
View file @
53fb86ef
...
...
@@ -229,6 +229,8 @@ public class SubsetServiceImpl implements SubsetService {
// Keep accessions that are not in the list
subset
.
setAccessionIds
(
subset
.
getAccessionIds
().
stream
().
filter
(
accessionId
->
!
uuidsToRemove
.
contains
(
accessionId
.
getUuid
())).
collect
(
Collectors
.
toList
()));
subset
.
setState
(
PublishState
.
DRAFT
);
return
deepLoad
(
subsetRepository
.
save
(
subset
));
}
...
...
@@ -253,6 +255,7 @@ public class SubsetServiceImpl implements SubsetService {
currentAccessions
.
add
(
accession
.
getUuid
());
}
}
subset
.
setState
(
PublishState
.
DRAFT
);
return
deepLoad
(
subsetRepository
.
save
(
subset
));
}
...
...
@@ -313,12 +316,13 @@ public class SubsetServiceImpl implements SubsetService {
throw
new
NotFoundElement
(
"No subset with specified uuid and version"
);
}
if
(!
securityUtils
.
hasRole
(
UserRole
.
ADMINISTRATOR
))
{
if
(!
securityUtils
.
hasRole
(
UserRole
.
ADMINISTRATOR
)
&&
loaded
.
getState
().
equals
(
PublishState
.
PUBLISHED
)
)
{
long
oneDay
=
24
*
60
*
60
*
1000
;
if
(
loaded
.
getLastModifiedDate
()
!=
null
&&
loaded
.
getLastModifiedDate
().
getTime
()
<=
(
System
.
currentTimeMillis
()
-
oneDay
))
{
throw
new
InvalidApiUsageException
(
"Cannot be un-published. More than 24 hours have passed since the publication."
);
}
}
loaded
.
setState
(
PublishState
.
DRAFT
);
return
deepLoad
(
subsetRepository
.
save
(
loaded
));
}
...
...
src/test/java/org/genesys/test/server/api/v1/SubsetRestControllerTest.java
View file @
53fb86ef
...
...
@@ -30,8 +30,10 @@ import java.util.Set;
import
java.util.UUID
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.stream.Collectors
;
import
java.util.HashSet
;
import
org.genesys.test.base.AbstractApiTest
;
import
org.genesys.test.base.WithMockOAuth2Authentication
;
import
org.genesys2.server.api.v1.SubsetController
;
import
org.genesys2.server.model.PublishState
;
import
org.genesys2.server.model.genesys.Accession
;
...
...
@@ -54,6 +56,7 @@ import org.junit.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.restdocs.JUnitRestDocumentation
;
import
org.springframework.security.test.context.support.WithMockUser
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -226,24 +229,30 @@ public class SubsetRestControllerTest extends AbstractApiTest {
assertNull
(
subsetRepository
.
getByUuid
(
subset
.
getUuid
()));
}
//FIXME uncomment and fix
// @Test
// public void listSubsetsTest() throws Exception {
// final Subset subset = subsetService.create(setUpSubset());
// final SubsetFilter subsetFilter = new SubsetFilter();
// subsetFilter.published = true;
//
// /*@formatter:off*/
// mockMvc.perform(post(SubsetController.API_BASE.concat("/list"))
// .contentType(MediaType.APPLICATION_JSON)
// .content(objectMapper.writeValueAsString(subsetFilter)))
// // .andDo(MockMvcResultHandlers.print())
// .andExpect(status().isOk())
// .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
// .andExpect(jsonPath("$.content[0]", not(nullValue())))
// .andExpect(jsonPath("$.content[0].id", is(subset.getId().intValue())));
// /*@formatter:on*/
// }
@Test
public
void
listSubsetsTest
()
throws
Exception
{
Subset
subset
=
subsetService
.
create
(
setUpSubset
());
assertEquals
(
subset
.
getState
(),
PublishState
.
DRAFT
);
subset
=
subsetService
.
reviewSubset
(
subset
);
assertEquals
(
subset
.
getState
(),
PublishState
.
REVIEWING
);
subset
=
subsetService
.
approveSubset
(
subset
);
assertEquals
(
subset
.
getState
(),
PublishState
.
PUBLISHED
);
final
SubsetFilter
subsetFilter
=
new
SubsetFilter
();
subsetFilter
.
state
=
new
HashSet
<>();
subsetFilter
.
state
.
add
(
PublishState
.
PUBLISHED
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
SubsetController
.
API_BASE
.
concat
(
"/list"
))
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
objectMapper
.
writeValueAsString
(
subsetFilter
)))
// .andDo(MockMvcResultHandlers.print())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andExpect
(
jsonPath
(
"$.content[0]"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.content[0].id"
,
is
(
subset
.
getId
().
intValue
())));
/*@formatter:on*/
}
@Test
public
void
removeAccessionsFromSubsetTest
()
throws
Exception
{
...
...
@@ -286,6 +295,65 @@ public class SubsetRestControllerTest extends AbstractApiTest {
assertThat
(
updated
.
getAccessionIds
().
size
(),
is
(
4
));
}
@Test
@WithMockOAuth2Authentication
(
roles
=
{
"ADMINISTRATOR"
},
scopes
=
{
"write"
})
public
void
approveSubsetTest
()
throws
Exception
{
Subset
subset
=
subsetService
.
create
(
setUpSubset
());
assertEquals
(
subset
.
getState
(),
PublishState
.
DRAFT
);
subset
=
subsetService
.
reviewSubset
(
subset
);
assertEquals
(
subset
.
getState
(),
PublishState
.
REVIEWING
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
SubsetController
.
API_BASE
.
concat
(
"/approve"
))
.
param
(
"uuid"
,
subset
.
getUuid
().
toString
())
.
param
(
"version"
,
subset
.
getVersion
().
toString
()))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.uuid"
,
is
(
subset
.
getUuid
().
toString
())))
.
andExpect
(
jsonPath
(
"$.state"
,
is
(
PublishState
.
PUBLISHED
.
name
())));
/*@formatter:on*/
}
@Test
@WithMockUser
(
username
=
"user"
,
password
=
"user"
,
roles
=
"ADMINISTRATOR"
)
public
void
reviewSubsetTest
()
throws
Exception
{
final
Subset
subset
=
subsetService
.
create
(
setUpSubset
());
assertEquals
(
subset
.
getState
(),
PublishState
.
DRAFT
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
SubsetController
.
API_BASE
.
concat
(
"/for-review"
))
.
param
(
"uuid"
,
subset
.
getUuid
().
toString
())
.
param
(
"version"
,
subset
.
getVersion
().
toString
()))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.uuid"
,
is
(
subset
.
getUuid
().
toString
())))
.
andExpect
(
jsonPath
(
"$.state"
,
is
(
PublishState
.
REVIEWING
.
name
())));
/*@formatter:on*/
}
@Test
@WithMockUser
(
username
=
"user"
,
password
=
"user"
,
roles
=
"ADMINISTRATOR"
)
public
void
rejectSubsetTest
()
throws
Exception
{
final
Subset
subset
=
subsetService
.
create
(
setUpSubset
());
assertEquals
(
subset
.
getState
(),
PublishState
.
DRAFT
);
/*@formatter:off*/
mockMvc
.
perform
(
post
(
SubsetController
.
API_BASE
.
concat
(
"/reject"
))
.
param
(
"uuid"
,
subset
.
getUuid
().
toString
())
.
param
(
"version"
,
subset
.
getVersion
().
toString
()))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
APPLICATION_JSON_UTF8
))
.
andExpect
(
jsonPath
(
"$"
,
not
(
nullValue
())))
.
andExpect
(
jsonPath
(
"$.uuid"
,
is
(
subset
.
getUuid
().
toString
())))
.
andExpect
(
jsonPath
(
"$.state"
,
is
(
PublishState
.
DRAFT
.
name
())));
/*@formatter:on*/
}
private
Subset
setUpSubset
()
{
final
Subset
subset
=
new
Subset
();
subset
.
setWiewsCode
(
institute
.
getCode
());
...
...
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