aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-12 11:34:43 +0300
committerGravatar Vitaly Takmazov2018-01-12 11:34:43 +0300
commit40b392f1d63f6aaa8794beaff4c0432dd29f1858 (patch)
tree96bec459d88522124196d9d8ca92e677b48d2da8
parent59d08c3fe59077238e7f7774be359a7966ed522c (diff)
refactoring and tests fixes
-rw-r--r--juick-api/src/main/java/com/juick/api/EmailManager.java16
-rw-r--r--juick-api/src/main/java/com/juick/api/MessengerManager.java4
-rw-r--r--juick-api/src/main/java/com/juick/api/TelegramBotManager.java2
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java3
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Post.java3
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java14
6 files changed, 23 insertions, 19 deletions
diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-api/src/main/java/com/juick/api/EmailManager.java
index 1c105ef9..c90e7b7a 100644
--- a/juick-api/src/main/java/com/juick/api/EmailManager.java
+++ b/juick-api/src/main/java/com/juick/api/EmailManager.java
@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
+import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.mail.MessagingException;
import javax.mail.Multipart;
@@ -29,17 +30,20 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl;
@Component
public class EmailManager implements ApplicationListener<MessageEvent> {
+
+ public static final String MSGID_PATTERN = "\\.|@|<";
+
private static final Logger logger = LoggerFactory.getLogger(EmailManager.class);
@Inject
- EmailService emailService;
+ private EmailService emailService;
@Inject
- SubscriptionService subscriptionService;
+ private SubscriptionService subscriptionService;
@Inject
- MessagesService messagesService;
+ private MessagesService messagesService;
@Inject
- UserService userService;
+ private UserService userService;
@Override
- public void onApplicationEvent(MessageEvent event) {
+ public void onApplicationEvent(@Nonnull MessageEvent event) {
Message msg = event.getMessage();
if (msg.getRid() == 0) {
String subject = String.format("New message from %s", msg.getUser().getName());
@@ -55,7 +59,7 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
}
}
- void emailNotify(String email, String subject, Message msg) {
+ private void emailNotify(String email, String subject, Message msg) {
Properties prop = System.getProperties();
prop.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(prop);
diff --git a/juick-api/src/main/java/com/juick/api/MessengerManager.java b/juick-api/src/main/java/com/juick/api/MessengerManager.java
index f1babe81..2008144a 100644
--- a/juick-api/src/main/java/com/juick/api/MessengerManager.java
+++ b/juick-api/src/main/java/com/juick/api/MessengerManager.java
@@ -120,7 +120,7 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
}
}
- void messengerNotify(String messengerUser, String text, String url) {
+ private void messengerNotify(String messengerUser, String text, String url) {
try {
if (!StringUtils.isEmpty(url)) {
final UrlButton showMessage = UrlButton.create("VIEW MESSAGE", new URL(url));
@@ -133,7 +133,7 @@ public class MessengerManager implements ApplicationListener<MessageEvent> {
logger.warn("messenger error", e);
}
}
- void signupNotify(String messengerUser, String hash) throws MalformedURLException, MessengerApiException, MessengerIOException {
+ private void signupNotify(String messengerUser, String hash) throws MalformedURLException, MessengerApiException, MessengerIOException {
final UrlButton urlButton = UrlButton.create("LOGIN",
new URL("https://juick.com/signup?type=messenger&hash=" + hash));
ButtonTemplate template = ButtonTemplate.create("Login to receive notifications",
diff --git a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
index 73b8c3a8..0417afe1 100644
--- a/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
+++ b/juick-api/src/main/java/com/juick/api/TelegramBotManager.java
@@ -61,7 +61,7 @@ public class TelegramBotManager implements ApplicationListener<MessageEvent> {
@Inject
private SubscriptionService subscriptionService;
- public static final String MSG_LINK = "🔗";
+ private static final String MSG_LINK = "🔗";
@PostConstruct
public void init() {
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
index 32a88a0c..edda931b 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
@@ -24,6 +24,7 @@ import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+import javax.annotation.Nonnull;
import javax.servlet.Filter;
/**
@@ -47,6 +48,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni
}
@Override
+ @Nonnull
protected String[] getServletMappings() {
return new String[]{"/"};
}
@@ -57,6 +59,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni
}
@Override
+ @Nonnull
protected String getServletName() {
return "API dispatcher servlet";
}
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java
index 92daf2e7..27a0e3c8 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Post.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java
@@ -19,6 +19,7 @@ package com.juick.api.controllers;
import com.juick.User;
import com.juick.api.ApiServer;
+import com.juick.api.EmailManager;
import com.juick.server.util.*;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
@@ -252,7 +253,7 @@ public class Post {
});
String[] inReplyToHeaders = msg.getHeader("In-Reply-To");
if (inReplyToHeaders != null && inReplyToHeaders.length > 0) {
- Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter("\\.|@|<");
+ Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter(EmailManager.MSGID_PATTERN);
int mid = Integer.parseInt(inReplyToScanner.next());
int rid = Integer.parseInt(inReplyToScanner.next());
logger.info("Message is reply to #{}/{}", mid, rid);
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 a270a120..fff7e02c 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
@@ -23,6 +23,7 @@ import com.juick.ExternalToken;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
+import com.juick.api.EmailManager;
import com.juick.api.configuration.ApiAppConfiguration;
import com.juick.api.configuration.ApiSecurityConfig;
import com.juick.configuration.RepositoryConfiguration;
@@ -299,22 +300,17 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests {
IntStream.rangeClosed(6, 12).forEach(i -> {
messagesService.createReply(topmid, 0, i, "yo", null);
});
- mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword))
- .contentType(MediaType.APPLICATION_JSON_UTF8))
- .andExpect(status().isOk())
- .andExpect(jsonPath("$[0]", is(topmid)));
+
+ assertThat(messagesService.getPopularCandidates().get(0), is(topmid));
Tag juickTag = tagService.getTag(juickTagId);
assertThat(juickTag.TID, is(2));
tagService.updateTags(topmid, Collections.singletonList(juickTag));
- mockMvc.perform(get("/messages/top_candidates").with(httpBasic(juickName, juickPassword))
- .contentType(MediaType.APPLICATION_JSON_UTF8))
- .andExpect(status().isOk())
- .andExpect(jsonPath("$", hasSize(0)));
+ assertThat(messagesService.getPopularCandidates().isEmpty(), is(true));
}
@Test
public void inReplyToScannerTest() {
String header = "<123456.56@juick.com>";
- Scanner headerScanner = new Scanner(header).useDelimiter("\\.|@|<");
+ Scanner headerScanner = new Scanner(header).useDelimiter(EmailManager.MSGID_PATTERN);
int mid = Integer.parseInt(headerScanner.next());
int rid = Integer.parseInt(headerScanner.next());
assertThat(mid, equalTo(123456));