From 9a4add44ecbd32dea6ac3d30fd81ae1ac82e3dbc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Oct 2017 05:37:18 +0300 Subject: api: ImagesService --- .../api/configuration/ApiAppConfiguration.java | 3 +++ .../juick/api/configuration/ApiInitializer.java | 5 ++--- .../juick/api/configuration/ApiSecurityConfig.java | 2 ++ .../java/com/juick/api/tests/MessagesTests.java | 26 +++++++++++++++++----- 4 files changed, 28 insertions(+), 8 deletions(-) (limited to 'juick-api') diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java index f77611e2..c78ea51a 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java @@ -20,6 +20,8 @@ package com.juick.api.configuration; import com.juick.api.ApiServer; import com.juick.api.TelegramBotManager; import com.juick.server.configuration.BaseWebConfiguration; +import com.juick.service.ImagesService; +import com.juick.service.ImagesServiceImpl; import org.springframework.context.annotation.*; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -69,6 +71,7 @@ public class ApiAppConfiguration extends BaseWebConfiguration { public ApiServer apiServer() { return new ApiServer(); } + @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java index fa025e56..8f9cb4ed 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java @@ -17,7 +17,6 @@ package com.juick.api.configuration; -import com.juick.configuration.DataConfiguration; import org.apache.commons.codec.CharEncoding; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @@ -32,13 +31,13 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni @Override protected Class[] getRootConfigClasses() { return new Class[]{ - ApiSecurityConfig.class, DataConfiguration.class, MessengerConfiguration.class + ApiSecurityConfig.class }; } @Override protected Class[] getServletConfigClasses() { - return new Class[]{ ApiAppConfiguration.class }; + return new Class[]{ MessengerConfiguration.class }; } @Override diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java index e4ae4b80..7e3f3345 100644 --- a/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java +++ b/juick-api/src/main/java/com/juick/api/configuration/ApiSecurityConfig.java @@ -24,6 +24,7 @@ import com.juick.service.security.deprecated.RequestParamHashRememberMeServices; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; import org.springframework.http.HttpMethod; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; @@ -48,6 +49,7 @@ import java.util.concurrent.TimeUnit; @Configuration @EnableWebSecurity @PropertySource("classpath:juick.conf") +@Import(ApiAppConfiguration.class) public class ApiSecurityConfig extends WebSecurityConfigurerAdapter { @Value("${auth_remember_me_key}") private String rememberMeKey; 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