aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/test/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-02 17:26:31 +0300
committerGravatar Vitaly Takmazov2017-11-02 17:26:31 +0300
commit3bbf2004183058d0476c25b5ff2a3f50c80165c9 (patch)
tree4fc8f2507694e239ea6c86817ee0415d36ff11cd /juick-server-jdbc/src/test/java/com/juick/service
parentd95a1d019b08a5eebe674e68a1692513d7d16991 (diff)
reorganize tests
Diffstat (limited to 'juick-server-jdbc/src/test/java/com/juick/service')
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
index 0577e009..23e01fd2 100644
--- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
+++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
@@ -22,6 +22,8 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.configuration.RepositoryConfiguration;
import com.juick.server.helpers.AnonymousUser;
+import com.juick.server.helpers.TagStats;
+import org.apache.commons.lang3.StringUtils;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -30,11 +32,13 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertEquals;
/**
* Created by aalexeev on 11/25/16.
@@ -122,4 +126,48 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
assertThat(pm.getText(), equalTo("hello"));
assertThat(pm.getUser().getUid(), equalTo(freefdId));
}
+
+ @Test
+ public void messageTests() {
+ int user_id = userService.createUser("mmmme", "secret");
+ User user = userService.getUserByUID(user_id).orElse(new User());
+ assertEquals("it should be me", "mmmme", user.getName());
+ int mid = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
+ Message msg = messagesService.getMessage(mid);
+ assertEquals("yo", msg.getText());
+ User me = msg.getUser();
+ assertEquals("mmmme", me.getName());
+ assertEquals("mmmme", messagesService.getMessageAuthor(mid).getName());
+ int tagID = tagService.createTag("weather");
+ Tag tag = tagService.getTag(tagID);
+ List<Tag> tagList = new ArrayList<>();
+ tagList.add(tag);
+ int mid2 = messagesService.createMessage(user_id, "yo2", null, tagList);
+ Message msg2 = messagesService.getMessage(mid2);
+ assertEquals(1, msg2.getTags().size());
+ assertEquals("we already have ugnich", -1, userService.createUser("ugnich", "x"));
+ int ugnich_id = userService.createUser("hugnich", "x");
+ User ugnich = userService.getUserByUID(ugnich_id).orElse(new User());
+ int rid = messagesService.createReply(msg2.getMid(), 0, ugnich.getUid(), "bla-bla", null);
+ assertEquals(1, rid);
+ Message msg3 = messagesService.getMessage(mid2);
+ assertEquals(1, msg3.getReplies());
+ assertEquals("weather", msg3.getTags().get(0).getName());
+ assertEquals(ugnich.getUid(), userService.checkPassword(ugnich.getName(), "x"));
+ assertEquals(-1, userService.checkPassword(ugnich.getName(), "xy"));
+ subscriptionService.subscribeMessage(msg.getMid(), ugnich.getUid());
+ assertEquals(1, subscriptionService.getUsersSubscribedToComments(msg.getMid(), user.getUid()).size());
+ messagesService.deleteMessage(user_id, mid);
+ messagesService.deleteMessage(user_id, mid2);
+ String htmlTagName = ">_<";
+ Tag htmlTag = tagService.getTag(htmlTagName, true);
+ TagStats htmlTagStats = new TagStats();
+ htmlTagStats.setTag(htmlTag);
+ String dbTagName = jdbcTemplate.queryForObject("select name from tags where name=?", String.class, htmlTagName);
+ assertEquals("db tags should not be escaped", dbTagName, htmlTag.getName());
+ int mid4 = messagesService.createMessage(user_id, "yoyoyo", null, null);
+ Message msg4 = messagesService.getMessage(mid4);
+ assertEquals("tags string should be empty", StringUtils.EMPTY, msg4.getTagsString());
+ messagesService.deleteMessage(user_id, mid4);
+ }
}