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
Merge requests
!162
Something went wrong on our end
Resolve "Improve Semantic Service handling"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Improve Semantic Service handling"
318-improve-semantic-service-handling
into
dev
Overview
0
Commits
20
Pipelines
0
Changes
5
Merged
Resolve "Improve Semantic Service handling"
Martin Weise
requested to merge
318-improve-semantic-service-handling
into
dev
May 30, 2023
Overview
0
Commits
20
Pipelines
0
Changes
5
Closes #318
0
0
Merge request reports
Viewing commit
95ee5b92
Prev
Next
Show latest version
5 files
+
79
−
158
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Unverified
95ee5b92
Fixed some tests
· 95ee5b92
Martin Weise
authored
May 31, 2023
dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointIntegrationTest.java deleted
100644 → 0
+
0
−
132
View file @ d83bd2e0
package
at.tuwien.endpoint
;
import
at.tuwien.BaseUnitTest
;
import
at.tuwien.api.container.*
;
import
at.tuwien.config.DockerConfig
;
import
at.tuwien.config.ReadyConfig
;
import
at.tuwien.endpoints.ContainerEndpoint
;
import
at.tuwien.entities.container.Container
;
import
at.tuwien.exception.*
;
import
at.tuwien.repository.jpa.ContainerRepository
;
import
at.tuwien.repository.jpa.ImageRepository
;
import
at.tuwien.repository.jpa.RealmRepository
;
import
at.tuwien.repository.jpa.UserRepository
;
import
at.tuwien.service.impl.ContainerServiceImpl
;
import
lombok.extern.log4j.Log4j2
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.test.context.support.WithAnonymousUser
;
import
org.springframework.security.test.context.support.WithMockUser
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
java.security.Principal
;
import
java.util.List
;
import
java.util.Optional
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
mockito
.
Mockito
.
doNothing
;
import
static
org
.
mockito
.
Mockito
.
when
;
@Log4j2
@ExtendWith
(
SpringExtension
.
class
)
@SpringBootTest
public
class
ContainerEndpointIntegrationTest
extends
BaseUnitTest
{
@MockBean
private
ReadyConfig
readyConfig
;
@Autowired
private
RealmRepository
realmRepository
;
@Autowired
private
ImageRepository
imageRepository
;
@Autowired
private
ContainerRepository
containerRepository
;
@Autowired
private
UserRepository
userRepository
;
@Autowired
private
ContainerEndpoint
containerEndpoint
;
@BeforeEach
public
void
beforeEach
()
{
afterEach
();
/* networks */
DockerConfig
.
createAllNetworks
();
/* metadata database */
realmRepository
.
save
(
REALM_DBREPO
);
imageRepository
.
save
(
IMAGE_1
);
userRepository
.
save
(
USER_1
);
userRepository
.
save
(
USER_2
);
userRepository
.
save
(
USER_3
);
}
@AfterEach
public
void
afterEach
()
{
DockerConfig
.
removeAllContainers
();
DockerConfig
.
removeAllNetworks
();
}
@Test
@WithAnonymousUser
public
void
findAll_anonymousNoLimit_succeeds
()
throws
InterruptedException
{
/* mock */
DockerConfig
.
createContainer
(
null
,
CONTAINER_1_SIMPLE
,
CONTAINER_1_ENV
);
DockerConfig
.
startContainer
(
CONTAINER_1_SIMPLE
);
containerRepository
.
save
(
CONTAINER_1_SIMPLE
);
/* test */
final
ResponseEntity
<
List
<
ContainerBriefDto
>>
response
=
containerEndpoint
.
findAll
(
null
,
null
);
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertNotNull
(
response
.
getBody
());
final
List
<
ContainerBriefDto
>
body
=
response
.
getBody
();
assertEquals
(
1
,
body
.
size
());
final
ContainerBriefDto
container0
=
body
.
get
(
0
);
assertTrue
(
container0
.
getRunning
());
}
@Test
@WithAnonymousUser
public
void
findById_anonymousNotRunning_succeeds
()
throws
DockerClientException
,
ContainerNotFoundException
{
/* mock */
DockerConfig
.
createContainer
(
null
,
CONTAINER_1_SIMPLE
,
CONTAINER_1_ENV
);
containerRepository
.
save
(
CONTAINER_1_SIMPLE
);
/* test */
final
ResponseEntity
<
ContainerDto
>
response
=
containerEndpoint
.
findById
(
CONTAINER_1_ID
);
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertNotNull
(
response
.
getBody
());
final
ContainerDto
body
=
response
.
getBody
();
assertFalse
(
body
.
getRunning
());
assertEquals
(
ContainerStateDto
.
EXITED
,
body
.
getState
());
}
@Test
@WithMockUser
(
username
=
USER_3_USERNAME
,
authorities
=
{
"modify-container-state"
})
public
void
modify_foreign_fails
()
{
final
ContainerChangeDto
request
=
ContainerChangeDto
.
builder
()
.
action
(
ContainerActionTypeDto
.
STOP
)
.
build
();
/* mock */
containerRepository
.
save
(
CONTAINER_1_SIMPLE
);
/* test */
assertThrows
(
NotAllowedException
.
class
,
()
->
{
containerEndpoint
.
modify
(
CONTAINER_1_ID
,
request
,
USER_3_PRINCIPAL
);
});
}
}
Loading