diff options
author | Vitaly Takmazov | 2018-03-28 14:16:08 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-28 15:25:02 +0300 |
commit | 49bf2e2971d734ed8d1e5fdc6aab284a51fa5203 (patch) | |
tree | 0fcd8b55f2c29a82d0aff7be90e6c6caddf0e278 /juick-server-jdbc | |
parent | 8fa74e5555805acc8ddaa71b362cd684ef1f76c1 (diff) |
h2 schema and test fixes
Diffstat (limited to 'juick-server-jdbc')
-rw-r--r-- | juick-server-jdbc/build.gradle | 7 | ||||
-rw-r--r-- | juick-server-jdbc/src/main/resources/schema.sql | 109 | ||||
-rw-r--r-- | juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java | 231 |
3 files changed, 55 insertions, 292 deletions
diff --git a/juick-server-jdbc/build.gradle b/juick-server-jdbc/build.gradle index 3dc3d0c4..d02af190 100644 --- a/juick-server-jdbc/build.gradle +++ b/juick-server-jdbc/build.gradle @@ -4,12 +4,5 @@ dependencies { compile("org.springframework.boot:spring-boot-starter-jdbc") compile project(':juick-common') - compile "org.apache.commons:commons-dbcp2:2.2.0" - compile "com.googlecode.log4jdbc:log4jdbc:1.2" - runtime 'mysql:mysql-connector-java:5.1.45' - - testCompile("org.springframework.boot:spring-boot-starter-test") - testRuntime 'com.h2database:h2:1.4.196' - testRuntime "org.postgresql:postgresql:42.2.2" } diff --git a/juick-server-jdbc/src/main/resources/schema.sql b/juick-server-jdbc/src/main/resources/schema.sql index 65166da4..c4b1026e 100644 --- a/juick-server-jdbc/src/main/resources/schema.sql +++ b/juick-server-jdbc/src/main/resources/schema.sql @@ -1,33 +1,34 @@ SET MODE MYSQL; +SET DB_CLOSE_ON_EXIT TRUE; -CREATE TABLE `android` ( +CREATE TABLE IF NOT EXISTS `android` ( `user_id` int(10) unsigned NOT NULL, `regid` char(255) NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, ); -CREATE TABLE `auth` ( +CREATE TABLE IF NOT EXISTS `auth` ( `user_id` int(10) unsigned NOT NULL, `protocol` enum('xmpp','email','sms') NOT NULL, `account` char(64) NOT NULL, `authcode` char(8) NOT NULL ); -CREATE TABLE `bl_tags` ( +CREATE TABLE IF NOT EXISTS `bl_tags` ( `user_id` int(10) unsigned NOT NULL, `tag_id` int(10) unsigned NOT NULL, ); -CREATE TABLE `bl_users` ( +CREATE TABLE IF NOT EXISTS `bl_users` ( `user_id` int(10) unsigned NOT NULL, `bl_user_id` int(10) unsigned NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`user_id`,`bl_user_id`) ); -CREATE TABLE `emails` ( +CREATE TABLE IF NOT EXISTS `emails` ( `user_id` int(10) unsigned NOT NULL, `email` char(64) NOT NULL, `subscr_hour` tinyint(4) DEFAULT NULL, KEY `email` (`email`) ); -CREATE TABLE `facebook` ( +CREATE TABLE IF NOT EXISTS `facebook` ( `user_id` int(10) unsigned DEFAULT NULL, `fb_id` bigint(20) unsigned NOT NULL, `loginhash` char(36) DEFAULT NULL, @@ -38,19 +39,19 @@ CREATE TABLE `facebook` ( `crosspost` tinyint(1) unsigned NOT NULL DEFAULT '1', KEY `user_id` (`user_id`) ); -CREATE TABLE `favorites` ( +CREATE TABLE IF NOT EXISTS `favorites` ( `user_id` int(10) unsigned NOT NULL, `message_id` int(10) unsigned NOT NULL, `ts` datetime NOT NULL, UNIQUE KEY `user_id_2` (`user_id`,`message_id`), KEY `message_id` (`message_id`) ); -CREATE TABLE `friends_facebook` ( +CREATE TABLE IF NOT EXISTS `friends_facebook` ( `user_id` int(10) unsigned NOT NULL, `friend_id` bigint(20) unsigned NOT NULL, UNIQUE KEY `user_id` (`user_id`,`friend_id`) ); -CREATE TABLE `images` ( +CREATE TABLE IF NOT EXISTS `images` ( `mid` int(10) unsigned NOT NULL, `rid` int(10) unsigned NOT NULL, `thumb` int(10) unsigned NOT NULL, @@ -60,7 +61,7 @@ CREATE TABLE `images` ( `width` int(10) unsigned NOT NULL, PRIMARY KEY (`mid`,`rid`) ); -CREATE TABLE `ios` ( +CREATE TABLE IF NOT EXISTS `ios` ( `user_id` int(10) unsigned NOT NULL, `token` char(64) NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -68,7 +69,7 @@ CREATE TABLE `ios` ( KEY (`user_id`) ); -CREATE TABLE `jids` ( +CREATE TABLE IF NOT EXISTS `jids` ( `user_id` int(10) unsigned DEFAULT NULL, `jid` char(64) NOT NULL, `active` tinyint(1) NOT NULL DEFAULT '1', @@ -78,19 +79,19 @@ CREATE TABLE `jids` ( KEY (`user_id`) ); -CREATE TABLE `logins` ( +CREATE TABLE IF NOT EXISTS `logins` ( `user_id` int(10) unsigned NOT NULL, `hash` char(16) NOT NULL, UNIQUE KEY (`user_id`) ); -CREATE TABLE `mail` ( +CREATE TABLE IF NOT EXISTS `mail` ( `user_id` int(10) unsigned NOT NULL, `hash` char(16) NOT NULL, PRIMARY KEY (`user_id`) ); -CREATE TABLE `meon` ( +CREATE TABLE IF NOT EXISTS `meon` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `link` char(255) NOT NULL, @@ -99,23 +100,23 @@ CREATE TABLE `meon` ( PRIMARY KEY (`id`) ); -CREATE TABLE `messages` ( +CREATE TABLE IF NOT EXISTS `messages` ( `message_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `lang` enum('en','ru','fr','fa','__') NOT NULL DEFAULT '__', - `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ts` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP, `replies` smallint(5) unsigned NOT NULL DEFAULT '0', `maxreplyid` smallint(5) unsigned NOT NULL DEFAULT '0', `privacy` tinyint(4) NOT NULL DEFAULT '1', `readonly` tinyint(1) NOT NULL DEFAULT '0', - `attach` enum('jpg','mp4','png') DEFAULT NULL, + `attach` nchar(3) check (attach in ('jpg', 'mp4', 'png')), `place_id` int(10) unsigned DEFAULT NULL, `lat` decimal(10,7) DEFAULT NULL, `lon` decimal(10,7) DEFAULT NULL, `popular` tinyint(4) NOT NULL DEFAULT '0', `hidden` tinyint(3) unsigned NOT NULL DEFAULT '0', `likes` smallint(6) NOT NULL DEFAULT '0', - `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`message_id`), KEY (`user_id`), KEY (`ts`), @@ -126,13 +127,13 @@ CREATE TABLE `messages` ( KEY (`updated`,`message_id`) ); -CREATE TABLE `messages_access` ( +CREATE TABLE IF NOT EXISTS `messages_access` ( `message_id` int(10) unsigned NOT NULL, `user_id` int(10) unsigned NOT NULL, KEY (`message_id`) ); -CREATE TABLE `messages_tags` ( +CREATE TABLE IF NOT EXISTS `messages_tags` ( `message_id` int(10) unsigned NOT NULL, `tag_id` int(10) unsigned NOT NULL, UNIQUE KEY `message_id_2` (`message_id`,`tag_id`), @@ -140,7 +141,7 @@ CREATE TABLE `messages_tags` ( KEY (`tag_id`) ); -CREATE TABLE `messages_txt` ( +CREATE TABLE IF NOT EXISTS `messages_txt` ( `message_id` int(10) unsigned NOT NULL, `tags` varchar(255) DEFAULT NULL, `repliesby` varchar(96) DEFAULT NULL, @@ -148,14 +149,14 @@ CREATE TABLE `messages_txt` ( PRIMARY KEY (`message_id`) ); -CREATE TABLE `messages_votes` ( +CREATE TABLE IF NOT EXISTS `messages_votes` ( `message_id` int(10) unsigned NOT NULL, `user_id` int(10) unsigned NOT NULL, `vote` tinyint(4) NOT NULL DEFAULT '1', UNIQUE KEY `message_id` (`message_id`,`user_id`) ); -CREATE TABLE `messenger` ( +CREATE TABLE IF NOT EXISTS `messenger` ( `user_id` int(10) unsigned DEFAULT NULL, `sender_id` bigint(20) NOT NULL, `display_name` char(64) NOT NULL, @@ -163,7 +164,7 @@ CREATE TABLE `messenger` ( `loginhash` char(36) DEFAULT NULL ); -CREATE TABLE `places` ( +CREATE TABLE IF NOT EXISTS `places` ( `place_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `lat` decimal(10,7) NOT NULL, `lon` decimal(10,7) NOT NULL, @@ -175,26 +176,26 @@ CREATE TABLE `places` ( PRIMARY KEY (`place_id`) ); -CREATE TABLE `places_tags` ( +CREATE TABLE IF NOT EXISTS `places_tags` ( `place_id` int(10) unsigned NOT NULL, `tag_id` int(10) unsigned NOT NULL ); -CREATE TABLE `pm` ( +CREATE TABLE IF NOT EXISTS `pm` ( `user_id` int(10) unsigned NOT NULL, `user_id_to` int(10) unsigned NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `txt` text NOT NULL ); -CREATE TABLE `pm_inroster` ( +CREATE TABLE IF NOT EXISTS `pm_inroster` ( `user_id` int(10) unsigned NOT NULL, `jid` char(64) NOT NULL, UNIQUE KEY (`user_id`,`jid`), KEY (`user_id`) ); -CREATE TABLE `pm_streams` ( +CREATE TABLE IF NOT EXISTS `pm_streams` ( `user_id` int(10) unsigned NOT NULL, `user_id_to` int(10) unsigned NOT NULL, `lastmessage` datetime NOT NULL, @@ -203,19 +204,19 @@ CREATE TABLE `pm_streams` ( UNIQUE KEY (`user_id`,`user_id_to`) ); -CREATE TABLE `presence` ( +CREATE TABLE IF NOT EXISTS `presence` ( `user_id` int(10) unsigned NOT NULL, `jid` char(64) DEFAULT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY (`jid`) ); -CREATE TABLE `replies` ( +CREATE TABLE IF NOT EXISTS `replies` ( `message_id` int(10) unsigned NOT NULL, `reply_id` smallint(5) unsigned NOT NULL, `user_id` int(10) unsigned NOT NULL, `replyto` smallint(5) unsigned NOT NULL DEFAULT '0', - `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ts` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP, `attach` enum('jpg','mp4','png') DEFAULT NULL, `txt` mediumtext NOT NULL, KEY (`message_id`), @@ -223,13 +224,13 @@ CREATE TABLE `replies` ( KEY (`ts`) ); -CREATE TABLE `subscr_messages` ( +CREATE TABLE IF NOT EXISTS `subscr_messages` ( `message_id` int(10) unsigned NOT NULL, `suser_id` int(10) unsigned NOT NULL, UNIQUE KEY (`message_id`,`suser_id`) ); -CREATE TABLE `subscr_tags` ( +CREATE TABLE IF NOT EXISTS `subscr_tags` ( `tag_id` int(10) unsigned NOT NULL, `suser_id` int(10) unsigned NOT NULL, `jid` char(64) NOT NULL, @@ -237,7 +238,7 @@ CREATE TABLE `subscr_tags` ( UNIQUE KEY (`tag_id`,`suser_id`) ); -CREATE TABLE `subscr_users` ( +CREATE TABLE IF NOT EXISTS `subscr_users` ( `user_id` int(10) unsigned NOT NULL, `suser_id` int(10) unsigned NOT NULL, `jid` char(64) DEFAULT NULL, @@ -247,10 +248,10 @@ CREATE TABLE `subscr_users` ( KEY (`suser_id`) ); -CREATE TABLE `tags` ( +CREATE TABLE IF NOT EXISTS `tags` ( `tag_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `synonym_id` int(10) unsigned DEFAULT NULL, - `name` char(70) DEFAULT NULL, + `name` varchar_ignorecase(70) DEFAULT NULL, `top` tinyint(1) unsigned NOT NULL DEFAULT '0', `noindex` tinyint(1) unsigned NOT NULL DEFAULT '0', `stat_messages` int(10) unsigned NOT NULL DEFAULT '0', @@ -259,16 +260,16 @@ CREATE TABLE `tags` ( KEY (`synonym_id`) ); -CREATE TABLE `tags_ignore` ( +CREATE TABLE IF NOT EXISTS `tags_ignore` ( `tag_id` int(10) unsigned NOT NULL ); -CREATE TABLE `tags_synonyms` ( +CREATE TABLE IF NOT EXISTS `tags_synonyms` ( `name` char(64) NOT NULL, `changeto` char(64) NOT NULL ); -CREATE TABLE `telegram` ( +CREATE TABLE IF NOT EXISTS `telegram` ( `user_id` int(10) unsigned DEFAULT NULL, `tg_id` bigint(20) NOT NULL, `tg_name` char(64) NOT NULL, @@ -276,26 +277,26 @@ CREATE TABLE `telegram` ( `loginhash` char(36) DEFAULT NULL ); -CREATE TABLE `telegram_chats` ( +CREATE TABLE IF NOT EXISTS `telegram_chats` ( `chat_id` bigint(20) DEFAULT NULL, UNIQUE KEY `chat_id` (`chat_id`) ); -CREATE TABLE `top_ignore_messages` ( +CREATE TABLE IF NOT EXISTS `top_ignore_messages` ( `message_id` int(10) unsigned NOT NULL ); -CREATE TABLE `top_ignore_tags` ( +CREATE TABLE IF NOT EXISTS `top_ignore_tags` ( `tag_id` int(10) unsigned NOT NULL, PRIMARY KEY (`tag_id`) ); -CREATE TABLE `top_ignore_users` ( +CREATE TABLE IF NOT EXISTS `top_ignore_users` ( `user_id` int(10) unsigned NOT NULL, PRIMARY KEY (`user_id`) ); -CREATE TABLE `twitter` ( +CREATE TABLE IF NOT EXISTS `twitter` ( `user_id` int(10) unsigned NOT NULL, `access_token` char(64) NOT NULL, `access_token_secret` char(64) NOT NULL, @@ -305,11 +306,11 @@ CREATE TABLE `twitter` ( PRIMARY KEY (`user_id`) ); -CREATE TABLE `useroptions` ( +CREATE TABLE IF NOT EXISTS `useroptions` ( `user_id` int(10) unsigned NOT NULL, `jnotify` tinyint(1) NOT NULL DEFAULT '1', `subscr_active` tinyint(1) NOT NULL DEFAULT '1', - `off_ts` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `off_ts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `xmppxhtml` tinyint(1) NOT NULL DEFAULT '0', `subscr_notify` tinyint(1) NOT NULL DEFAULT '1', `recommendations` tinyint(1) NOT NULL DEFAULT '1', @@ -321,7 +322,7 @@ CREATE TABLE `useroptions` ( KEY `recommendations` (`recommendations`) ); -CREATE TABLE `users` ( +CREATE TABLE IF NOT EXISTS `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `nick` char(64) NOT NULL, `passw` char(32) NOT NULL, @@ -335,19 +336,19 @@ CREATE TABLE `users` ( UNIQUE KEY `nick` (`nick`) ); -CREATE TABLE `users_refs` ( +CREATE TABLE IF NOT EXISTS `users_refs` ( `user_id` int(10) unsigned NOT NULL, `ref` int(10) unsigned NOT NULL, KEY `ref` (`ref`) ); -CREATE TABLE `users_subscr` ( +CREATE TABLE IF NOT EXISTS `users_subscr` ( `user_id` int(10) unsigned NOT NULL, `cnt` smallint(5) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`) ); -CREATE TABLE `usersinfo` ( +CREATE TABLE IF NOT EXISTS `usersinfo` ( `user_id` int(10) unsigned NOT NULL, `jid` char(32) DEFAULT NULL, `fullname` char(32) DEFAULT NULL, @@ -359,11 +360,11 @@ CREATE TABLE `usersinfo` ( PRIMARY KEY (`user_id`) ); -CREATE TABLE `version` ( +CREATE TABLE IF NOT EXISTS `version` ( `version` bigint(20) NOT NULL ); -CREATE TABLE `vk` ( +CREATE TABLE IF NOT EXISTS `vk` ( `user_id` int(10) unsigned DEFAULT NULL, `vk_id` bigint(20) NOT NULL, `loginhash` char(36) DEFAULT NULL, @@ -375,7 +376,7 @@ CREATE TABLE `vk` ( KEY (`user_id`) ); -CREATE TABLE `winphone` ( +CREATE TABLE IF NOT EXISTS `winphone` ( `user_id` int(10) unsigned NOT NULL, `url` char(255) NOT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -383,7 +384,7 @@ CREATE TABLE `winphone` ( KEY (`user_id`) ); -CREATE TABLE `wl_users` ( +CREATE TABLE IF NOT EXISTS `wl_users` ( `user_id` int(10) unsigned NOT NULL, `wl_user_id` int(10) unsigned NOT NULL, PRIMARY KEY (`user_id`,`wl_user_id`) 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 deleted file mode 100644 index 5cbc2ca0..00000000 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.service; - -import com.juick.Message; -import com.juick.Tag; -import com.juick.User; -import com.juick.server.helpers.AnonymousUser; -import com.juick.server.helpers.TagStats; -import com.juick.util.MessageUtils; -import org.apache.commons.lang3.StringUtils; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.inject.Inject; -import java.sql.Timestamp; -import java.time.Instant; -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.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; - -/** - * Created by aalexeev on 11/25/16. - */ -@RunWith(SpringRunner.class) -public class MessageServiceTest extends AbstractJUnit4SpringContextTests { - @Inject - private MessagesService messagesService; - @Inject - private UserService userService; - @Inject - private SubscriptionService subscriptionService; - @Inject - private TagService tagService; - @Inject - private TelegramService telegramService; - @Inject - private JdbcTemplate jdbcTemplate; - @Inject - private CrosspostService crosspostService; - @Inject - private PMQueriesService pmQueriesService; - @Inject - private EmailService emailService; - - @MockBean - private ImagesService imagesService; - - static int ugnichId, freefdId, mid; - - private static boolean setUpIsDone = false; - - @Before - public void createUgniches() { - if (!setUpIsDone) { - ugnichId = userService.createUser("ugnich", "secret"); - freefdId = userService.createUser("freefd", "secret"); - setUpIsDone = true; - } - } - - @Test - public void getMyFeed() { - mid = messagesService.createMessage(ugnichId, "test", null, null); - int mid2 = messagesService.createMessage(ugnichId, "test2", null, null); - subscriptionService.subscribeUser(userService.getUserByUID(freefdId).orElse(AnonymousUser.INSTANCE), - userService.getUserByUID(ugnichId).orElse(AnonymousUser.INSTANCE)); - List<Integer> freefdFeed = messagesService.getMyFeed(freefdId, 0, false); - assertThat(freefdFeed.size(), equalTo(2)); - int tonyaid = userService.createUser("Tonya", "secret"); - int mid3 = messagesService.createMessage(tonyaid, "test3", null, null); - messagesService.recommendMessage(mid3, ugnichId); - assertThat(messagesService.getMyFeed(freefdId, 0, false).size(), equalTo(2)); - assertThat(messagesService.getMyFeed(freefdId, 0, true).size(), equalTo(3)); - assertThat(messagesService.getMyFeed(freefdId, mid2, true).size(), equalTo(1)); - assertThat(messagesService.getMyFeed(freefdId, mid, false).size(), equalTo(0)); - assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(MessagesService.RecommendStatus.Added)); - assertThat(messagesService.getMessage(mid).getLikes(), equalTo(1)); - assertThat(messagesService.recommendMessage(mid, ugnichId), equalTo(MessagesService.RecommendStatus.Deleted)); - assertThat(messagesService.getMessage(mid).getLikes(), equalTo(0)); - assertThat(messagesService.getAll(ugnichId, 0).size(), equalTo(3)); - - User ugnich = userService.getUserByUID(ugnichId).orElse(AnonymousUser.INSTANCE); - User freefd = userService.getUserByUID(freefdId).orElse(AnonymousUser.INSTANCE); - Tag yoTag = tagService.getTag("yoyo", true); - assertThat(tagService.getTag("YOYO", false), equalTo(yoTag)); - int mid = messagesService.createMessage(ugnichId, "yo", null, Collections.singletonList(yoTag)); - List<User> subscribers = subscriptionService.getSubscribedUsers(ugnichId, mid); - - telegramService.createTelegramUser(12345, "freefd"); - String loginhash = jdbcTemplate.queryForObject("SELECT loginhash FROM telegram where tg_id=?", - String.class, 12345); - crosspostService.setTelegramUser(loginhash, freefd.getUid()); - - List<Long> telegramSubscribers = telegramService.getTelegramIdentifiers(subscribers); - assertThat(subscribers.size(), equalTo(1)); - assertThat(subscribers.size(), equalTo(telegramSubscribers.size())); - assertThat(subscribers.get(0).getUid(), equalTo(freefd.getUid())); - tagService.blacklistTag(freefd, yoTag); - List<User> subscribers2 = subscriptionService.getSubscribedUsers(ugnichId, mid); - assertThat(subscribers2.size(), equalTo(0)); - assertThat(telegramService.getTelegramIdentifiers(subscribers2).size(), equalTo(0)); - tagService.blacklistTag(freefd, yoTag); - assertThat(subscriptionService.getSubscribedUsers(ugnichId, mid).size(), equalTo(1)); - } - @Test - public void pmTests() { - pmQueriesService.createPM(freefdId, ugnichId, "hello"); - Message pm = pmQueriesService.getPMMessages(ugnichId, freefdId).get(0); - 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); - assertThat(msg2.getTo(), equalTo(null)); - Message reply = messagesService.getReply(msg2.getMid(), rid); - assertThat(reply.getTo().getName(), equalTo(user.getName())); - List<Message> replies = messagesService.getReplies(msg2.getMid()); - assertThat(replies.size(), equalTo(1)); - assertThat(replies.get(0), equalTo(reply)); - int ridToReply = messagesService.createReply(msg2.getMid(), 1, ugnich_id, "blax2", null); - Message reply2 = messagesService.getReply(msg2.getMid(), ridToReply); - assertThat(reply.getTo().getName(), equalTo(user.getName())); - List<Message> replies2 = messagesService.getReplies(msg2.getMid()); - assertThat(replies2.size(), equalTo(2)); - assertThat(replies2.get(1), equalTo(reply2)); - Message msg3 = messagesService.getMessage(mid2); - assertEquals(2, 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(), user.getUid()); - subscriptionService.subscribeMessage(msg.getMid(), ugnich.getUid()); - int reply_id = messagesService.createReply(msg.getMid(), 0, ugnich_id, "comment", null); - assertEquals(1, subscriptionService.getUsersSubscribedToComments(msg, - messagesService.getReply(msg.getMid(), reply_id)).size()); - assertThat(messagesService.getDiscussions(ugnich.getUid(), Instant.now().toEpochMilli()).get(0), - equalTo(msg.getMid())); - 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, MessageUtils.getTagsString(msg4)); - messagesService.deleteMessage(user_id, mid4); - } - @Test - public void lastJidShouldNotBeDeleted() { - int ugnich_id = userService.createUser("hugnich2", "x"); - jdbcTemplate.update("INSERT INTO jids(user_id,jid,active) VALUES(?,?,?)", ugnich_id, "firstjid@localhost", 1); - jdbcTemplate.update("INSERT INTO jids(user_id,jid,active) VALUES(?,?,?)", ugnich_id, "secondjid@localhost", 1); - assertThat(userService.deleteJID(ugnich_id, "secondjid@localhost"), equalTo(true)); - assertThat(userService.deleteJID(ugnich_id, "firstjid@localhost"), equalTo(false)); - } - @Test - public void lastEmailShouldNotBeDeleted() { - int ugnich_id = userService.createUser("hugnich3", "x"); - jdbcTemplate.update("INSERT INTO emails(user_id,email) VALUES(?,?)", ugnich_id, "first@localhost"); - jdbcTemplate.update("INSERT INTO emails(user_id,email) VALUES(?,?)", ugnich_id, "second@localhost"); - assertThat(emailService.deleteEmail(ugnich_id, "second@localhost"), equalTo(true)); - assertThat(emailService.deleteEmail(ugnich_id, "first@localhost"), equalTo(false)); - } - @Test - public void messageUpdatedTimeShouldMatchLastReplyTime() throws InterruptedException { - int ugnich_id = userService.createUser("hugnich4", "x"); - int mid = messagesService.createMessage(ugnich_id, "yo", null, null); - Instant ts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?", - Timestamp.class, mid).toInstant(); - Thread.sleep(1000); - int rid = messagesService.createReply(mid, 0, ugnich_id, "people", null); - Instant rts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?", - Timestamp.class, mid).toInstant(); - assertThat(rts, greaterThan(ts)); - Message msg = messagesService.getReply(mid, rid); - assertThat(rts, equalTo(msg.getTimestamp())); - messagesService.deleteMessage(ugnich_id, mid); - } -} |