aboutsummaryrefslogtreecommitdiff
path: root/juick-www
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-01-12 14:59:11 +0300
committerGravatar Vitaly Takmazov2017-01-12 14:59:11 +0300
commit0c1ef3ab4f352445df3c1ebf87fe9eac2f78df41 (patch)
tree67248eabf7ca63cdfe5beddad090a33c86b51973 /juick-www
parent14940bf9bf63b1ca8d7d09fde37be52c9ae94ca8 (diff)
tests refactoring
Diffstat (limited to 'juick-www')
-rw-r--r--juick-www/build.gradle4
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java (renamed from juick-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java)2
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java2
-rw-r--r--juick-www/src/test/java/com/juick/www/WebAppTests.java90
4 files changed, 96 insertions, 2 deletions
diff --git a/juick-www/build.gradle b/juick-www/build.gradle
index 8d081515..26cf61da 100644
--- a/juick-www/build.gradle
+++ b/juick-www/build.gradle
@@ -30,6 +30,10 @@ dependencies {
compile 'com.mitchellbosecke:pebble-spring4:2.3.0'
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedRuntime 'mysql:mysql-connector-java:5.1.40'
+
+ testCompile project(path: ':juick-server', configuration: 'testArtifacts')
+ testCompile ('net.sourceforge.htmlunit:htmlunit:2.24')
+
}
compileFrontend.dependsOn 'npmInstall'
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java
index cd681190..7ffefb1d 100644
--- a/juick-www/src/main/java/com/juick/www/configuration/WebAppConfiguration.java
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java
@@ -21,7 +21,7 @@ import javax.inject.Inject;
@Configuration
@PropertySource("classpath:juick.conf")
@EnableCaching
-public class WebAppConfiguration {
+public class WwwAppConfiguration {
@Resource
private Environment env;
@Inject
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
index cd5429c2..0e185447 100644
--- a/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwInitializer.java
@@ -18,7 +18,7 @@ public class WwwInitializer extends AbstractAnnotationConfigDispatcherServletIni
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{
- WebAppConfiguration.class,
+ WwwAppConfiguration.class,
DataConfiguration.class,
SearchConfiguration.class
};
diff --git a/juick-www/src/test/java/com/juick/www/WebAppTests.java b/juick-www/src/test/java/com/juick/www/WebAppTests.java
new file mode 100644
index 00000000..b4fa14bb
--- /dev/null
+++ b/juick-www/src/test/java/com/juick/www/WebAppTests.java
@@ -0,0 +1,90 @@
+package com.juick.www;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.juick.Message;
+import com.juick.User;
+import com.juick.configuration.MockDataConfiguration;
+import com.juick.service.MessagesService;
+import com.juick.service.UserService;
+import com.juick.tests.util.MockUtils;
+import com.juick.www.configuration.WwwAppConfiguration;
+import com.juick.www.configuration.WwwServletConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
+import org.springframework.web.context.WebApplicationContext;
+
+import javax.inject.Inject;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by vitalyster on 12.01.2017.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextConfiguration
+public class WebAppTests {
+ @Configuration
+ @Import(value = {WwwServletConfiguration.class, WwwAppConfiguration.class, MockDataConfiguration.class})
+ static class Config {}
+
+ @Inject
+ private WebApplicationContext wac;
+ @Inject
+ private WebApp webApp;
+
+ private WebClient webClient;
+
+ @Inject
+ UserService userService;
+ @Inject
+ MessagesService messagesService;
+
+ @Before
+ public void setup() {
+ webClient = MockMvcWebClientBuilder.webAppContextSetup(this.wac).build();
+ }
+
+ @Test
+ public void postWithoutTagsShouldNotHaveAsteriskInTitle() throws Exception {
+ String ugnichName = "ugnich";
+ String ugnichPassword = "MyPassw0rd!";
+ String msgText = "Привет, я - Угнич";
+ String hash = "12345678";
+
+ User user = MockUtils.mockUser(1, ugnichName, ugnichPassword);
+ Message msg = MockUtils.mockMessage(1, user, msgText);
+
+ when(userService.getUIDbyName(ugnichName))
+ .thenReturn(1);
+ when(userService.getUserByName(ugnichName))
+ .thenReturn(user);
+ when(userService.getUserByUID(1))
+ .thenReturn(Optional.of(user));
+ when(userService.getFullyUserByName(ugnichName))
+ .thenReturn(user);
+ when(messagesService.getMyFeed(1, 0))
+ .thenReturn(Collections.singletonList(1));
+ when(messagesService.getMessages(Collections.singletonList(1)))
+ .thenReturn(Collections.singletonList(msg));
+ when(userService.getUIDbyHash(hash))
+ .thenReturn(1);
+ when(messagesService.getMessageAuthor(1)).thenReturn(user);
+ when(messagesService.canViewThread(1, 0)).thenReturn(true);
+ when(messagesService.getMessage(1)).thenReturn(msg);
+ HtmlPage threadPage = webClient.getPage("http://localhost:8080/ugnich/1");
+ assertThat(threadPage.getTitleText(), equalTo("ugnich:"));
+ }
+}