aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/build.gradle6
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java26
2 files changed, 27 insertions, 5 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index d086e70a..c90b22d2 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -2,16 +2,12 @@ buildscript {
repositories {
mavenCentral()
}
- dependencies {
- classpath 'com.tkruse.gradle:gradle-groovysh-plugin:1.0.8'
- }
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.github.ben-manes.versions'
-apply plugin: 'com.github.tkruse.groovysh'
def springFrameworkVersion = "4.3.4.RELEASE"
def springSecurityVersion = "4.2.0.RELEASE"
@@ -32,8 +28,10 @@ dependencies {
providedRuntime 'mysql:mysql-connector-java:5.1.40'
testCompile "junit:junit:4.12"
+ testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile "org.mockito:mockito-core:1.+"
testCompile "org.springframework:spring-test:${springFrameworkVersion}"
+ testRuntime 'com.jayway.jsonpath:json-path:2.2.0'
}
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
index d03bd0bf..9f324686 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
@@ -1,5 +1,8 @@
package com.juick.api.tests;
+import com.juick.Message;
+import com.juick.Tag;
+import com.juick.User;
import com.juick.api.configuration.ApiAppConfiguration;
import com.juick.api.configuration.ApiMvcConfiguration;
import com.juick.service.MessagesService;
@@ -12,6 +15,7 @@ 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.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@@ -22,8 +26,12 @@ import org.springframework.web.context.WebApplicationContext;
import javax.inject.Inject;
import java.util.Collections;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
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.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
@@ -65,6 +73,16 @@ public class MessagesTests {
@Test
public void messageTests() throws Exception {
+ String ugnichName = "ugnich";
+ String msgText = "Привет, я - Угнич";
+ User user = new User();
+ user.setName(ugnichName);
+ user.setUid(1);
+ Message msg = new Message();
+ msg.setMid(1);
+ msg.setUser(user);
+ msg.setText(msgText);
+ msg.setTags(Collections.singletonList(new Tag("yo")));
mockMvc.perform(get("/home"))
.andExpect(status().is4xxClientError());
when(userService.getUIDByHttpAuth(null))
@@ -72,8 +90,14 @@ public class MessagesTests {
when(messagesService.getMyFeed(1, 0))
.thenReturn(Collections.singletonList(1));
+ when(messagesService.getMessages(Collections.singletonList(1)))
+ .thenReturn(Collections.singletonList(msg));
mockMvc.perform(get("/home"))
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
+ .andExpect(jsonPath("$", hasSize(1)))
+ .andExpect(jsonPath("$[0].mid", is(1)))
+ .andExpect(jsonPath("$[0].body", is(msgText)));
}
}