diff options
author | Vitaly Takmazov | 2017-10-15 05:37:18 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-15 19:50:15 +0300 |
commit | 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc (patch) | |
tree | 38b7a4ba01d1fc47841d3ba2787209b2b2a2de9e /juick-api/src/test | |
parent | aeda9e3733e685f5069b5cfbb16272cd32073fa0 (diff) |
api: ImagesService
Diffstat (limited to 'juick-api/src/test')
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java index fc71c755..518e3762 100644 --- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java +++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java @@ -28,11 +28,10 @@ import com.juick.api.configuration.ApiSecurityConfig; import com.juick.api.configuration.MessengerConfiguration; import com.juick.configuration.MockDataConfiguration; import com.juick.server.helpers.TagStats; -import com.juick.service.MessagesService; -import com.juick.service.TagService; -import com.juick.service.UserService; +import com.juick.service.*; import com.juick.test.util.MockUtils; import com.juick.util.DateFormattersHolder; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -91,6 +90,10 @@ public class MessagesTests { ApiServer apiServer() { return Mockito.mock(ApiServer.class); } + @Bean + ImagesService imagesService() { + return new MockImagesService(); + } } private MockMvc mockMvc; @@ -105,6 +108,8 @@ public class MessagesTests { private TagService tagService; @Inject private ObjectMapper jsonMapper; + @Inject + private ImagesService imagesService; private User ugnich, freefd; String ugnichName, ugnichPassword, freefdName, freefdPassword; @@ -138,6 +143,13 @@ public class MessagesTests { .thenReturn(new User()); } + @After + public void resetMocks() { + Mockito.reset(userService); + Mockito.reset(messagesService); + Mockito.reset(tagService); + } + @Test public void testAllUnAuthorized() throws Exception { @@ -164,6 +176,8 @@ public class MessagesTests { Message msg = MockUtils.mockMessage(1, ugnich, msgText); Instant now = Instant.now(); msg.setTimestamp(now); + msg.setAttachmentType("png"); + imagesService.setAttachmentMetadata("", "http://localhost/", msg); when(messagesService.getMyFeed(1, 0, true)) .thenReturn(Collections.singletonList(1)); when(messagesService.getMessages(Collections.singletonList(1))) @@ -177,7 +191,9 @@ public class MessagesTests { .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].mid", is(1))) .andExpect(jsonPath("$[0].timestamp", is(DateFormattersHolder.getMessageFormatterInstance().format(now)))) - .andExpect(jsonPath("$[0].body", is(msgText))); + .andExpect(jsonPath("$[0].body", is(msgText))) + .andExpect(jsonPath("$[0].attachment.url", is("http://localhost/p/1.png"))) + .andExpect(jsonPath("$[0].attachment.small.url", is("http://localhost/photos-512/1.png"))); } @Test @@ -235,7 +251,7 @@ public class MessagesTests { get("/home") .with(httpBasic(ugnichName, ugnichPassword)) .header("Origin", "http://api.example.net")) - .andExpect(status().isOk()) + .andExpect(status().isNotFound()) .andExpect(header().string("Access-Control-Allow-Origin", "*")); } |