From b80069500bc2bcaf51842da4d22c20aebdf57dd5 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Fri, 13 Jan 2023 11:57:47 +0200 Subject: [PATCH] fixed unit tests --- .../controller/AbstractNotifyEntityTest.java | 6 ----- .../BaseAlarmCommentControllerTest.java | 24 +++++++------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java b/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java index 9653fdba33..672e55825b 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AbstractNotifyEntityTest.java @@ -340,12 +340,6 @@ public abstract class AbstractNotifyEntityTest extends AbstractWebTest { Mockito.argThat(matcherOriginatorId), Mockito.any(TbMsg.class), Mockito.isNull()); } - protected void testPushMsgToRuleEngineTime(EntityId matcherOriginatorId, TenantId tenantId, HasName entity, int cntTime) { - tenantId = tenantId.isNullUid() && ((HasTenantId) entity).getTenantId() != null ? ((HasTenantId) entity).getTenantId() : tenantId; - Mockito.verify(tbClusterService, times(cntTime)).pushMsgToRuleEngine(Mockito.eq(tenantId), - Mockito.eq(matcherOriginatorId), Mockito.any(TbMsg.class), Mockito.isNull()); - } - private void testNotificationMsgToEdgeServiceTime(EntityId entityId, TenantId tenantId, ActionType actionType, int cntTime) { EdgeEventActionType edgeEventActionType = ActionType.CREDENTIALS_UPDATED.equals(actionType) ? EdgeEventActionType.CREDENTIALS_UPDATED : edgeTypeByActionType(actionType); diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseAlarmCommentControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseAlarmCommentControllerTest.java index 4986eacb52..8aba871651 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseAlarmCommentControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseAlarmCommentControllerTest.java @@ -105,8 +105,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT AlarmComment createdComment = createAlarmComment(alarm.getId()); - testLogEntityAction(createdComment, createdComment.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED, 1); - testPushMsgToRuleEngineTime(createdComment.getId(), tenantId, createdComment, 1); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ADDED_COMMENT, 1, createdComment); } @Test @@ -118,8 +117,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT AlarmComment createdComment = createAlarmComment(alarm.getId()); Assert.assertEquals(AlarmCommentType.OTHER, createdComment.getType()); - testLogEntityAction(createdComment, createdComment.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED, 1); - testPushMsgToRuleEngineTime(createdComment.getId(), tenantId, createdComment, 1); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ADDED_COMMENT, 1, createdComment); } @Test @@ -138,8 +136,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT Assert.assertEquals("true", updatedAlarmComment.getComment().get("edited").asText()); Assert.assertNotNull(updatedAlarmComment.getComment().get("editedOn")); - testLogEntityAction(updatedAlarmComment, updatedAlarmComment.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.UPDATED, 1); - testPushMsgToRuleEngineTime(updatedAlarmComment.getId(), tenantId, updatedAlarmComment, 1); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.UPDATED_COMMENT, 1, savedComment); } @Test @@ -158,8 +155,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT Assert.assertEquals("true", updatedAlarmComment.getComment().get("edited").asText()); Assert.assertNotNull(updatedAlarmComment.getComment().get("editedOn")); - testLogEntityAction(updatedAlarmComment, updatedAlarmComment.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED, 1); - testPushMsgToRuleEngineTime(updatedAlarmComment.getId(), tenantId, updatedAlarmComment, 1); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.UPDATED_COMMENT, 1, updatedAlarmComment); } @Test @@ -177,7 +173,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT .andExpect(status().isForbidden()) .andExpect(statusReason(containsString(msgErrorPermission))); - testNotifyEntityNever(savedComment.getId(), savedComment); + testNotifyEntityNever(alarm.getId(), savedComment); } @Test @@ -195,11 +191,11 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT .andExpect(status().isForbidden()) .andExpect(statusReason(containsString(msgErrorPermission))); - testNotifyEntityNever(savedComment.getId(), savedComment); + testNotifyEntityNever(alarm.getId(), savedComment); } @Test - public void testDeleteAlarmViaCustomer() throws Exception { + public void testDeleteAlarmСommentViaCustomer() throws Exception { loginCustomerUser(); AlarmComment alarmComment = createAlarmComment(alarm.getId()); @@ -208,8 +204,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) .andExpect(status().isOk()); - testNotifyEntityOneTimeMsgToEdgeServiceNever(alarmComment, alarmComment.getId(), alarmComment.getId(), - tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, alarmComment); } @Test @@ -222,8 +217,7 @@ public abstract class BaseAlarmCommentControllerTest extends AbstractControllerT doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) .andExpect(status().isOk()); - testNotifyEntityOneTimeMsgToEdgeServiceNever(alarmComment, alarmComment.getId(), alarmComment.getId(), - tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED); + testLogEntityAction(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, alarmComment); } @Test