From e5472f0edc02ddee19924c9a18dbe3b623e90991 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Mon, 23 Sep 2024 11:15:53 +0530 Subject: [PATCH 1/2] added fix for unit tests --- .../appsmith/server/imports/internal/ImportServiceTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index 8a742fa911d3..6c1d19ade726 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -902,7 +902,7 @@ public void importArtifactFromInvalidJsonFileWithoutArtifactTest() { .equals( AppsmithError.VALIDATION_FAILURE.getMessage( "Field '" + FieldName.APPLICATION - + "' Sorry! Seems like you've imported a page-level json instead of an application. Please use the import within the page."))) + + "'. Sorry! It seems you've imported a page-level JSON instead of an application. Please use the import within the page."))) .verify(); } From f59a3687d89d4e86a28c69fa7fec79190bc34ab3 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Mon, 23 Sep 2024 12:11:37 +0530 Subject: [PATCH 2/2] added a constant file --- .../server/constants/ImportExportConstants.java | 7 +++++++ .../imports/internal/ImportServiceCEImpl.java | 10 +++++----- .../imports/internal/ImportServiceTests.java | 14 ++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ImportExportConstants.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ImportExportConstants.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ImportExportConstants.java new file mode 100644 index 000000000000..5124c8002ec5 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ImportExportConstants.java @@ -0,0 +1,7 @@ +package com.appsmith.server.constants; + +public class ImportExportConstants { + + public static final String ARTIFACT_JSON_IMPORT_VALIDATION_ERROR_MESSAGE = + "'. Sorry! It seems you've imported a page-level JSON instead of an application. Please use the import within the page."; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java index e409f047288e..28353b7d1fd7 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java @@ -5,6 +5,7 @@ import com.appsmith.external.models.Datasource; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.constants.FieldName; +import com.appsmith.server.constants.ImportExportConstants; import com.appsmith.server.converters.ArtifactExchangeJsonAdapter; import com.appsmith.server.domains.Application; import com.appsmith.server.domains.Artifact; @@ -421,11 +422,10 @@ private Mono importArtifactInWorkspace( log.error("Error in importing {}. Field {} is missing", artifactContextString, errorField); if (errorField.equals(artifactContextString)) { - return Mono.error( - new AppsmithException( - AppsmithError.VALIDATION_FAILURE, - "Field '" + artifactContextString - + "'. Sorry! It seems you've imported a page-level JSON instead of an application. Please use the import within the page.")); + return Mono.error(new AppsmithException( + AppsmithError.VALIDATION_FAILURE, + "Field '" + artifactContextString + + ImportExportConstants.ARTIFACT_JSON_IMPORT_VALIDATION_ERROR_MESSAGE)); } return Mono.error(new AppsmithException( diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index 6c1d19ade726..38337a84be5a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -21,6 +21,7 @@ import com.appsmith.server.actioncollections.base.ActionCollectionService; import com.appsmith.server.applications.base.ApplicationService; import com.appsmith.server.constants.FieldName; +import com.appsmith.server.constants.ImportExportConstants; import com.appsmith.server.datasources.base.DatasourceService; import com.appsmith.server.domains.ActionCollection; import com.appsmith.server.domains.Application; @@ -895,14 +896,11 @@ public void importArtifactFromInvalidJsonFileWithoutArtifactTest() { importService.extractArtifactExchangeJsonAndSaveArtifact(filePart, workspaceId, null); StepVerifier.create(resultMono) - .expectErrorMatches( - throwable -> throwable instanceof AppsmithException - && throwable - .getMessage() - .equals( - AppsmithError.VALIDATION_FAILURE.getMessage( - "Field '" + FieldName.APPLICATION - + "'. Sorry! It seems you've imported a page-level JSON instead of an application. Please use the import within the page."))) + .expectErrorMatches(throwable -> throwable instanceof AppsmithException + && throwable + .getMessage() + .equals(AppsmithError.VALIDATION_FAILURE.getMessage("Field '" + FieldName.APPLICATION + + ImportExportConstants.ARTIFACT_JSON_IMPORT_VALIDATION_ERROR_MESSAGE))) .verify(); }