Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
ff285a55
Commit
ff285a55
authored
Sep 03, 2019
by
Piotr Gawron
Browse files
Merge branch '931-minervanet-error-report-107' into 'master'
Resolve "MINERVANET - Error Report 107" Closes
#931
See merge request
!927
parents
7f42c480
3af2f4e6
Pipeline
#13864
passed with stage
in 14 minutes and 48 seconds
Changes
8
Pipelines
18
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentController.java
View file @
ff285a55
...
...
@@ -16,7 +16,10 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import
org.springframework.web.bind.annotation.*
;
import
lcsb.mapviewer.api.*
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
@RestController
@RequestMapping
(
value
=
"/projects/{projectId}/comments"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
@@ -26,9 +29,12 @@ public class CommentController extends BaseController {
private
CommentRestImpl
commentController
;
private
IUserService
userService
;
@Autowired
public
CommentController
(
CommentRestImpl
commentController
)
{
public
CommentController
(
CommentRestImpl
commentController
,
IUserService
userService
)
{
this
.
commentController
=
commentController
;
this
.
userService
=
userService
;
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -63,7 +69,7 @@ public class CommentController extends BaseController {
@PreAuthorize
(
"hasAuthority('IS_ADMIN')"
+
" or hasAuthority('IS_CURATOR') and hasAuthority('WRITE_PROJECT:' + #projectId)"
+
" or @commentService.getComment
By
Id(#commentId)?.
user?.
login == authentication.name"
)
" or @commentService.get
OwnerBy
CommentId(#commentId)?.login == authentication.name"
)
@DeleteMapping
(
value
=
"/{commentId}/"
)
public
Map
<
String
,
Object
>
removeComment
(
@RequestBody
(
required
=
false
)
String
body
,
...
...
@@ -129,10 +135,15 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@RequestParam
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
if
(
user
.
getLogin
().
equals
(
Configuration
.
ANONYMOUS_LOGIN
))
{
user
=
null
;
}
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
ALIAS
.
getJsName
(),
elementId
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -145,10 +156,14 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@RequestParam
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
if
(
user
.
getLogin
().
equals
(
Configuration
.
ANONYMOUS_LOGIN
))
{
user
=
null
;
}
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
REACTION
.
getJsName
(),
reactionId
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -160,10 +175,14 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@PathVariable
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
if
(
user
.
getLogin
().
equals
(
Configuration
.
ANONYMOUS_LOGIN
))
{
user
=
null
;
}
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
POINT
.
getJsName
(),
coordinates
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
private
Point2D
parseCoordinates
(
String
coordinates
)
throws
QueryException
{
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentRestImpl.java
View file @
ff285a55
...
...
@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.Comment;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.dao.map.ReactionDao
;
import
lcsb.mapviewer.persist.dao.map.species.ElementDao
;
import
lcsb.mapviewer.services.interfaces.ICommentService
;
...
...
@@ -245,7 +246,7 @@ public class CommentRestImpl extends BaseRestImpl {
}
public
Map
<
String
,
Object
>
addComment
(
String
projectId
,
String
elementType
,
String
elementId
,
String
name
,
String
email
,
String
content
,
boolean
pinned
,
Point2D
pointCoordinates
,
String
submodelId
)
String
name
,
String
email
,
String
content
,
boolean
pinned
,
Point2D
pointCoordinates
,
String
submodelId
,
User
owner
)
throws
QueryException
{
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
);
if
(
model
==
null
)
{
...
...
@@ -280,7 +281,7 @@ public class CommentRestImpl extends BaseRestImpl {
}
Comment
comment
=
commentService
.
addComment
(
name
,
email
,
content
,
pointCoordinates
,
commentedObject
,
pinned
,
submodel
);
submodel
,
owner
);
return
preparedComment
(
comment
,
createCommentColumnSet
(
""
));
}
...
...
service/src/main/java/lcsb/mapviewer/services/impl/CommentService.java
View file @
ff285a55
...
...
@@ -76,7 +76,7 @@ public class CommentService implements ICommentService {
@Override
public
Comment
addComment
(
String
name
,
String
email
,
String
content
,
Point2D
coordinates
,
Object
object
,
boolean
pinned
,
Model
submodel
)
{
boolean
pinned
,
Model
submodel
,
User
owner
)
{
Comment
comment
=
new
Comment
();
comment
.
setName
(
name
);
comment
.
setEmail
(
email
);
...
...
@@ -87,7 +87,7 @@ public class CommentService implements ICommentService {
comment
.
setTableName
(
object
.
getClass
());
comment
.
setTableId
(
ObjectUtils
.
getIdOfObject
(
object
));
}
comment
.
setUser
(
null
);
comment
.
setUser
(
owner
);
comment
.
setPinned
(
pinned
);
commentDao
.
add
(
comment
);
...
...
@@ -313,4 +313,15 @@ public class CommentService implements ICommentService {
&&
!(
Math
.
abs
(
y1
-
y2
)
>
COMMENT_POINT_DISTANCE_EPSILON
);
}
@Override
public
User
getOwnerByCommentId
(
String
commentId
)
{
Comment
comment
=
getCommentById
(
commentId
);
if
(
comment
==
null
||
comment
.
getUser
()
==
null
)
{
return
null
;
}
// fetch lazy data
comment
.
getUser
().
getLogin
();
return
comment
.
getUser
();
}
}
service/src/main/java/lcsb/mapviewer/services/interfaces/ICommentService.java
View file @
ff285a55
...
...
@@ -38,7 +38,7 @@ public interface ICommentService {
* @return comment object created based on the data provided as parameters
*/
Comment
addComment
(
String
name
,
String
email
,
String
content
,
Point2D
coordinates
,
Object
object
,
boolean
pinned
,
Model
submodel
);
boolean
pinned
,
Model
submodel
,
User
owner
);
/**
* This method remove comment. Comment is not removed from the system, only
...
...
@@ -81,5 +81,7 @@ public interface ICommentService {
void
removeCommentsForModel
(
ModelData
model
);
Comment
getCommentById
(
String
commentId
);
User
getOwnerByCommentId
(
String
commentId
);
}
service/src/test/java/lcsb/mapviewer/services/impl/CommentServiceTest.java
View file @
ff285a55
...
...
@@ -64,11 +64,11 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public
void
testGetAgregatedComments
()
throws
Exception
{
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Conteneta 1"
,
new
Point2D
.
Double
(
0
,
1
),
alias
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetb 2"
,
new
Point2D
.
Double
(
0
,
2
),
alias
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 3"
,
new
Point2D
.
Double
(
0
,
3
),
alias2
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 4"
,
new
Point2D
.
Double
(
0
,
4
),
null
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 5"
,
new
Point2D
.
Double
(
0
,
5
),
null
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Conteneta 1"
,
new
Point2D
.
Double
(
0
,
1
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetb 2"
,
new
Point2D
.
Double
(
0
,
2
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 3"
,
new
Point2D
.
Double
(
0
,
3
),
alias2
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 4"
,
new
Point2D
.
Double
(
0
,
4
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 5"
,
new
Point2D
.
Double
(
0
,
5
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
CommentService
service
=
new
CommentService
(
null
,
null
,
null
,
null
);
service
.
setCommentDao
(
commentDao
);
List
<
List
<
Comment
>>
comments
=
service
.
getAgregatedComments
(
model
,
null
);
...
...
@@ -89,7 +89,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public
void
testAddComment
()
throws
Exception
{
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
null
,
false
,
model
);
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
@@ -99,7 +99,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public
void
testAddCommentForReaction
()
throws
Exception
{
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
model
.
getReactions
().
iterator
().
next
(),
false
,
model
);
model
.
getReactions
().
iterator
().
next
(),
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
@@ -109,7 +109,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public
void
testAddCommentForAlias
()
throws
Exception
{
Element
alias
=
model
.
getElementByElementId
(
"sa1"
);
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
alias
,
false
,
model
);
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
web/src/test/java/lcsb/mapviewer/web/CommentControllerIntegrationTest.java
View file @
ff285a55
...
...
@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import
com.google.gson.JsonParser
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.Comment
;
import
lcsb.mapviewer.model.map.model.ModelData
;
...
...
@@ -40,6 +41,8 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@Rollback
public
class
CommentControllerIntegrationTest
extends
ControllerIntegrationTest
{
Logger
logger
=
LogManager
.
getLogger
();
private
static
final
String
TEST_PROJECT
=
"test_project"
;
private
static
final
String
TEST_USER_PASSWORD
=
"test_user_pass"
;
private
static
final
String
TEST_USER_LOGIN
=
"test_user"
;
...
...
@@ -47,10 +50,10 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
private
static
final
String
TEST_CURATOR_LOGIN
=
"test_curator"
;
private
static
final
String
TEST_ADMIN_PASSWORD
=
"test_admin"
;
private
static
final
String
TEST_ADMIN_LOGIN
=
"test_admin"
;
Logger
logger
=
LogManager
.
getLogger
();
private
ModelData
map
;
private
Reaction
reaction
;
private
Element
element
;
private
Project
project
;
@Autowired
private
CommentDao
commentDao
;
...
...
@@ -63,7 +66,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Before
public
void
setup
()
{
Project
project
=
createProject
(
TEST_PROJECT
);
project
=
createProject
(
TEST_PROJECT
);
project
.
setOwner
(
userService
.
getUserByLogin
(
BUILT_IN_TEST_ADMIN_LOGIN
));
map
=
project
.
getModels
().
iterator
().
next
();
reaction
=
map
.
getReactions
().
iterator
().
next
();
...
...
@@ -135,14 +138,14 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
}
private
void
createComments
()
{
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
comment
=
createComment
();
comment
=
createComment
(
map
);
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
comment
=
createComment
();
comment
=
createComment
(
map
);
comment
.
setDeleted
(
true
);
commentDao
.
add
(
comment
);
}
...
...
@@ -176,7 +179,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
comment
.
setName
(
"author name"
);
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
...
...
@@ -201,7 +204,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
comment
.
setName
(
"author name"
);
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
...
...
@@ -226,7 +229,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_CURATOR_LOGIN
,
TEST_CURATOR_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
comment
.
setName
(
"author name"
);
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
...
...
@@ -267,7 +270,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
...
...
@@ -286,7 +289,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_CURATOR_LOGIN
,
TEST_CURATOR_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
...
...
@@ -305,7 +308,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_CURATOR_LOGIN
,
TEST_CURATOR_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
...
...
@@ -318,12 +321,11 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public
void
testRemoveAsOwner
()
throws
Exception
{
User
user
=
create
Curato
r
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
User
user
=
create
Use
r
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
project
);
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
Comment
comment
=
createComment
();
comment
.
setUser
(
user
);
Comment
comment
=
createComment
(
map
,
user
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
...
...
@@ -338,7 +340,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public
void
testRemoveAsGuestAccount
()
throws
Exception
{
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
...
...
@@ -520,7 +522,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
...
...
@@ -543,7 +545,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
...
...
@@ -562,7 +564,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_CURATOR_LOGIN
,
TEST_CURATOR_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
...
...
@@ -585,7 +587,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
...
...
@@ -599,7 +601,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public
void
testAddElementCommentAsUserWithAccess
()
throws
Exception
{
createUser
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
map
.
getProject
());
User
user
=
createUser
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
map
.
getProject
());
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
...
...
@@ -621,6 +623,36 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.
andExpect
(
status
().
is2xxSuccessful
());
assertEquals
(
1
,
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
size
());
Comment
comment
=
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
get
(
0
);
assertEquals
(
"Owner of the comment wasn't set properly"
,
user
,
comment
.
getUser
());
}
@Test
public
void
testAddElementCommentAsAnonymous
()
throws
Exception
{
String
body
=
EntityUtils
.
toString
(
new
UrlEncodedFormEntity
(
Arrays
.
asList
(
new
BasicNameValuePair
(
"name"
,
"test_user"
),
new
BasicNameValuePair
(
"email"
,
"a@a.lu"
),
new
BasicNameValuePair
(
"content"
,
"tes content"
),
new
BasicNameValuePair
(
"pinned"
,
"true"
),
new
BasicNameValuePair
(
"coordinates"
,
"10,2"
),
new
BasicNameValuePair
(
"modelId"
,
map
.
getId
().
toString
()))));
userService
.
grantUserPrivilege
(
userService
.
getUserByLogin
(
Configuration
.
ANONYMOUS_LOGIN
),
PrivilegeType
.
READ_PROJECT
,
TEST_PROJECT
);
RequestBuilder
request
=
post
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/bioEntities/elements/"
+
element
.
getId
())
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
content
(
body
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
());
assertEquals
(
1
,
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
size
());
Comment
comment
=
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
get
(
0
);
assertNull
(
"Owner of the comment wasn't set properly"
,
comment
.
getUser
());
}
@Test
...
...
@@ -842,22 +874,15 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.
andExpect
(
status
().
isNotFound
());
}
private
Comment
createComment
()
{
Comment
comment
=
new
Comment
();
comment
.
setModel
(
map
);
comment
.
setCoordinates
(
new
Point2D
.
Double
(
10
,
20
));
return
comment
;
}
private
Comment
createReactionComment
()
{
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
comment
.
setTableName
(
reaction
.
getClass
());
comment
.
setTableId
(
reaction
.
getId
());
return
comment
;
}
private
Comment
createElementComment
()
{
Comment
comment
=
createComment
();
Comment
comment
=
createComment
(
map
);
comment
.
setTableName
(
element
.
getClass
());
comment
.
setTableId
(
element
.
getId
());
return
comment
;
...
...
web/src/test/java/lcsb/mapviewer/web/CommentControllerIntegrationTestWithoutTransaction.java
View file @
ff285a55
package
lcsb.mapviewer.web
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
delete
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.util.Arrays
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.*
;
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.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.model.map.Comment
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@Rollback
public
class
CommentControllerIntegrationTestWithoutTransaction
extends
ControllerIntegrationTest
{
Logger
logger
=
LogManager
.
getLogger
();
@Autowired
private
IUserService
userService
;
@Before
public
void
setup
()
{
}
...
...
@@ -34,4 +51,17 @@ public class CommentControllerIntegrationTestWithoutTransaction extends Controll
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is4xxClientError
());
}
@Test
public
void
testRemoveCommentAsUserWithAccess
()
throws
Exception
{
User
user
=
userService
.
getUserByLogin
(
Configuration
.
ANONYMOUS_LOGIN
);
Comment
comment
=
createCommentInSeparateThread
(
getBuildInModel
(),
user
);
RequestBuilder
request
=
delete
(
"/projects/"
+
BUILT_IN_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
());
}
}
web/src/test/java/lcsb/mapviewer/web/ControllerIntegrationTest.java
View file @
ff285a55
...
...
@@ -31,6 +31,7 @@ import lcsb.mapviewer.model.Project;
import
lcsb.mapviewer.model.ProjectStatus
;
import
lcsb.mapviewer.model.cache.UploadedFileEntry
;
import
lcsb.mapviewer.model.graphics.PolylineData
;
import
lcsb.mapviewer.model.map.Comment
;
import
lcsb.mapviewer.model.map.layout.ColorSchemaType
;
import
lcsb.mapviewer.model.map.layout.Layout
;
import
lcsb.mapviewer.model.map.model.ModelData
;
...
...
@@ -43,7 +44,7 @@ import lcsb.mapviewer.model.user.User;
import
lcsb.mapviewer.persist.DbUtils
;
import
lcsb.mapviewer.persist.dao.ProjectDao
;
import
lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao
;
import
lcsb.mapviewer.persist.dao.map.
LayoutDao
;
import
lcsb.mapviewer.persist.dao.map.
*
;
import
lcsb.mapviewer.persist.dao.user.UserDao
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
import
lcsb.mapviewer.web.config.SpringWebConfig
;
...
...
@@ -55,6 +56,8 @@ abstract public class ControllerIntegrationTest {
protected
static
final
String
BUILT_IN_TEST_ADMIN_PASSWORD
=
"admin"
;
protected
static
final
String
BUILT_IN_TEST_ADMIN_LOGIN
=
"admin"
;
protected
static
final
String
BUILT_IN_PROJECT
=
"empty"
;
@Rule
public
UnitTestFailedWatcher
unitTestFailedWatcher
=
new
UnitTestFailedWatcher
();
protected
MockMvc
mockMvc
;
...
...
@@ -66,10 +69,19 @@ abstract public class ControllerIntegrationTest {
private
IUserService
userService
;
@Autowired
private
ProjectDao
projectDao
;
@Autowired
private
ModelDao
modelDao
;
@Autowired
private
CommentDao
commentDao
;
@Autowired
private
UserDao
userDao
;
@Autowired
private
PasswordEncoder
passwordEncoder
;
@Autowired
private
UploadedFileEntryDao
fileDao
;
...
...
@@ -325,4 +337,30 @@ abstract public class ControllerIntegrationTest {
});
}
protected
Comment
createCommentInSeparateThread
(
ModelData
model
,
User
owner
)
throws
Exception
{
return
callInSeparateThread
(()
->
{
Comment
comment
=
createComment
(
model
,
owner
);
commentDao
.
add
(
comment
);
return
comment
;
});
}
protected
ModelData
getBuildInModel
()
throws
Exception
{
return
callInSeparateThread
(()
->
{
return
modelDao
.
getLastModelForProjectIdentifier
(
BUILT_IN_PROJECT
,
true
);
});
}
protected
Comment
createComment
(
ModelData
map
)
{
return
createComment
(
map
,
null
);
}
protected
Comment
createComment
(
ModelData
map
,
User
owner
)
{
Comment
comment
=
new
Comment
();
comment
.
setModel
(
map
);
comment
.
setUser
(
owner
);
comment
.
setCoordinates
(
new
Point2D
.
Double
(
10
,
20
));
return
comment
;
}