aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/build.gradle4
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java79
2 files changed, 83 insertions, 0 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index 382ea8bd..d086e70a 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -30,6 +30,10 @@ dependencies {
compile 'com.neovisionaries:nv-websocket-client:1.30'
compile 'net.coobird:thumbnailator:0.4.8'
providedRuntime 'mysql:mysql-connector-java:5.1.40'
+
+ testCompile "junit:junit:4.12"
+ testCompile "org.mockito:mockito-core:1.+"
+ testCompile "org.springframework:spring-test:${springFrameworkVersion}"
}
compileJava.options.encoding = 'UTF-8'
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
new file mode 100644
index 00000000..d03bd0bf
--- /dev/null
+++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java
@@ -0,0 +1,79 @@
+package com.juick.api.tests;
+
+import com.juick.api.configuration.ApiAppConfiguration;
+import com.juick.api.configuration.ApiMvcConfiguration;
+import com.juick.service.MessagesService;
+import com.juick.service.UserService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Primary;
+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.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import javax.inject.Inject;
+import java.util.Collections;
+
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/**
+ * Created by vitalyster on 25.11.2016.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+@WebAppConfiguration
+public class MessagesTests {
+ @Configuration
+ @Import(value={ApiMvcConfiguration.class, ApiAppConfiguration.class})
+ static class Config {
+ @Bean
+ @Primary
+ MessagesService messagesService() {
+ return Mockito.mock(MessagesService.class);
+ }
+ @Bean
+ @Primary
+ UserService userService() {
+ return Mockito.mock(UserService.class);
+ }
+ }
+
+ private MockMvc mockMvc;
+ @Inject
+ WebApplicationContext webApplicationContext;
+
+ @Inject
+ MessagesService messagesService;
+ @Inject
+ UserService userService;
+
+ @Before
+ public void setUp() {
+ mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
+ .build();
+ }
+
+ @Test
+ public void messageTests() throws Exception {
+ mockMvc.perform(get("/home"))
+ .andExpect(status().is4xxClientError());
+ when(userService.getUIDByHttpAuth(null))
+ .thenReturn(1);
+
+ when(messagesService.getMyFeed(1, 0))
+ .thenReturn(Collections.singletonList(1));
+
+ mockMvc.perform(get("/home"))
+ .andExpect(status().isOk());
+ }
+}