-
diff --git a/src/main/webapp/css/knowledge-edit.css b/src/main/webapp/css/knowledge-edit.css
index f34a5904e..229a07123 100644
--- a/src/main/webapp/css/knowledge-edit.css
+++ b/src/main/webapp/css/knowledge-edit.css
@@ -89,3 +89,10 @@
.tag_list > a {
text-decoration: none;
}
+
+.markdown_sample{
+ border: 2px solid silver;
+ padding: 5px;
+ height: 300px;
+ overflow: auto;
+}
diff --git a/src/main/webapp/js/knowledge-edit.js b/src/main/webapp/js/knowledge-edit.js
index 21c041cf2..ce6c5a4b4 100644
--- a/src/main/webapp/js/knowledge-edit.js
+++ b/src/main/webapp/js/knowledge-edit.js
@@ -184,15 +184,27 @@ $(document).ready(function() {
$('#emojiSymbolsModal').on('loaded.bs.modal', function (event) {
emojiSelect('#emojiSymbolsModal');
});
-
- $('#sampleMarkdownCheck').click(function() {
- var text = $('#sampleMarkdownText').val();
- var textarea = $('#content');
- textarea.val(text);
- preview();
- $('#helpMarkdownModal').modal('hide');
- var p = $("#preview").offset().top - 60;
- $('html,body').animate({ scrollTop: p }, 'fast');
+ $('#helpMarkdownModal').on('shown.bs.modal', function (event) {
+ $.post(_CONTEXT + '/open.knowledge/marked', {
+ title : 'Markdown Sample',
+ content : $('#sampleMarkdownText').val()
+ }, function(data) {
+ var html = '
';
+ var content = data.content;
+ html += content;
+ html += '
';
+
+ var jqObj = $('#markdownSamplePreview');
+ jqObj.html(html);
+ jqObj.find('code').addClass('hljs');
+ codeHighlight(jqObj)
+ .then(function() {
+ var content = emoji(jqObj.html().trim(), _CONTEXT + '/bower/emoji-parser/emoji', {classes: 'emoji-img'});
+ jqObj.html(content);
+ }).then(function () {
+ jqObj.find('a.oembed').oembed();
+ });
+ });
});
setUpTagSelect();
diff --git a/src/test/java/org/support/project/knowledge/TestCommon.java b/src/test/java/org/support/project/knowledge/TestCommon.java
index 440b4bf03..54d6db5b7 100644
--- a/src/test/java/org/support/project/knowledge/TestCommon.java
+++ b/src/test/java/org/support/project/knowledge/TestCommon.java
@@ -4,9 +4,16 @@
import java.io.IOException;
import java.util.List;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
import org.support.project.common.config.ConfigLoader;
import org.support.project.common.exception.SerializeException;
+import org.support.project.common.logic.H2DBServerLogic;
import org.support.project.common.serialize.SerializeUtils;
+import org.support.project.common.test.OrderedRunner;
import org.support.project.common.util.FileUtil;
import org.support.project.common.util.RandomUtil;
import org.support.project.knowledge.config.AppConfig;
@@ -15,58 +22,155 @@
import org.support.project.ormapping.tool.config.ORmappingToolConfig;
import org.support.project.ormapping.tool.dao.InitializeDao;
import org.support.project.web.bean.LoginedUser;
+import org.support.project.web.dao.GroupsDao;
import org.support.project.web.dao.RolesDao;
+import org.support.project.web.dao.UserGroupsDao;
+import org.support.project.web.dao.UserRolesDao;
import org.support.project.web.dao.UsersDao;
+import org.support.project.web.entity.GroupsEntity;
import org.support.project.web.entity.RolesEntity;
+import org.support.project.web.entity.UserGroupsEntity;
+import org.support.project.web.entity.UserRolesEntity;
import org.support.project.web.entity.UsersEntity;
-public class TestCommon {
- public static LoginedUser loginedUser = null;
- public static LoginedUser loginedUser2 = null;
-
- public static void testConnection() throws SerializeException, IOException {
- // コネクション設定
- String configFileName = "/ormappingtool.xml";
- ORmappingToolConfig config = SerializeUtils.bytesToObject(
- TestCommon.class.getResourceAsStream(configFileName),
- ORmappingToolConfig.class);
- config.getConnectionConfig().convURL();
- ConnectionManager.getInstance().addConnectionConfig(config.getConnectionConfig());
- }
-
- public static void initData() throws Exception {
- loginedUser = new LoginedUser();
- loginedUser2 = new LoginedUser();
-
- //DBを完全初期化
- InitializeDao initializeDao = InitializeDao.get();
- initializeDao.dropAllTable();
- InitDB.main(null);
- // 全文検索エンジンのインデックスの消去
- AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
- File indexDir = new File(appConfig.getIndexPath());
- FileUtil.delete(indexDir);
-
- // テスト用のユーザを登録
- UsersEntity entity = new UsersEntity();
- entity.setUserKey(RandomUtil.randamGen(64));
- entity.setUserName("テストユーザ");
- entity.setPassword(RandomUtil.randamGen(64));
- entity = UsersDao.get().insert(entity);
- loginedUser.setLoginUser(entity);
-
- RolesDao rolesDao = RolesDao.get();
- List
rolesEntities = rolesDao.selectOnUserKey(entity.getUserKey());
- loginedUser.setRoles(rolesEntities);
-
- UsersEntity entity2 = new UsersEntity();
- entity2.setUserKey(RandomUtil.randamGen(64));
- entity2.setUserName("テストユーザ2");
- entity2.setPassword(RandomUtil.randamGen(64));
- entity2 = UsersDao.get().insert(entity2);
- loginedUser2.setLoginUser(entity2);
- loginedUser.setRoles(rolesEntities);
- }
-
-
+/**
+ * Abstract class for test.
+ * @author Koda
+ *
+ */
+@RunWith(OrderedRunner.class)
+public abstract class TestCommon {
+ /** login user for test */
+ public static LoginedUser loginedUser = null;
+ /** login user for test */
+ public static LoginedUser loginedUser2 = null;
+ /** login user for test */
+ public static LoginedUser loginedUser3 = null;
+
+ /** group for test */
+ public static GroupsEntity group = null;
+ /** login user for test */
+ public static LoginedUser groupuser1 = null;
+ /** login user for test */
+ public static LoginedUser groupuser2 = null;
+
+
+ /**
+ * @BeforeClass
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ H2DBServerLogic.get().start();
+ testConnection();
+ initData();
+ }
+ /**
+ * @AfterClass
+ * @throws Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ H2DBServerLogic.get().stop();
+ }
+ /**
+ * @Before
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+ /**
+ * @After
+ * @throws Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * connection change for test
+ * @throws SerializeException
+ * @throws IOException
+ */
+ public static void testConnection() throws SerializeException, IOException {
+ // コネクション設定
+ String configFileName = "/ormappingtool.xml";
+ ORmappingToolConfig config = SerializeUtils.bytesToObject(TestCommon.class.getResourceAsStream(configFileName), ORmappingToolConfig.class);
+ config.getConnectionConfig().convURL();
+ ConnectionManager.getInstance().addConnectionConfig(config.getConnectionConfig());
+ }
+
+ /**
+ * Insert common data for test.
+ * @throws Exception
+ */
+ public static void initData() throws Exception {
+ loginedUser = new LoginedUser();
+ loginedUser2 = new LoginedUser();
+ loginedUser3 = new LoginedUser();
+ groupuser1 = new LoginedUser();
+ groupuser2 = new LoginedUser();
+
+ // DBを完全初期化
+ InitializeDao initializeDao = InitializeDao.get();
+ initializeDao.dropAllTable();
+ InitDB.main(null);
+ // 全文検索エンジンのインデックスの消去
+ AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
+ File indexDir = new File(appConfig.getIndexPath());
+ FileUtil.delete(indexDir);
+
+ Integer[] roles = {2}; // 2はユーザ、1はAdmin
+ addUser(loginedUser, "テストユーザ1", roles);
+ addUser(loginedUser2, "テストユーザ2", roles);
+ addUser(loginedUser3, "テストユーザ3", roles);
+
+ addUser(groupuser1, "GroupUser1", roles);
+ addUser(groupuser2, "GroupUser2", roles);
+
+ GroupsEntity groupsEntity = new GroupsEntity();
+ groupsEntity.setGroupName("テストグループ");
+ groupsEntity.setGroupKey("TestGroup");
+ group = GroupsDao.get().save(groupsEntity);
+
+ UserGroupsEntity usergroup = new UserGroupsEntity();
+ usergroup.setGroupId(group.getGroupId());
+ usergroup.setUserId(groupuser1.getUserId());
+ UserGroupsDao.get().save(usergroup);
+
+ usergroup = new UserGroupsEntity();
+ usergroup.setGroupId(group.getGroupId());
+ usergroup.setUserId(groupuser2.getUserId());
+ UserGroupsDao.get().save(usergroup);
+ }
+
+ /**
+ * テストユーザの情報を生成
+ * @param user
+ * @param userName
+ * @param roleIds
+ * @return
+ */
+ protected static List addUser(LoginedUser user, String userName, Integer[] roleIds) {
+ // テスト用のユーザを登録
+ UsersEntity entity = new UsersEntity();
+ entity.setUserKey(RandomUtil.randamGen(64));
+ entity.setUserName(userName);
+ entity.setPassword(RandomUtil.randamGen(64));
+ entity = UsersDao.get().insert(entity);
+ user.setLoginUser(entity);
+
+ RolesDao rolesDao = RolesDao.get();
+ for (Integer roleId : roleIds) {
+ UserRolesEntity role = new UserRolesEntity();
+ role.setRoleId(roleId);
+ role.setUserId(entity.getUserId());
+ UserRolesDao.get().save(role);
+ }
+ List rolesEntities = rolesDao.selectOnUserKey(entity.getUserKey());
+ user.setRoles(rolesEntities);
+ return rolesEntities;
+ }
+
}
diff --git a/src/test/java/org/support/project/knowledge/dao/KnowledgesDaoTest.java b/src/test/java/org/support/project/knowledge/dao/KnowledgesDaoTest.java
index d0137482e..aa8e44177 100644
--- a/src/test/java/org/support/project/knowledge/dao/KnowledgesDaoTest.java
+++ b/src/test/java/org/support/project/knowledge/dao/KnowledgesDaoTest.java
@@ -25,25 +25,7 @@
public class KnowledgesDaoTest extends TestCommon {
/** ログ */
private static Log LOG = LogFactory.getLog(KnowledgesDaoTest.class);
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- H2DBServerLogic.get().start();
- initData();
- }
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- H2DBServerLogic.get().stop();
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
+
@Test
public void testSelectKnowledges() throws Exception {
java.util.List knowledgeIds = new ArrayList();
diff --git a/src/test/java/org/support/project/knowledge/dao/NotifyConfigsDaoTest.java b/src/test/java/org/support/project/knowledge/dao/NotifyConfigsDaoTest.java
new file mode 100644
index 000000000..1fb31895c
--- /dev/null
+++ b/src/test/java/org/support/project/knowledge/dao/NotifyConfigsDaoTest.java
@@ -0,0 +1,151 @@
+package org.support.project.knowledge.dao;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.support.project.common.config.INT_FLAG;
+import org.support.project.common.test.AssertEx;
+import org.support.project.common.test.Order;
+import org.support.project.knowledge.TestCommon;
+import org.support.project.knowledge.entity.NotifyConfigsEntity;
+import org.support.project.web.entity.UsersEntity;
+
+/**
+ * 通知のDaoのテスト
+ * @author Koda
+ */
+public class NotifyConfigsDaoTest extends TestCommon {
+ private static final int LIMIT = 100;
+ private static final int OFFSET = 0;
+
+ @Test
+ @Order(order = 1)
+ public void testNotify1() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyDesktopUsersOnPublicComment(LIMIT, OFFSET);
+ AssertEx.eq(1, users.size());
+ }
+ @Test
+ @Order(order = 2)
+ public void testNotify2() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemIgnorePublic(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyDesktopUsersOnPublicComment(LIMIT, OFFSET);
+ AssertEx.eq(0, users.size());
+ }
+ @Test
+ @Order(order = 3)
+ public void testNotify3() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyDesktopUsersOnPublicComment(1, OFFSET);
+ AssertEx.eq(1, users.size());
+ AssertEx.eq(loginedUser.getUserId(), users.get(0).getUserId());
+ }
+ @Test
+ @Order(order = 4)
+ public void testNotify4() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyDesktopUsersOnPublicComment(1, 1);
+ AssertEx.eq(1, users.size());
+ AssertEx.eq(loginedUser2.getUserId(), users.get(0).getUserId());
+ }
+
+
+
+ @Test
+ @Order(order = 5)
+ public void testNotify5() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyMailUsersOnPublicComment(LIMIT, OFFSET);
+ AssertEx.eq(1, users.size());
+ }
+ @Test
+ @Order(order = 6)
+ public void testNotify6() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemIgnorePublic(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyMailUsersOnPublicComment(LIMIT, OFFSET);
+ AssertEx.eq(0, users.size());
+ }
+ @Test
+ @Order(order = 7)
+ public void testNotify7() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyMailUsersOnPublicComment(1, OFFSET);
+ AssertEx.eq(1, users.size());
+ AssertEx.eq(loginedUser.getUserId(), users.get(0).getUserId());
+ }
+ @Test
+ @Order(order = 8)
+ public void testNotify8() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ List users = NotifyConfigsDao.get().getNotifyMailUsersOnPublicComment(1, 1);
+ AssertEx.eq(1, users.size());
+ AssertEx.eq(loginedUser2.getUserId(), users.get(0).getUserId());
+ }
+
+}
diff --git a/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java b/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java
index c9552678b..1f85c8f5a 100644
--- a/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java
+++ b/src/test/java/org/support/project/knowledge/logic/KnowledgeLogicTest.java
@@ -28,28 +28,9 @@
public class KnowledgeLogicTest extends TestCommon {
/** ログ */
private static Log LOG = LogFactory.getLog(KnowledgeLogicTest.class);
-
private static List list = new ArrayList<>();
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- H2DBServerLogic.get().start();
- initData();
- }
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- H2DBServerLogic.get().stop();
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
@Test
@Order(order= 1)
public void testInsert() throws Exception {
diff --git a/src/test/java/org/support/project/knowledge/logic/MarkdownLogicTest.java b/src/test/java/org/support/project/knowledge/logic/MarkdownLogicTest.java
index c8a858210..e148e50a3 100644
--- a/src/test/java/org/support/project/knowledge/logic/MarkdownLogicTest.java
+++ b/src/test/java/org/support/project/knowledge/logic/MarkdownLogicTest.java
@@ -29,23 +29,6 @@
public class MarkdownLogicTest extends TestCommon {
/** ログ */
private static Log LOG = LogFactory.getLog(MarkdownLogicTest.class);
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
/**
* 改行コードは無視して値比較をするために、文字列(Line)の配列で取得
diff --git a/src/test/java/org/support/project/knowledge/logic/NotifyCommentLogicTest.java b/src/test/java/org/support/project/knowledge/logic/NotifyCommentLogicTest.java
new file mode 100644
index 000000000..1c3157a9b
--- /dev/null
+++ b/src/test/java/org/support/project/knowledge/logic/NotifyCommentLogicTest.java
@@ -0,0 +1,296 @@
+package org.support.project.knowledge.logic;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.support.project.common.config.INT_FLAG;
+import org.support.project.common.log.Log;
+import org.support.project.common.log.LogFactory;
+import org.support.project.common.test.Order;
+import org.support.project.knowledge.TestCommon;
+import org.support.project.knowledge.config.NotifyType;
+import org.support.project.knowledge.dao.CommentsDao;
+import org.support.project.knowledge.dao.NotifyConfigsDao;
+import org.support.project.knowledge.entity.CommentsEntity;
+import org.support.project.knowledge.entity.KnowledgesEntity;
+import org.support.project.knowledge.entity.NotifyConfigsEntity;
+import org.support.project.ormapping.common.DBUserPool;
+import org.support.project.web.bean.LabelValue;
+import org.support.project.web.entity.UsersEntity;
+
+/**
+ * Test for Notification logic.
+ * @author Koda
+ */
+public class NotifyCommentLogicTest extends TestCommon {
+ /** ログ */
+ private static Log LOG = LogFactory.getLog(NotifyCommentLogicTest.class);
+
+ /** テスト用ナレッジ1 */
+ private static KnowledgesEntity knowledge1;
+ /** テスト用ナレッジ2 */
+ private static KnowledgesEntity knowledge2;
+ /** テスト用ナレッジ3 */
+ private static KnowledgesEntity knowledge3;
+ /** テスト用ナレッジ4 */
+ private static KnowledgesEntity knowledge4;
+
+ /**
+ * @BeforeClass
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ TestCommon.setUpBeforeClass();
+ DBUserPool.get().setUser(loginedUser.getUserId());
+
+ LOG.info("テストユーザ1でKnowledge登録");
+ KnowledgesEntity knowledge = new KnowledgesEntity();
+ knowledge.setTitle("テスト1");
+ knowledge.setContent("テスト");
+ knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PUBLIC); // 公開
+ knowledge1 = KnowledgeLogic.get().insert(knowledge, null, null, null, null, null, loginedUser);
+
+ LOG.info("テストユーザ1でKnowledge登録");
+ knowledge = new KnowledgesEntity();
+ knowledge.setTitle("テスト2");
+ knowledge.setContent("テスト2");
+ knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PRIVATE); // 非公開
+ knowledge2 = KnowledgeLogic.get().insert(knowledge, null, null, null, null, null, loginedUser);
+
+ LOG.info("テストユーザ1でKnowledge登録");
+ knowledge = new KnowledgesEntity();
+ knowledge.setTitle("テスト3");
+ knowledge.setContent("テスト3");
+ knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PROTECT); // 非公開
+ List targets = new ArrayList<>();
+ LabelValue labelValue = new LabelValue();
+ labelValue.setLabel(TargetLogic.ID_PREFIX_USER + loginedUser2.getUserId());
+ labelValue.setValue(TargetLogic.ID_PREFIX_USER + loginedUser2.getUserId());
+ targets.add(labelValue);
+ knowledge3 = KnowledgeLogic.get().insert(knowledge, null, null, targets, null, null, loginedUser);
+
+ LOG.info("テストユーザ1でKnowledge登録");
+ knowledge = new KnowledgesEntity();
+ knowledge.setTitle("テスト4");
+ knowledge.setContent("テスト4");
+ knowledge.setPublicFlag(KnowledgeLogic.PUBLIC_FLAG_PROTECT); // 非公開
+ targets = new ArrayList<>();
+ labelValue = new LabelValue();
+ labelValue.setLabel(TargetLogic.ID_PREFIX_GROUP + group.getGroupId());
+ labelValue.setValue(TargetLogic.ID_PREFIX_GROUP + group.getGroupId());
+ targets.add(labelValue);
+ knowledge4 = KnowledgeLogic.get().insert(knowledge, null, null, targets, null, null, loginedUser);
+ }
+
+ @Test
+ @Order(order = 1)
+ public void testNotify1() throws Exception {
+ KnowledgesEntity knowledge = knowledge1;
+ // 公開のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertNull(user); // 通知設定がセットされていないので、通知先は無し
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertNull(user); // 通知設定がセットされていないので、通知先は無し
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+
+ knowledge = knowledge3;
+
+ // 保護のナレッジにコメント登録
+ comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertNull(user); // 通知設定がセットされていないので、通知先は無し
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertNull(user); // 通知設定がセットされていないので、通知先は無し
+
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ }
+
+
+
+
+ @Test
+ @Order(order = 2)
+ public void testNotify2() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setMyItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setMyItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser3.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setMyItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ KnowledgesEntity knowledge = knowledge1;
+
+ // 公開のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(2, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(2, users.size());
+ }
+
+
+ @Test
+ @Order(order = 3)
+ public void testNotify3() throws Exception {
+ KnowledgesEntity knowledge = knowledge2;
+ // 非公開のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertNull(user);
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertNull(user);
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ }
+
+ @Test
+ @Order(order = 4)
+ public void testNotify4() throws Exception {
+ KnowledgesEntity knowledge = knowledge3;
+ // 保護のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ }
+
+
+ @Test
+ @Order(order = 5)
+ public void testNotify5() throws Exception {
+ DBUserPool.get().setUser(loginedUser2.getUserId());
+ KnowledgesEntity knowledge = knowledge3;
+ // 保護のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ }
+
+
+ @Test
+ @Order(order = 6)
+ public void testNotify6() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(loginedUser2.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setMyItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.OFF.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ KnowledgesEntity knowledge = knowledge3;
+ // 公開のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(0, users.size());
+ }
+
+
+ @Test
+ @Order(order = 7)
+ public void testNotify7() throws Exception {
+ NotifyConfigsEntity notifyConfigs = new NotifyConfigsEntity();
+ notifyConfigs.setUserId(groupuser1.getUserId());
+ notifyConfigs.setNotifyMail(INT_FLAG.ON.getValue());
+ notifyConfigs.setNotifyDesktop(INT_FLAG.ON.getValue());
+ notifyConfigs.setMyItemComment(INT_FLAG.ON.getValue());
+ notifyConfigs.setToItemComment(INT_FLAG.ON.getValue());
+ NotifyConfigsDao.get().save(notifyConfigs);
+
+ KnowledgesEntity knowledge = knowledge4;
+ // 公開のナレッジにコメント登録
+ CommentsEntity comment = new CommentsEntity();
+ comment.setKnowledgeId(knowledge.getKnowledgeId());
+ CommentsDao.get().save(comment);
+
+ UsersEntity user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+ user = NotifyCommentLogic.get().getInsertUserOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(loginedUser.getUserId(), user.getUserId());
+
+ List users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Desktop, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ users = NotifyCommentLogic.get().getTargetUsersOnComment(NotifyType.Mail, comment, knowledge);
+ Assert.assertEquals(1, users.size());
+ }
+
+
+}
diff --git a/src/test/resources/ormappingtool.xml b/src/test/resources/ormappingtool.xml
index 050d552af..3365c3ddc 100644
--- a/src/test/resources/ormappingtool.xml
+++ b/src/test/resources/ormappingtool.xml
@@ -3,7 +3,7 @@
connection
org.h2.Driver
- jdbc:h2:~/.knowledge/knowledgeTestDB
+ jdbc:h2:tcp://localhost/./knowledgeTestDB
sa
public