From 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Oct 2017 05:37:18 +0300 Subject: api: ImagesService --- .../java/com/juick/api/tests/MessagesTests.java | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'juick-api/src/test/java') 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", "*")); } -- cgit v1.2.3