Commit 88c2ff1f authored by Tim Coates (CPVV)'s avatar Tim Coates (CPVV)

Additional unit tests

parent 909fb7d2
......@@ -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
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
avatar:
directory: src/test/resources
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment