diff --git a/manager/src/test/java/com/usthe/manager/dao/NoticeRuleDaoTest.java b/manager/src/test/java/com/usthe/manager/dao/NoticeRuleDaoTest.java index e078ccf30bb..7629ff27197 100644 --- a/manager/src/test/java/com/usthe/manager/dao/NoticeRuleDaoTest.java +++ b/manager/src/test/java/com/usthe/manager/dao/NoticeRuleDaoTest.java @@ -1,21 +1,76 @@ package com.usthe.manager.dao; -import com.usthe.manager.controller.NoticeConfigController; +import com.usthe.common.entity.manager.NoticeRule; +import com.usthe.manager.AbstractSpringIntegrationTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; -import static org.junit.jupiter.api.Assertions.*; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test case for {@link NoticeRuleDao} */ -class NoticeRuleDaoTest { +@Transactional +class NoticeRuleDaoTest extends AbstractSpringIntegrationTest { + + @Resource + private NoticeRuleDao noticeRuleDao; @BeforeEach void setUp() { + // insert notice rule with enable = true + NoticeRule enabled = NoticeRule.builder() + .name("mock notice rule") + .enable(true) + .filterAll(true) + .gmtCreate(LocalDateTime.now()) + .gmtUpdate(LocalDateTime.now()) + .modifier("mock") + .creator("mock") + .priorities(Collections.emptyList()) + .receiverId(1L) + .receiverName("mock receiver") + .tags(Collections.emptyList()) + .build(); + enabled = noticeRuleDao.saveAndFlush(enabled); + assertNotNull(enabled); + + // insert notice rule with enable = false + NoticeRule disabled = NoticeRule.builder() + .id(2L) + .name("mock notice rule") + .enable(false) + .filterAll(true) + .gmtCreate(LocalDateTime.now()) + .gmtUpdate(LocalDateTime.now()) + .modifier("mock") + .creator("mock") + .priorities(Collections.emptyList()) + .receiverId(1L) + .receiverName("mock receiver") + .tags(Collections.emptyList()) + .build(); + disabled = noticeRuleDao.saveAndFlush(disabled); + assertNotNull(disabled); + } + + @AfterEach + void tearDown() { + noticeRuleDao.deleteAll(); } @Test void findNoticeRulesByEnableTrue() { + List enabledList = noticeRuleDao.findNoticeRulesByEnableTrue(); + assertNotNull(enabledList); + assertEquals(1, enabledList.size()); } } \ No newline at end of file diff --git a/manager/src/test/java/com/usthe/manager/dao/ParamDaoTest.java b/manager/src/test/java/com/usthe/manager/dao/ParamDaoTest.java index db76805fcaa..094a30c4955 100644 --- a/manager/src/test/java/com/usthe/manager/dao/ParamDaoTest.java +++ b/manager/src/test/java/com/usthe/manager/dao/ParamDaoTest.java @@ -1,29 +1,104 @@ package com.usthe.manager.dao; -import com.usthe.manager.controller.NoticeConfigController; +import com.usthe.common.entity.manager.Param; +import com.usthe.manager.AbstractSpringIntegrationTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; -import static org.junit.jupiter.api.Assertions.*; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test case for {@link ParamDao} */ -class ParamDaoTest { +@Transactional +class ParamDaoTest extends AbstractSpringIntegrationTest { + + @Resource + private ParamDao paramDao; @BeforeEach void setUp() { + Param param = Param.builder() + .field("mock field") + .value("mock value") + .gmtCreate(LocalDateTime.now()) + .gmtUpdate(LocalDateTime.now()) + .monitorId(1L) + .type((byte) 1) + .build(); + + param = paramDao.saveAndFlush(param); + assertNotNull(param); + } + + @AfterEach + void tearDown() { + paramDao.deleteAll(); } @Test void findParamsByMonitorId() { + List paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(1L, paramList.size()); } @Test void deleteParamsByMonitorId() { + // make sure params size is correct + List paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(1L, paramList.size()); + + // delete params by monitor id when monitor id is wrong + paramDao.deleteParamsByMonitorId(2L); + paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(1L, paramList.size()); + + // delete params by monitor id when monitor id is true + paramDao.deleteParamsByMonitorId(1L); + paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(0L, paramList.size()); } @Test void deleteParamsByMonitorIdIn() { + // make sure params size is correct + List paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(1L, paramList.size()); + + // delete params by monitor id when monitor id is wrong + Set ids = new HashSet<>(); + ids.add(2L); + paramDao.deleteParamsByMonitorIdIn(ids); + paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(1L, paramList.size()); + + // delete params by monitor id when monitor id is true + ids.add(1L); + paramDao.deleteParamsByMonitorId(1L); + paramList = paramDao.findParamsByMonitorId(1L); + assertNotNull(paramList); + + assertEquals(0L, paramList.size()); } } \ No newline at end of file diff --git a/manager/src/test/java/com/usthe/manager/dao/ParamDefineDaoTest.java b/manager/src/test/java/com/usthe/manager/dao/ParamDefineDaoTest.java index 83be06c6433..774df90ef78 100644 --- a/manager/src/test/java/com/usthe/manager/dao/ParamDefineDaoTest.java +++ b/manager/src/test/java/com/usthe/manager/dao/ParamDefineDaoTest.java @@ -1,21 +1,65 @@ package com.usthe.manager.dao; -import com.usthe.manager.controller.NoticeConfigController; +import com.usthe.common.entity.manager.ParamDefine; +import com.usthe.manager.AbstractSpringIntegrationTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; -import static org.junit.jupiter.api.Assertions.*; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test case for {@link ParamDefineDao} */ -class ParamDefineDaoTest { +@Transactional +class ParamDefineDaoTest extends AbstractSpringIntegrationTest { + + @Resource + private ParamDefineDao paramDefineDao; @BeforeEach void setUp() { + ParamDefine paramDefine = ParamDefine.builder() + .app("mock app") + .field("mock field") + .defaultValue("mock default value") + .limit((short) 1) + .keyAlias("mock key alias") + .valueAlias("mock value alias") + .options(Collections.emptyList()) + .range("mock range") + .name(new HashMap<>()) + .hide(true) + .required(true) + .type("mock type") + .placeholder("mock placeholder") + .creator("mock creator") + .modifier("mock modifier") + .gmtCreate(LocalDateTime.now()) + .gmtUpdate(LocalDateTime.now()) + .build(); + + paramDefine = paramDefineDao.saveAndFlush(paramDefine); + assertNotNull(paramDefine); + } + + @AfterEach + void tearDown() { + paramDefineDao.deleteAll(); } @Test void findParamDefinesByApp() { + List paramDefineList = paramDefineDao.findParamDefinesByApp("mock app"); + assertNotNull(paramDefineList); + assertEquals(1, paramDefineList.size()); } } \ No newline at end of file diff --git a/manager/src/test/java/com/usthe/manager/dao/TagDaoTest.java b/manager/src/test/java/com/usthe/manager/dao/TagDaoTest.java index b50572129a8..f6d2d6d061e 100644 --- a/manager/src/test/java/com/usthe/manager/dao/TagDaoTest.java +++ b/manager/src/test/java/com/usthe/manager/dao/TagDaoTest.java @@ -1,21 +1,66 @@ package com.usthe.manager.dao; -import com.usthe.manager.controller.NoticeConfigController; +import com.usthe.common.entity.manager.Tag; +import com.usthe.manager.AbstractSpringIntegrationTest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.transaction.annotation.Transactional; -import static org.junit.jupiter.api.Assertions.*; +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test case for {@link TagDao} */ -class TagDaoTest { +@Transactional +class TagDaoTest extends AbstractSpringIntegrationTest { + + @Resource + private TagDao tagDao; @BeforeEach void setUp() { + Tag tag = Tag.builder() + .name("mock tag") + .value("mock value") + .color("mock color") + .type((byte) 1) + .creator("mock creator") + .modifier("mock modifier") + .gmtCreate(LocalDateTime.now()) + .gmtUpdate(LocalDateTime.now()) + .build(); + + tag = tagDao.saveAndFlush(tag); + assertNotNull(tag); + } + + @AfterEach + void tearDown() { + tagDao.deleteAll(); } @Test void deleteTagsByIdIn() { + List tagList = tagDao.findAll(); + + assertNotNull(tagList); + assertFalse(tagList.isEmpty()); + + Set ids = tagList.stream().map(Tag::getId).collect(Collectors.toSet()); + assertDoesNotThrow(() -> tagDao.deleteTagsByIdIn(ids)); + + tagList = tagDao.findAll(); + assertNotNull(tagList); + assertTrue(tagList.isEmpty()); } } \ No newline at end of file