Browse Source

Fix AlarmCommentControllerTest delete assertions for callSuper=true

The deprecation cleanup set @EqualsAndHashCode(callSuper = true) on AlarmComment,
so equals/hashCode now include the BaseData id and createdTime. The delete tests
built the expected comment via a fresh builder (no id), which no longer matches the
server-generated deletion comment (which reuses the original comment id).

Mutate the original alarm comment (already carrying the correct id/createdTime) into
the expected SYSTEM deletion comment instead of building a fresh one.
pull/15897/head
Oleksandra Matviienko 3 months ago
parent
commit
432262f358
  1. 48
      application/src/test/java/org/thingsboard/server/controller/AlarmCommentControllerTest.java

48
application/src/test/java/org/thingsboard/server/controller/AlarmCommentControllerTest.java

@ -226,15 +226,13 @@ public class AlarmCommentControllerTest extends AbstractControllerTest {
doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId())
.andExpect(status().isOk()); .andExpect(status().isOk());
AlarmComment expectedAlarmComment = AlarmComment.builder() alarmComment.setType(AlarmCommentType.SYSTEM);
.alarmId(alarm.getId()) alarmComment.setUserId(null);
.type(AlarmCommentType.SYSTEM) alarmComment.setComment(JacksonUtil.newObjectNode()
.comment(JacksonUtil.newObjectNode() .put("text", String.format(COMMENT_DELETED.getText(), CUSTOMER_USER_EMAIL))
.put("text", String.format(COMMENT_DELETED.getText(), CUSTOMER_USER_EMAIL)) .put("subtype", COMMENT_DELETED.name())
.put("subtype", COMMENT_DELETED.name()) .put("userName", CUSTOMER_USER_EMAIL));
.put("userName", CUSTOMER_USER_EMAIL)) testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, alarmComment);
.build();
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment);
} }
@Test @Test
@ -252,15 +250,13 @@ public class AlarmCommentControllerTest extends AbstractControllerTest {
loginTenantAdmin(); loginTenantAdmin();
doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId()) doDelete("/api/alarm/" + alarm.getId() + "/comment/" + alarmComment.getId())
.andExpect(status().isOk()); .andExpect(status().isOk());
AlarmComment expectedAlarmComment = AlarmComment.builder() alarmComment.setType(AlarmCommentType.SYSTEM);
.alarmId(alarm.getId()) alarmComment.setUserId(null);
.type(AlarmCommentType.SYSTEM) alarmComment.setComment(JacksonUtil.newObjectNode()
.comment(JacksonUtil.newObjectNode() .put("text", String.format(COMMENT_DELETED.getText(), TENANT_ADMIN_EMAIL))
.put("text", String.format(COMMENT_DELETED.getText(), TENANT_ADMIN_EMAIL)) .put("subtype", COMMENT_DELETED.name())
.put("subtype", COMMENT_DELETED.name()) .put("userName", TENANT_ADMIN_EMAIL));
.put("userName", TENANT_ADMIN_EMAIL)) testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, alarmComment);
.build();
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment);
} }
@Test @Test
@ -285,15 +281,13 @@ public class AlarmCommentControllerTest extends AbstractControllerTest {
assertThat(systemComment.getComment().get("text").asText()).isEqualTo(String.format("Comment was deleted by user %s", assertThat(systemComment.getComment().get("text").asText()).isEqualTo(String.format("Comment was deleted by user %s",
TENANT_ADMIN_EMAIL)); TENANT_ADMIN_EMAIL));
AlarmComment expectedAlarmComment = AlarmComment.builder() alarmComment.setType(AlarmCommentType.SYSTEM);
.alarmId(alarm.getId()) alarmComment.setUserId(null);
.type(AlarmCommentType.SYSTEM) alarmComment.setComment(JacksonUtil.newObjectNode()
.comment(JacksonUtil.newObjectNode() .put("text", String.format(COMMENT_DELETED.getText(), TENANT_ADMIN_EMAIL))
.put("text", String.format(COMMENT_DELETED.getText(), TENANT_ADMIN_EMAIL)) .put("subtype", COMMENT_DELETED.name())
.put("subtype", COMMENT_DELETED.name()) .put("userName", TENANT_ADMIN_EMAIL));
.put("userName", TENANT_ADMIN_EMAIL)) testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, alarmComment);
.build();
testLogEntityActionEntityEqClass(alarm, alarm.getId(), tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED_COMMENT, 1, expectedAlarmComment);
} }
@Test @Test

Loading…
Cancel
Save