From 89ed3e9aff37d1a9c2c7e3b8ea92b18c9cf11b88 Mon Sep 17 00:00:00 2001 From: "angelo.andreussi" Date: Thu, 23 Jan 2025 11:45:19 +0100 Subject: [PATCH] fix: changed error message for foreign key constraint violations to support different datastores scenario and changed related tests --- .../org/eclipse/kapua/commons/util/KapuaExceptionUtils.java | 2 +- .../eclipse/kapua/commons/util/KapuaExceptionUtilsTest.java | 2 +- .../resources/features/authorization/DomainService.feature | 2 +- .../resources/features/connection/UserCouplingI9n.feature | 4 ++-- .../main/resources/kapua-service-error-messages.properties | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commons/src/main/java/org/eclipse/kapua/commons/util/KapuaExceptionUtils.java b/commons/src/main/java/org/eclipse/kapua/commons/util/KapuaExceptionUtils.java index 36513a61966..b35d82d8a1d 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/util/KapuaExceptionUtils.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/util/KapuaExceptionUtils.java @@ -103,7 +103,7 @@ public static KapuaException convertPersistenceException(Exception he) { break; default: { if (cve.getInternalException() instanceof SQLIntegrityConstraintViolationException) { - String message = cve.getMessage().contains("FOREIGN KEY") ? "Check if some foreign key relation exists between this entity and another one in the platform" : ""; + String message = cve.getMessage().contains("FOREIGN KEY") ? "This entity relates to other entities and cannot be deleted." : ""; ee = new KapuaSQLIntegrityConstraintViolationException(message); } } diff --git a/commons/src/test/java/org/eclipse/kapua/commons/util/KapuaExceptionUtilsTest.java b/commons/src/test/java/org/eclipse/kapua/commons/util/KapuaExceptionUtilsTest.java index d839c131df1..50b5cd82707 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/util/KapuaExceptionUtilsTest.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/util/KapuaExceptionUtilsTest.java @@ -117,7 +117,7 @@ public void convertPersistenceDatabaseExceptionTest() { SQLIntegrityConstraintViolationException mockedDatabaseException2 = Mockito.mock(SQLIntegrityConstraintViolationException.class); Mockito.when(mockedDatabaseException.getInternalException()).thenReturn(mockedDatabaseException2); Mockito.when(mockedDatabaseException.getMessage()).thenReturn("FOREIGN KEY"); - KapuaSQLIntegrityConstraintViolationException ke = new KapuaSQLIntegrityConstraintViolationException("Check if some foreign key relation exists between this entity and another one in the platform"); + KapuaSQLIntegrityConstraintViolationException ke = new KapuaSQLIntegrityConstraintViolationException("This entity relates to other entities and cannot be deleted."); Assert.assertEquals("ComparisonFailure not expected for: " + exception,ke.toString(), KapuaExceptionUtils.convertPersistenceException(exception).toString()); //generic SQL constraint violation diff --git a/qa/integration/src/test/resources/features/authorization/DomainService.feature b/qa/integration/src/test/resources/features/authorization/DomainService.feature index a2d2ee978ab..befc584a79e 100644 --- a/qa/integration/src/test/resources/features/authorization/DomainService.feature +++ b/qa/integration/src/test/resources/features/authorization/DomainService.feature @@ -70,7 +70,7 @@ Feature: Domain Service tests | test_name_1 | read,write | Then A domain was created And The domain matches the creator - Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "SQL integrity constraint violation!" + Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "Entity constraint violation error." When I create the domain | name | actions | | test_name_1 | read,write | diff --git a/qa/integration/src/test/resources/features/connection/UserCouplingI9n.feature b/qa/integration/src/test/resources/features/connection/UserCouplingI9n.feature index 61542fa7509..b60cefbe9a3 100644 --- a/qa/integration/src/test/resources/features/connection/UserCouplingI9n.feature +++ b/qa/integration/src/test/resources/features/connection/UserCouplingI9n.feature @@ -448,7 +448,7 @@ Feature: User Coupling And I set the reserved user for the connection from device "device-1" in account "test-acc-1" to "test-user-1" Then I set the user coupling mode for the connection from device "device-2" in account "test-acc-1" to "STRICT" # Try to set a duplicate reserved user - Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "SQL integrity constraint violation!" + Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "Entity constraint violation error." When I set the reserved user for the connection from device "device-2" in account "test-acc-1" to "test-user-1" Then An exception was thrown # Reserved users must be unique! @@ -873,7 +873,7 @@ Feature: User Coupling And I set the reserved user for the connection from device "device-1" in account "test-acc-1" to "test-user-1" Then I set the user coupling mode for the connection from device "device-2" in account "test-acc-1" to "STRICT" # Try to set a duplicate reserved user - Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "SQL integrity constraint violation!" + Given I expect the exception "KapuaSQLIntegrityConstraintViolationException" with the text "Entity constraint violation error." When I set the reserved user for the connection from device "device-2" in account "test-acc-1" to "test-user-1" Then An exception was thrown # Reserved users must be unique! diff --git a/service/api/src/main/resources/kapua-service-error-messages.properties b/service/api/src/main/resources/kapua-service-error-messages.properties index f9b0b65de3a..5e3dd6b1685 100644 --- a/service/api/src/main/resources/kapua-service-error-messages.properties +++ b/service/api/src/main/resources/kapua-service-error-messages.properties @@ -40,4 +40,4 @@ UNAUTHENTICATED=No authenticated Subject found in context. USER_ALREADY_RESERVED_BY_ANOTHER_CONNECTION=This user is already reserved for another connection. Please select different user for this connection. DEVICE_NOT_FOUND=The selected devices were not found. Please refresh device list. PARSING_ERROR=Error while parsing: {0} -SQL_INTEGRITY_VIOLATION=SQL integrity constraint violation! {0} \ No newline at end of file +SQL_INTEGRITY_VIOLATION=Entity constraint violation error. {0} \ No newline at end of file