Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DBRepo
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAIR Data Austria DB Repository
DBRepo
Commits
d3ab82e0
Verified
Commit
d3ab82e0
authored
1 year ago
by
Martin Weise
Browse files
Options
Downloads
Patches
Plain Diff
Fixed test
parent
a291ecaa
No related branches found
No related tags found
3 merge requests
!256
Master
,
!254
Master
,
!253
Dev
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/StoreEndpointUnitTest.java
+31
-29
31 additions, 29 deletions
.../test/java/at/tuwien/endpoints/StoreEndpointUnitTest.java
with
31 additions
and
29 deletions
dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/StoreEndpointUnitTest.java
+
31
−
29
View file @
d3ab82e0
...
@@ -72,8 +72,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -72,8 +72,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithAnonymousUser
@WithAnonymousUser
public
void
findAll_publicAnonymous_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
public
void
findAll_publicAnonymous_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
ImageNotSupportedException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
/* test */
/* test */
findAll_generic
(
DATABASE_3_ID
,
DATABASE_3
,
null
);
findAll_generic
(
DATABASE_3_ID
,
DATABASE_3
,
null
);
...
@@ -81,8 +82,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -81,8 +82,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithMockUser
(
username
=
USER_1_USERNAME
)
@WithMockUser
(
username
=
USER_1_USERNAME
)
public
void
findAll_noRole_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
public
void
findAll_noRole_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
ImageNotSupportedException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
/* test */
/* test */
findAll_generic
(
DATABASE_1_ID
,
DATABASE_1
,
USER_1_PRINCIPAL
);
findAll_generic
(
DATABASE_1_ID
,
DATABASE_1
,
USER_1_PRINCIPAL
);
...
@@ -90,8 +92,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -90,8 +92,9 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
{
"list-queries"
})
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
{
"list-queries"
})
public
void
findAll_hasRole_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
public
void
findAll_hasRole_succeeds
()
throws
QueryStoreException
,
DatabaseNotFoundException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
ImageNotSupportedException
,
ContainerNotFoundException
,
DatabaseConnectionException
,
TableMalformedException
,
UserNotFoundException
,
NotAllowedException
,
AccessDeniedException
{
/* test */
/* test */
findAll_generic
(
DATABASE_1_ID
,
DATABASE_1
,
USER_1_PRINCIPAL
);
findAll_generic
(
DATABASE_1_ID
,
DATABASE_1
,
USER_1_PRINCIPAL
);
...
@@ -229,15 +232,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -229,15 +232,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
"persist-query"
)
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
"persist-query"
)
public
void
persist_ownRead_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
public
void
persist_ownRead_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
NotAllowedException
,
DatabaseConnectionException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
NotAllowedException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
ImageNotSupportedException
,
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
/* mock */
/* mock */
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
.
thenReturn
(
Optional
.
of
(
USER_1
));
.
thenReturn
(
Optional
.
of
(
USER_1
));
/* test */
/* test */
final
QueryDto
response
=
persist_generic
(
DATABASE_1_ID
,
DATABASE_1
,
QUERY_1_ID
,
QUERY_1
,
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_READ_ACCESS
);
final
QueryDto
response
=
persist_generic
(
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_READ_ACCESS
);
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
}
}
...
@@ -245,15 +248,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -245,15 +248,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
"persist-query"
)
@WithMockUser
(
username
=
USER_1_USERNAME
,
authorities
=
"persist-query"
)
public
void
persist_ownWriteOwn_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
public
void
persist_ownWriteOwn_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
NotAllowedException
,
DatabaseConnectionException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
NotAllowedException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
ImageNotSupportedException
,
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
/* mock */
/* mock */
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
.
thenReturn
(
Optional
.
of
(
USER_1
));
.
thenReturn
(
Optional
.
of
(
USER_1
));
/* test */
/* test */
final
QueryDto
response
=
persist_generic
(
DATABASE_1_ID
,
DATABASE_1
,
QUERY_1_ID
,
QUERY_1
,
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_WRITE_OWN_ACCESS
);
final
QueryDto
response
=
persist_generic
(
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_WRITE_OWN_ACCESS
);
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
}
}
...
@@ -269,7 +272,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -269,7 +272,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
.
thenReturn
(
Optional
.
of
(
USER_1
));
.
thenReturn
(
Optional
.
of
(
USER_1
));
/* test */
/* test */
final
QueryDto
response
=
persist_generic
(
DATABASE_1_ID
,
DATABASE_1
,
QUERY_1_ID
,
QUERY_1
,
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_WRITE_ALL_ACCESS
);
final
QueryDto
response
=
persist_generic
(
USER_1_ID
,
USER_1_PRINCIPAL
,
DATABASE_1_USER_1_WRITE_ALL_ACCESS
);
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_ID
,
response
.
getId
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
assertEquals
(
QUERY_1_STATEMENT
,
response
.
getQuery
());
}
}
...
@@ -277,15 +280,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -277,15 +280,15 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
@Test
@Test
@WithMockUser
(
username
=
USER_2_USERNAME
,
authorities
=
"persist-query"
)
@WithMockUser
(
username
=
USER_2_USERNAME
,
authorities
=
"persist-query"
)
public
void
persist_foreignWriteAll_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
public
void
persist_foreignWriteAll_succeeds
()
throws
UserNotFoundException
,
QueryStoreException
,
NotAllowedException
,
DatabaseConnectionException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
NotAllowedException
,
QueryNotFoundException
,
DatabaseNotFoundException
,
ImageNotSupportedException
,
ImageNotSupportedException
,
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
/* mock */
/* mock */
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
when
(
userRepository
.
findByUsername
(
USER_1_USERNAME
))
.
thenReturn
(
Optional
.
of
(
USER_1
));
.
thenReturn
(
Optional
.
of
(
USER_1
));
/* test */
/* test */
persist_generic
(
DATABASE_1_ID
,
DATABASE_1
,
QUERY_1_ID
,
QUERY_1
,
USER_2_ID
,
USER_2_PRINCIPAL
,
DATABASE_1_USER_2_WRITE_ALL_ACCESS
);
persist_generic
(
USER_2_ID
,
USER_2_PRINCIPAL
,
DATABASE_1_USER_2_WRITE_ALL_ACCESS
);
}
}
...
@@ -293,8 +296,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -293,8 +296,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
/* ## GENERIC TEST CASES ## */
/* ## GENERIC TEST CASES ## */
/* ################################################################################################### */
/* ################################################################################################### */
protected
QueryDto
persist_generic
(
Long
databaseId
,
Database
database
,
Long
queryId
,
Query
query
,
protected
QueryDto
persist_generic
(
UUID
userId
,
Principal
principal
,
DatabaseAccess
access
)
UUID
userId
,
Principal
principal
,
DatabaseAccess
access
)
throws
DatabaseNotFoundException
,
UserNotFoundException
,
QueryStoreException
,
QueryNotFoundException
,
throws
DatabaseNotFoundException
,
UserNotFoundException
,
QueryStoreException
,
QueryNotFoundException
,
ImageNotSupportedException
,
NotAllowedException
,
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
ImageNotSupportedException
,
NotAllowedException
,
AccessDeniedException
,
IdentifierAlreadyPublishedException
{
final
QueryPersistDto
request
=
QueryPersistDto
.
builder
()
final
QueryPersistDto
request
=
QueryPersistDto
.
builder
()
...
@@ -302,25 +304,25 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
...
@@ -302,25 +304,25 @@ public class StoreEndpointUnitTest extends BaseUnitTest {
.
build
();
.
build
();
/* mock */
/* mock */
when
(
databaseService
.
find
(
databaseId
))
when
(
databaseService
.
find
(
DATABASE_1_ID
))
.
thenReturn
(
database
);
.
thenReturn
(
DATABASE_1
);
when
(
storeService
.
findOne
(
databaseId
,
queryId
,
principal
))
when
(
storeService
.
findOne
(
DATABASE_1_ID
,
QUERY_1_ID
,
principal
))
.
thenReturn
(
query
);
.
thenReturn
(
QUERY_1
);
doReturn
(
query
)
doReturn
(
QUERY_1
)
.
when
(
storeService
)
.
when
(
storeService
)
.
persist
(
databaseId
,
queryId
,
request
);
.
persist
(
DATABASE_1_ID
,
QUERY_1_ID
,
request
);
if
(
access
!=
null
)
{
if
(
access
!=
null
)
{
log
.
trace
(
"mock access for database with id {} and user id {}"
,
databaseId
,
userId
);
log
.
trace
(
"mock access for database with id {} and user id {}"
,
DATABASE_1_ID
,
userId
);
when
(
accessService
.
find
(
databaseId
,
userId
))
when
(
accessService
.
find
(
DATABASE_1_ID
,
userId
))
.
thenReturn
(
access
);
.
thenReturn
(
access
);
}
else
{
}
else
{
log
.
trace
(
"mock no access for database with id {} and user id {}"
,
databaseId
,
userId
);
log
.
trace
(
"mock no access for database with id {} and user id {}"
,
DATABASE_1_ID
,
userId
);
when
(
accessService
.
find
(
databaseId
,
userId
))
when
(
accessService
.
find
(
DATABASE_1_ID
,
userId
))
.
thenThrow
(
NotAllowedException
.
class
);
.
thenThrow
(
NotAllowedException
.
class
);
}
}
/* test */
/* test */
final
ResponseEntity
<
QueryDto
>
response
=
storeEndpoint
.
persist
(
databaseId
,
queryId
,
request
,
principal
);
final
ResponseEntity
<
QueryDto
>
response
=
storeEndpoint
.
persist
(
DATABASE_1_ID
,
QUERY_1_ID
,
request
,
principal
);
assertEquals
(
HttpStatus
.
ACCEPTED
,
response
.
getStatusCode
());
assertEquals
(
HttpStatus
.
ACCEPTED
,
response
.
getStatusCode
());
assertNotNull
(
response
.
getBody
());
assertNotNull
(
response
.
getBody
());
return
response
.
getBody
();
return
response
.
getBody
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment