Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Avatar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
Avatar
Commits
88c2ff1f
Commit
88c2ff1f
authored
Jul 07, 2020
by
Tim Coates (CPVV)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional unit tests
parent
909fb7d2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
1 deletion
+66
-1
src/test/java/au/com/tpic/avatar/services/AvatarServiceTest.java
...t/java/au/com/tpic/avatar/services/AvatarServiceTest.java
+15
-1
src/test/java/au/com/tpic/avatar/web/AvatarControllerTest.java
...est/java/au/com/tpic/avatar/web/AvatarControllerTest.java
+49
-0
src/test/resources/application-unit-test.yml
src/test/resources/application-unit-test.yml
+2
-0
src/test/resources/test-100.jpg
src/test/resources/test-100.jpg
+0
-0
src/test/resources/test.png
src/test/resources/test.png
+0
-0
No files found.
src/test/java/au/com/tpic/avatar/services/AvatarServiceTest.java
View file @
88c2ff1f
...
...
@@ -17,7 +17,7 @@ class AvatarServiceTest {
public
AvatarServiceTest
()
throws
IOException
{
AvatarServiceProperites
properties
=
new
AvatarServiceProperites
();
properties
.
setDirectory
(
Path
.
of
(
"
build"
,
"tmp
"
));
properties
.
setDirectory
(
Path
.
of
(
"
src"
,
"test"
,
"resources
"
));
this
.
avatarService
=
new
AvatarService
(
properties
);
}
...
...
@@ -35,4 +35,18 @@ class AvatarServiceTest {
assertThat
(
avatarService
.
getAvatar
(
"B725DDDD5F2F979522DCC55A05E"
,
"200"
)).
isEqualTo
(
expectedResponse
);
}
@Test
void
getAvatarFromDirectory
()
throws
IOException
{
byte
[]
expectedBody
=
getClass
().
getResourceAsStream
(
"/test.png"
).
readAllBytes
();
ResponseEntity
<
byte
[]>
expectedResponse
=
ResponseEntity
.
ok
().
contentType
(
MediaType
.
IMAGE_PNG
).
body
(
expectedBody
);
assertThat
(
avatarService
.
getAvatar
(
"098f6bcd4621d373cade4e832627b4f6.png"
,
"200"
)).
isEqualTo
(
expectedResponse
);
}
@Test
void
getResizedAvatarFromDirectory
()
throws
IOException
{
byte
[]
expectedBody
=
getClass
().
getResourceAsStream
(
"/test-100.jpg"
).
readAllBytes
();
ResponseEntity
<
byte
[]>
expectedResponse
=
ResponseEntity
.
ok
().
contentType
(
MediaType
.
IMAGE_JPEG
).
body
(
expectedBody
);
assertThat
(
avatarService
.
getAvatar
(
"098f6bcd4621d373cade4e832627b4f6"
,
"100"
)).
isEqualTo
(
expectedResponse
);
}
}
\ No newline at end of file
src/test/java/au/com/tpic/avatar/web/AvatarControllerTest.java
0 → 100644
View file @
88c2ff1f
package
au.com.tpic.avatar.web
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@SpringBootTest
@ActiveProfiles
(
"unit-test"
)
@AutoConfigureMockMvc
class
AvatarControllerTest
{
@Autowired
private
MockMvc
mockMvc
;
@Test
void
getDefaultAvatar
()
throws
Exception
{
byte
[]
expectedImage
=
getClass
().
getResourceAsStream
(
"/default.jpg"
).
readAllBytes
();
mockMvc
.
perform
(
get
(
"/avatar"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
IMAGE_JPEG
))
.
andExpect
(
content
().
bytes
(
expectedImage
));
}
@Test
void
getAvatarFromDirectory
()
throws
Exception
{
byte
[]
expectedImage
=
getClass
().
getResourceAsStream
(
"/test.png"
).
readAllBytes
();
mockMvc
.
perform
(
get
(
"/avatar/098f6bcd4621d373cade4e832627b4f6.png"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
IMAGE_PNG
))
.
andExpect
(
content
().
bytes
(
expectedImage
));
}
@Test
void
getResizedAvatarFromDirectory
()
throws
Exception
{
byte
[]
expectedImage
=
getClass
().
getResourceAsStream
(
"/test-100.jpg"
).
readAllBytes
();
mockMvc
.
perform
(
get
(
"/avatar/098f6bcd4621d373cade4e832627b4f6?s=100"
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
contentType
(
MediaType
.
IMAGE_JPEG
))
.
andExpect
(
content
().
bytes
(
expectedImage
));
}
}
\ No newline at end of file
src/test/resources/application-unit-test.yml
0 → 100644
View file @
88c2ff1f
avatar
:
directory
:
src/test/resources
\ No newline at end of file
src/test/resources/test-100.jpg
0 → 100644
View file @
88c2ff1f
1.83 KB
src/test/resources/test.png
0 → 100644
View file @
88c2ff1f
6.27 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment