aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/test/java/com/juick/api
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/test/java/com/juick/api')
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java66
1 files changed, 12 insertions, 54 deletions
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 2a5dba18..61d1b008 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
@@ -6,20 +6,17 @@ import com.juick.User;
import com.juick.api.configuration.ApiAppConfiguration;
import com.juick.api.configuration.ApiMvcConfiguration;
import com.juick.api.configuration.ApiSecurityConfig;
-import com.juick.configuration.DataConfiguration;
+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 org.apache.commons.lang3.RandomStringUtils;
+import com.juick.tests.util.MockUtils;
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.http.MediaType;
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.context.ContextConfiguration;
@@ -47,26 +44,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@WebAppConfiguration
public class MessagesTests {
@Configuration
- @Import(value = {ApiMvcConfiguration.class, ApiAppConfiguration.class, ApiSecurityConfig.class, DataConfiguration.class})
- static class Config {
- @Bean
- @Primary
- MessagesService messagesService() {
- return Mockito.mock(MessagesService.class);
- }
-
- @Bean
- @Primary
- UserService userService() {
- return Mockito.mock(UserService.class);
- }
-
- @Bean
- @Primary
- TagService tagService() {
- return Mockito.mock(TagService.class);
- }
- }
+ @Import(value = {ApiMvcConfiguration.class, ApiAppConfiguration.class, ApiSecurityConfig.class, MockDataConfiguration.class})
+ static class Config {}
private MockMvc mockMvc;
@Inject
@@ -82,27 +61,6 @@ public class MessagesTests {
private User ugnich, freefd;
String ugnichName, ugnichPassword, freefdName, freefdPassword;
- private static Message getMessage(final User user, final String messageText) {
- Message msg = new Message();
-
- msg.setMid(1);
- msg.setUser(user);
- msg.setText(messageText == null ? RandomStringUtils.randomAlphanumeric(24) : messageText);
- msg.setTags(Collections.singletonList(new Tag(RandomStringUtils.randomAlphabetic(4))));
-
- return msg;
- }
-
- private static User getUser(final int uid, final String name, final String password) {
- User user = new User();
-
- user.setName(name);
- user.setUid(uid);
- user.setCredentials(password);
- user.setBanned(false);
-
- return user;
- }
@Before
public void setUp() {
@@ -115,8 +73,8 @@ public class MessagesTests {
freefdName = "freefd";
freefdPassword = "MyPassw0rd!";
- ugnich = getUser(1, ugnichName, ugnichPassword);
- freefd = getUser(2, freefdName, freefdPassword);
+ ugnich = MockUtils.mockUser(1, ugnichName, ugnichPassword);
+ freefd = MockUtils.mockUser(2, freefdName, freefdPassword);
List<String> users = new ArrayList<>(2);
users.add(ugnichName);
@@ -152,7 +110,7 @@ public class MessagesTests {
public void homeTestWithMessages() throws Exception {
String msgText = "Привет, я - Угнич";
- Message msg = getMessage(ugnich, msgText);
+ Message msg = MockUtils.mockMessage(1, ugnich, msgText);
when(messagesService.getMyFeed(1, 0))
.thenReturn(Collections.singletonList(1));
@@ -174,8 +132,8 @@ public class MessagesTests {
String msgText = "Привет, я - Угнич";
String hash = "12345678";
- User user = getUser(1, ugnichName, ugnichPassword);
- Message msg = getMessage(user, msgText);
+ User user = MockUtils.mockUser(1, ugnichName, ugnichPassword);
+ Message msg = MockUtils.mockMessage(1, user, msgText);
when(userService.getUIDbyName(ugnichName))
.thenReturn(1);
@@ -208,8 +166,8 @@ public class MessagesTests {
@Test
public void homeTestWithMessagesAndSimpleCors() throws Exception {
- User user = getUser(1, ugnichName, ugnichPassword);
- Message msg = getMessage(user, null);
+ User user = MockUtils.mockUser(1, ugnichName, ugnichPassword);
+ Message msg = MockUtils.mockMessage(1, user, null);
when(userService.getFullyUserByName(ugnichName))
.thenReturn(user);
@@ -230,7 +188,7 @@ public class MessagesTests {
@Test
public void homeTestWithPreflightCors() throws Exception {
- User user = getUser(1, ugnichName, ugnichPassword);
+ User user = MockUtils.mockUser(1, ugnichName, ugnichPassword);
when(userService.getFullyUserByName(ugnichName))
.thenReturn(user);