From 54f9240c0898e28de491aa16a0b61f4498eaa1e3 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Fri, 24 Mar 2023 15:21:57 +0200 Subject: [PATCH] Fix tests --- .../org/thingsboard/server/controller/BaseController.java | 2 +- .../edge/rpc/processor/device/DeviceEdgeProcessor.java | 2 +- .../server/controller/BaseDeviceControllerTest.java | 2 +- .../server/controller/BaseTenantControllerTest.java | 2 +- .../service/entitiy/alarm/DefaultTbAlarmServiceTest.java | 6 +++--- .../java/org/thingsboard/server/common/data/EntityType.java | 3 ++- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java index 1cdc1062d0..a68955d9b4 100644 --- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java +++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java @@ -605,7 +605,7 @@ public abstract class BaseController { validateId((UUIDBased) entityId, "Invalid entity id"); SecurityUser user = getCurrentUser(); E entity = findingFunction.apply(user.getTenantId(), entityId); - checkNotNull(entity, entityId.getEntityType() + " with id [" + entityId + "] not found"); + checkNotNull(entity, entityId.getEntityType().getNormalName() + " with id [" + entityId + "] is not found"); return checkEntity(user, entity, operation); } catch (Exception e) { throw handleException(e, false); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java index 0d53c9bf9c..e26499aacc 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/device/DeviceEdgeProcessor.java @@ -87,7 +87,7 @@ public class DeviceEdgeProcessor extends BaseDeviceProcessor { return handleUnsupportedMsgType(deviceUpdateMsg.getMsgType()); } } catch (DataValidationException e) { - if (e.getMessage().contains("Can't create more then")) { + if (e.getMessage().contains("limit reached")) { log.warn("[{}] Number of allowed devices violated {}", tenantId, deviceUpdateMsg, e); return Futures.immediateFuture(null); } else { diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java index 6bb747cbfe..9b05b38a22 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java @@ -671,7 +671,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest { doPost("/api/device/credentials", deviceCredentials) .andExpect(status().isBadRequest()) - .andExpect(statusReason(containsString("Incorrect deviceId null"))); + .andExpect(statusReason(containsString("Invalid entity id"))); testNotifyEntityNever(deviceCredentials.getDeviceId(), new Device()); testNotificationUpdateGatewayNever(); diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java index 18dc371a80..2e42009e5b 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java @@ -511,7 +511,7 @@ public abstract class BaseTenantControllerTest extends AbstractControllerTest { for (Queue queue : foundTenantQueues) { doGet("/api/queues/" + queue.getId()) .andExpect(status().isNotFound()) - .andExpect(statusReason(containsString(msgErrorNotFound))); + .andExpect(statusReason(containsString(msgErrorNoFound("Queue", queue.getId().toString())))); } loginSysAdmin(); diff --git a/application/src/test/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmServiceTest.java b/application/src/test/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmServiceTest.java index 93aeb17de6..decefb6f90 100644 --- a/application/src/test/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/entitiy/alarm/DefaultTbAlarmServiceTest.java @@ -67,7 +67,7 @@ public class DefaultTbAlarmServiceTest { @MockBean protected AlarmService alarmService; @MockBean - protected AlarmCommentService alarmCommentService; + protected TbAlarmCommentService alarmCommentService; @MockBean protected AlarmSubscriptionService alarmSubscriptionService; @MockBean @@ -101,7 +101,7 @@ public class DefaultTbAlarmServiceTest { .thenReturn(AlarmApiCallResult.builder().successful(true).modified(true).build()); service.ack(alarm, new User(new UserId(UUID.randomUUID()))); - verify(alarmCommentService, times(1)).createOrUpdateAlarmComment(any(), any()); + verify(alarmCommentService, times(1)).saveAlarmComment(any(), any(), any()); verify(notificationEntityService, times(1)).notifyCreateOrUpdateAlarm(any(), any(), any()); verify(alarmSubscriptionService, times(1)).acknowledgeAlarm(any(), any(), anyLong()); } @@ -114,7 +114,7 @@ public class DefaultTbAlarmServiceTest { .thenReturn(AlarmApiCallResult.builder().successful(true).cleared(true).build()); service.clear(alarm, new User(new UserId(UUID.randomUUID()))); - verify(alarmCommentService, times(1)).createOrUpdateAlarmComment(any(), any()); + verify(alarmCommentService, times(1)).saveAlarmComment(any(), any(), any()); verify(notificationEntityService, times(1)).notifyCreateOrUpdateAlarm(any(), any(), any()); verify(alarmSubscriptionService, times(1)).clearAlarm(any(), any(), anyLong(), any()); } diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java b/common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java index a4b4c1e5fb..572dc16c0b 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/EntityType.java @@ -50,6 +50,7 @@ public enum EntityType { NOTIFICATION_RULE; @Getter - private final String normalName = StringUtils.capitalize(name().toLowerCase().replaceAll("_", " ")); + private final String normalName = StringUtils.capitalize(StringUtils.removeStart(name(), "TB_") + .toLowerCase().replaceAll("_", " ")); }