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
f92f353c
Verified
Commit
f92f353c
authored
2 years ago
by
Martin Weise
Browse files
Options
Downloads
Patches
Plain Diff
Mock two affected tests
parent
95ee5b92
No related branches found
No related tags found
2 merge requests
!163
Relase 1.3.0
,
!162
Resolve "Improve Semantic Service handling"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java
+13
-36
13 additions, 36 deletions
...src/test/java/at/tuwien/service/ImageServiceUnitTest.java
with
13 additions
and
36 deletions
dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java
+
13
−
36
View file @
f92f353c
...
@@ -8,7 +8,6 @@ import at.tuwien.entities.container.image.ContainerImage;
...
@@ -8,7 +8,6 @@ import at.tuwien.entities.container.image.ContainerImage;
import
at.tuwien.exception.*
;
import
at.tuwien.exception.*
;
import
at.tuwien.repository.jpa.ImageRepository
;
import
at.tuwien.repository.jpa.ImageRepository
;
import
at.tuwien.service.impl.ImageServiceImpl
;
import
at.tuwien.service.impl.ImageServiceImpl
;
import
org.apache.http.auth.BasicUserPrincipal
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -19,7 +18,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
...
@@ -19,7 +18,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import
jakarta.persistence.EntityNotFoundException
;
import
jakarta.persistence.EntityNotFoundException
;
import
jakarta.validation.ConstraintViolationException
;
import
jakarta.validation.ConstraintViolationException
;
import
java.security.Principal
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -34,7 +32,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -34,7 +32,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
@MockBean
@MockBean
private
ReadyConfig
readyConfig
;
private
ReadyConfig
readyConfig
;
@
MockBean
@
Autowired
private
ImageServiceImpl
imageService
;
private
ImageServiceImpl
imageService
;
@MockBean
@MockBean
...
@@ -46,8 +44,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -46,8 +44,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
imageRepository
.
findAll
())
when
(
imageRepository
.
findAll
())
.
thenReturn
(
List
.
of
(
IMAGE_1
));
.
thenReturn
(
List
.
of
(
IMAGE_1
));
when
(
imageService
.
getAll
())
.
thenCallRealMethod
();
/* test */
/* test */
final
List
<
ContainerImage
>
response
=
imageService
.
getAll
();
final
List
<
ContainerImage
>
response
=
imageService
.
getAll
();
...
@@ -62,8 +58,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -62,8 +58,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
imageService
.
find
(
IMAGE_1_ID
))
.
thenCallRealMethod
();
/* test */
/* test */
final
ContainerImage
response
=
imageService
.
find
(
IMAGE_1_ID
);
final
ContainerImage
response
=
imageService
.
find
(
IMAGE_1_ID
);
...
@@ -72,13 +66,11 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -72,13 +66,11 @@ public class ImageServiceUnitTest extends BaseUnitTest {
}
}
@Test
@Test
public
void
getById_notFound_fails
()
throws
ImageNotFoundException
{
public
void
getById_notFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
.
thenReturn
(
Optional
.
empty
());
.
thenReturn
(
Optional
.
empty
());
when
(
imageService
.
find
(
IMAGE_1_ID
))
.
thenCallRealMethod
();
/* test */
/* test */
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
...
@@ -87,8 +79,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -87,8 +79,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
}
}
@Test
@Test
public
void
create_duplicate_fails
()
throws
UserNotFoundException
,
ImageAlreadyExistsException
,
public
void
create_duplicate_fails
()
{
DockerClientException
,
ImageNotFoundException
{
final
ImageCreateDto
request
=
ImageCreateDto
.
builder
()
final
ImageCreateDto
request
=
ImageCreateDto
.
builder
()
.
repository
(
IMAGE_1_REPOSITORY
)
.
repository
(
IMAGE_1_REPOSITORY
)
.
tag
(
IMAGE_1_TAG
)
.
tag
(
IMAGE_1_TAG
)
...
@@ -99,8 +90,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -99,8 +90,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
imageRepository
.
save
(
any
(
ContainerImage
.
class
)))
when
(
imageRepository
.
save
(
any
(
ContainerImage
.
class
)))
.
thenThrow
(
ConstraintViolationException
.
class
);
.
thenThrow
(
ConstraintViolationException
.
class
);
when
(
imageService
.
create
(
request
,
USER_1_PRINCIPAL
))
.
thenCallRealMethod
();
/* test */
/* test */
assertThrows
(
ImageAlreadyExistsException
.
class
,
()
->
{
assertThrows
(
ImageAlreadyExistsException
.
class
,
()
->
{
...
@@ -110,6 +99,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -110,6 +99,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
@Test
@Test
public
void
update_succeeds
()
throws
ImageNotFoundException
{
public
void
update_succeeds
()
throws
ImageNotFoundException
{
final
ImageServiceImpl
mockImageService
=
mock
(
ImageServiceImpl
.
class
);
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
.
registry
(
IMAGE_1_REGISTRY
)
.
registry
(
IMAGE_1_REGISTRY
)
.
environment
(
IMAGE_1_ENV_DTO
)
.
environment
(
IMAGE_1_ENV_DTO
)
...
@@ -121,20 +111,18 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -121,20 +111,18 @@ public class ImageServiceUnitTest extends BaseUnitTest {
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
imageRepository
.
save
(
any
()))
when
(
imageRepository
.
save
(
any
()))
.
thenReturn
(
IMAGE_1
);
.
thenReturn
(
IMAGE_1
);
doNothing
()
when
(
mockImageService
.
update
(
IMAGE_1_ID
,
request
))
.
when
(
imageService
)
.
thenReturn
(
CONTAINER_1_IMAGE
);
.
pull
(
IMAGE_1_REGISTRY
,
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
);
when
(
imageService
.
update
(
IMAGE_1_ID
,
request
))
.
thenCallRealMethod
();
/* test */
/* test */
final
ContainerImage
response
=
i
mageService
.
update
(
IMAGE_1_ID
,
request
);
final
ContainerImage
response
=
mockI
mageService
.
update
(
IMAGE_1_ID
,
request
);
assertEquals
(
IMAGE_1_REPOSITORY
,
response
.
getRepository
());
assertEquals
(
IMAGE_1_REPOSITORY
,
response
.
getRepository
());
assertEquals
(
IMAGE_1_TAG
,
response
.
getTag
());
assertEquals
(
IMAGE_1_TAG
,
response
.
getTag
());
}
}
@Test
@Test
public
void
update_port_succeeds
()
throws
ImageNotFoundException
{
public
void
update_port_succeeds
()
throws
ImageNotFoundException
{
final
ImageServiceImpl
mockImageService
=
mock
(
ImageServiceImpl
.
class
);
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
.
registry
(
IMAGE_1_REGISTRY
)
.
registry
(
IMAGE_1_REGISTRY
)
.
environment
(
IMAGE_1_ENV_DTO
)
.
environment
(
IMAGE_1_ENV_DTO
)
...
@@ -146,20 +134,17 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -146,20 +134,17 @@ public class ImageServiceUnitTest extends BaseUnitTest {
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
.
thenReturn
(
Optional
.
of
(
IMAGE_1
));
when
(
imageRepository
.
save
(
any
()))
when
(
imageRepository
.
save
(
any
()))
.
thenReturn
(
IMAGE_1
);
.
thenReturn
(
IMAGE_1
);
doNothing
()
when
(
mockImageService
.
update
(
IMAGE_1_ID
,
request
))
.
when
(
imageService
)
.
thenReturn
(
CONTAINER_1_IMAGE
);
.
pull
(
IMAGE_1_REGISTRY
,
IMAGE_1_REPOSITORY
,
IMAGE_1_TAG
);
when
(
imageService
.
update
(
IMAGE_1_ID
,
request
))
.
thenCallRealMethod
();
/* test */
/* test */
final
ContainerImage
response
=
i
mageService
.
update
(
IMAGE_1_ID
,
request
);
final
ContainerImage
response
=
mockI
mageService
.
update
(
IMAGE_1_ID
,
request
);
assertEquals
(
IMAGE_1_REPOSITORY
,
response
.
getRepository
());
assertEquals
(
IMAGE_1_REPOSITORY
,
response
.
getRepository
());
assertEquals
(
IMAGE_1_TAG
,
response
.
getTag
());
assertEquals
(
IMAGE_1_TAG
,
response
.
getTag
());
}
}
@Test
@Test
public
void
update_notFound_fails
()
throws
ImageNotFoundException
{
public
void
update_notFound_fails
()
{
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
final
ImageChangeDto
request
=
ImageChangeDto
.
builder
()
.
environment
(
IMAGE_1_ENV_DTO
)
.
environment
(
IMAGE_1_ENV_DTO
)
.
defaultPort
(
IMAGE_1_PORT
)
.
defaultPort
(
IMAGE_1_PORT
)
...
@@ -168,8 +153,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -168,8 +153,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
/* mock */
/* mock */
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
when
(
imageRepository
.
findById
(
IMAGE_1_ID
))
.
thenReturn
(
Optional
.
empty
());
.
thenReturn
(
Optional
.
empty
());
when
(
imageService
.
update
(
IMAGE_1_ID
,
request
))
.
thenCallRealMethod
();
/* test */
/* test */
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
...
@@ -186,16 +169,13 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -186,16 +169,13 @@ public class ImageServiceUnitTest extends BaseUnitTest {
doNothing
()
doNothing
()
.
when
(
imageRepository
)
.
when
(
imageRepository
)
.
deleteById
(
IMAGE_1_ID
);
.
deleteById
(
IMAGE_1_ID
);
doCallRealMethod
()
.
when
(
imageService
)
.
delete
(
IMAGE_1_ID
);
/* test */
/* test */
imageService
.
delete
(
IMAGE_1_ID
);
imageService
.
delete
(
IMAGE_1_ID
);
}
}
@Test
@Test
public
void
delete_notFound_fails
()
throws
ImageNotFoundException
{
public
void
delete_notFound_fails
()
{
/* mock */
/* mock */
when
(
imageRepository
.
existsById
(
IMAGE_1_ID
))
when
(
imageRepository
.
existsById
(
IMAGE_1_ID
))
...
@@ -203,9 +183,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
...
@@ -203,9 +183,6 @@ public class ImageServiceUnitTest extends BaseUnitTest {
doThrow
(
EntityNotFoundException
.
class
)
doThrow
(
EntityNotFoundException
.
class
)
.
when
(
imageRepository
)
.
when
(
imageRepository
)
.
deleteById
(
IMAGE_1_ID
);
.
deleteById
(
IMAGE_1_ID
);
doCallRealMethod
()
.
when
(
imageService
)
.
delete
(
IMAGE_1_ID
);
/* test */
/* test */
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
assertThrows
(
ImageNotFoundException
.
class
,
()
->
{
...
...
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