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
51ca6c6d
Unverified
Commit
51ca6c6d
authored
Nov 17, 2022
by
Martin Weise
Browse files
Options
Downloads
Patches
Plain Diff
Resort to mocking image Repository
parent
95133f59
No related branches found
No related tags found
1 merge request
!106
Dev
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java
+49
-7
49 additions, 7 deletions
...va/at/tuwien/service/ContainerServiceIntegrationTest.java
with
49 additions
and
7 deletions
fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java
+
49
−
7
View file @
51ca6c6d
...
@@ -46,11 +46,11 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -46,11 +46,11 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
@MockBean
@MockBean
private
ContainerRepository
containerRepository
;
private
ContainerRepository
containerRepository
;
@
Autowired
@
MockBean
private
DockerClient
dockerClient
;
private
ImageRepository
imageRepository
;
@Autowired
@Autowired
private
HostConfig
hostConfig
;
private
DockerClient
dockerClient
;
@Autowired
@Autowired
private
ContainerService
containerService
;
private
ContainerService
containerService
;
...
@@ -58,9 +58,6 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -58,9 +58,6 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
@Autowired
@Autowired
private
DockerUtil
dockerUtil
;
private
DockerUtil
dockerUtil
;
@Autowired
private
ImageRepository
imageRepository
;
@Autowired
@Autowired
private
UserRepository
userRepository
;
private
UserRepository
userRepository
;
...
@@ -85,7 +82,6 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -85,7 +82,6 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
/* mock data */
/* mock data */
userRepository
.
save
(
USER_1
);
userRepository
.
save
(
USER_1
);
imageRepository
.
save
(
IMAGE_1
);
}
}
@AfterEach
@AfterEach
...
@@ -131,6 +127,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -131,6 +127,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
.
thenReturn
(
Optional
.
empty
());
.
thenReturn
(
Optional
.
empty
());
when
(
containerRepository
.
save
(
any
(
Container
.
class
)))
when
(
containerRepository
.
save
(
any
(
Container
.
class
)))
.
thenReturn
(
CONTAINER_1
);
.
thenReturn
(
CONTAINER_1
);
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
final
Container
container
=
containerService
.
create
(
request
,
principal
);
final
Container
container
=
containerService
.
create
(
request
,
principal
);
...
@@ -150,6 +148,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -150,6 +148,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
containerRepository
.
findByInternalName
(
CONTAINER_1_INTERNALNAME
))
when
(
containerRepository
.
findByInternalName
(
CONTAINER_1_INTERNALNAME
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
assertThrows
(
ContainerAlreadyExistsException
.
class
,
()
->
{
assertThrows
(
ContainerAlreadyExistsException
.
class
,
()
->
{
...
@@ -163,6 +163,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -163,6 +163,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
empty
());
.
thenReturn
(
Optional
.
empty
());
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
...
@@ -179,6 +181,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -179,6 +181,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
.
build
();
.
build
();
final
Principal
principal
=
new
BasicUserPrincipal
(
USER_1_USERNAME
);
final
Principal
principal
=
new
BasicUserPrincipal
(
USER_1_USERNAME
);
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
containerService
.
create
(
request
,
principal
);
containerService
.
create
(
request
,
principal
);
...
@@ -189,6 +195,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -189,6 +195,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
@Test
@Test
public
void
findById_notFound_fails
()
{
public
void
findById_notFound_fails
()
{
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
containerService
.
find
(
CONTAINER_1_ID
);
containerService
.
find
(
CONTAINER_1_ID
);
...
@@ -199,6 +209,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -199,6 +209,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_start_succeeds
()
throws
DockerClientException
,
ContainerNotFoundException
{
public
void
change_start_succeeds
()
throws
DockerClientException
,
ContainerNotFoundException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -211,6 +223,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -211,6 +223,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_stop_succeeds
()
throws
DockerClientException
,
InterruptedException
,
ContainerNotFoundException
{
public
void
change_stop_succeeds
()
throws
DockerClientException
,
InterruptedException
,
ContainerNotFoundException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -224,6 +238,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -224,6 +238,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_startSavedButNotFound_fails
()
{
public
void
change_startSavedButNotFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
...
@@ -237,6 +253,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -237,6 +253,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_removeSavedButNotFound_fails
()
{
public
void
change_removeSavedButNotFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
...
@@ -250,6 +268,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -250,6 +268,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
getAll_succeeds
()
{
public
void
getAll_succeeds
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findAll
())
when
(
containerRepository
.
findAll
())
.
thenReturn
(
List
.
of
(
CONTAINER_1
,
CONTAINER_2
));
.
thenReturn
(
List
.
of
(
CONTAINER_1
,
CONTAINER_2
));
...
@@ -262,6 +282,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -262,6 +282,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
remove_succeeds
()
throws
DockerClientException
,
ContainerStillRunningException
,
ContainerNotFoundException
{
public
void
remove_succeeds
()
throws
DockerClientException
,
ContainerStillRunningException
,
ContainerNotFoundException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -284,6 +306,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -284,6 +306,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
remove_stillRunning_fails
()
throws
InterruptedException
{
public
void
remove_stillRunning_fails
()
throws
InterruptedException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -299,6 +323,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -299,6 +323,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_alreadyRunning_fails
()
throws
InterruptedException
{
public
void
change_alreadyRunning_fails
()
throws
InterruptedException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -314,6 +340,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -314,6 +340,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_startNotFound_fails
()
{
public
void
change_startNotFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
empty
());
.
thenReturn
(
Optional
.
empty
());
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -328,6 +356,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -328,6 +356,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_alreadyStopped_fails
()
throws
InterruptedException
{
public
void
change_alreadyStopped_fails
()
throws
InterruptedException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -344,6 +374,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -344,6 +374,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_stopNeverStarted_fails
()
{
public
void
change_stopNeverStarted_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -358,6 +390,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -358,6 +390,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
change_stopSavedButNotFound_fails
()
{
public
void
change_stopSavedButNotFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
...
@@ -372,6 +406,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -372,6 +406,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
ContainerNotRunningException
{
ContainerNotRunningException
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
@@ -388,6 +424,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -388,6 +424,10 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
@Test
@Test
public
void
inspect_notFound_fails
()
{
public
void
inspect_notFound_fails
()
{
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
/* test */
/* test */
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
assertThrows
(
ContainerNotFoundException
.
class
,
()
->
{
containerService
.
inspect
(
CONTAINER_2_ID
);
containerService
.
inspect
(
CONTAINER_2_ID
);
...
@@ -398,6 +438,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
...
@@ -398,6 +438,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
public
void
inspect_notRunning_fails
()
{
public
void
inspect_notRunning_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findByRepositoryAndTag
(
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
when
(
containerRepository
.
findById
(
CONTAINER_1_ID
))
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
.
thenReturn
(
Optional
.
of
(
CONTAINER_1
));
dockerUtil
.
createContainer
(
CONTAINER_1
);
dockerUtil
.
createContainer
(
CONTAINER_1
);
...
...
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