From 2be12ebce3d600804227f6b74374c8db37921139 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 11 Dec 2017 22:55:51 +0300 Subject: fix some tests --- .../java/com/juick/api/tests/MessagesTests.java | 3 +-- .../configuration/MockStorageConfiguration.java | 14 -------------- .../juick/components/test/NotificationTests.java | 2 ++ .../configuration/MockStorageConfiguration.java | 14 ++++++++++++++ .../src/test/java/com/juick/www/WebAppTests.java | 22 ++++++++++++++++++++-- 5 files changed, 37 insertions(+), 18 deletions(-) delete mode 100644 juick-api/src/test/java/com/juick/api/tests/configuration/MockStorageConfiguration.java create mode 100644 juick-server-jdbc/src/test/java/com/juick/configuration/MockStorageConfiguration.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 07e649ec..0022c966 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 @@ -25,7 +25,6 @@ import com.juick.Tag; import com.juick.User; import com.juick.api.configuration.ApiAppConfiguration; import com.juick.api.configuration.ApiSecurityConfig; -import com.juick.api.tests.configuration.MockStorageConfiguration; import com.juick.configuration.RepositoryConfiguration; import com.juick.server.helpers.TagStats; import com.juick.service.ImagesService; @@ -65,7 +64,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * Created by vitalyster on 25.11.2016. */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, RepositoryConfiguration.class, MockStorageConfiguration.class}) +@ContextConfiguration(classes = {ApiAppConfiguration.class, ApiSecurityConfig.class, RepositoryConfiguration.class}) @WebAppConfiguration public class MessagesTests extends AbstractJUnit4SpringContextTests { diff --git a/juick-api/src/test/java/com/juick/api/tests/configuration/MockStorageConfiguration.java b/juick-api/src/test/java/com/juick/api/tests/configuration/MockStorageConfiguration.java deleted file mode 100644 index 374bec0a..00000000 --- a/juick-api/src/test/java/com/juick/api/tests/configuration/MockStorageConfiguration.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.juick.api.tests.configuration; - -import com.juick.service.ImagesService; -import com.juick.service.MockImagesService; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class MockStorageConfiguration { - @Bean - public ImagesService imagesService() { - return new MockImagesService(); - } -} diff --git a/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java b/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java index cc02b07d..9688e935 100644 --- a/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java +++ b/juick-notifications/src/test/java/com/juick/components/test/NotificationTests.java @@ -17,6 +17,7 @@ package com.juick.components.test; +import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.LoggingEvent; import ch.qos.logback.core.Appender; @@ -62,6 +63,7 @@ public class NotificationTests { ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final Appender mockAppender = mock(Appender.class); when(mockAppender.getName()).thenReturn("MOCK"); + root.setLevel(Level.DEBUG); root.addAppender(mockAppender); cleanUp.cleanupTokens(); verify(mockAppender).doAppend(argThat(argument -> diff --git a/juick-server-jdbc/src/test/java/com/juick/configuration/MockStorageConfiguration.java b/juick-server-jdbc/src/test/java/com/juick/configuration/MockStorageConfiguration.java new file mode 100644 index 00000000..bfaa26b9 --- /dev/null +++ b/juick-server-jdbc/src/test/java/com/juick/configuration/MockStorageConfiguration.java @@ -0,0 +1,14 @@ +package com.juick.configuration; + +import com.juick.service.ImagesService; +import com.juick.service.MockImagesService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MockStorageConfiguration { + @Bean + public ImagesService imagesService() { + return new MockImagesService(); + } +} diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java index 927ea71c..aacfe8ce 100644 --- a/juick-www/src/test/java/com/juick/www/WebAppTests.java +++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java @@ -39,13 +39,14 @@ import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.error.PebbleException; import com.mitchellbosecke.pebble.template.PebbleTemplate; import org.apache.commons.text.StringEscapeUtils; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.mock.web.MockMultipartFile; @@ -56,6 +57,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.util.FileSystemUtils; import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; @@ -63,6 +65,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Collections; import java.util.stream.IntStream; import java.util.stream.StreamSupport; @@ -112,6 +116,8 @@ public class WebAppTests { @Inject PebbleEngine pebbleEngine; + @Value("${img_path:/tmp}") + String imgPath; private static User ugnich, freefd; private static String ugnichName, ugnichPassword, freefdName, freefdPassword; @@ -119,7 +125,7 @@ public class WebAppTests { private static boolean isSetUp = false; @Before - public void setup() { + public void setup() throws IOException { if (!isSetUp) { mockMvc = MockMvcBuilders.webAppContextSetup(wac) .apply(springSecurity()) @@ -141,6 +147,18 @@ public class WebAppTests { isSetUp = true; } + Files.createDirectory(Paths.get(imgPath, "p")); + Files.createDirectory(Paths.get(imgPath, "photos-1024")); + Files.createDirectory(Paths.get(imgPath, "photos-512")); + Files.createDirectory(Paths.get(imgPath, "ps")); + } + + @After + public void teardown() throws IOException { + FileSystemUtils.deleteRecursively(Paths.get(imgPath, "p")); + FileSystemUtils.deleteRecursively(Paths.get(imgPath, "photos-1024")); + FileSystemUtils.deleteRecursively(Paths.get(imgPath, "photos-512")); + FileSystemUtils.deleteRecursively(Paths.get(imgPath, "ps")); } @Test -- cgit v1.2.3