diff --git a/admin-console/src/main/java/com/agiletec/apsadmin/category/CategoryAction.java b/admin-console/src/main/java/com/agiletec/apsadmin/category/CategoryAction.java index f1f3f5814..3a2d507e4 100644 --- a/admin-console/src/main/java/com/agiletec/apsadmin/category/CategoryAction.java +++ b/admin-console/src/main/java/com/agiletec/apsadmin/category/CategoryAction.java @@ -115,10 +115,14 @@ private void checkTitles(boolean checkErrors) { this.getTitles().put(lang.getCode(), title.trim()); } if (checkErrors) { - if (null == title || title.trim().length() == 0) { + int maxLength = 70; + if (StringUtils.isBlank(title)) { String[] args = {lang.getDescr()}; this.addFieldError(titleKey, this.getText("error.category.insertTitle", args)); - } + } else if (null != title && title.trim().length() > maxLength) { + String[] args = {lang.getDescr(), String.valueOf(maxLength)}; + this.addFieldError(titleKey, this.getText("error.category.title.wrongTitleLength", args)); + } } } } diff --git a/admin-console/src/main/java/com/agiletec/apsadmin/category/package_en.properties b/admin-console/src/main/java/com/agiletec/apsadmin/category/package_en.properties index 35b1678be..09bf4cf1f 100644 --- a/admin-console/src/main/java/com/agiletec/apsadmin/category/package_en.properties +++ b/admin-console/src/main/java/com/agiletec/apsadmin/category/package_en.properties @@ -48,5 +48,6 @@ error.category.deleteWithChildren.notAllowed=Sorry. You can''t delete a category #VALIDATOR'S LABELS categoryCode=Category code error.category.insertTitle=Please provide a category title in ''{0}'' +error.category.title.wrongTitleLength=The field (''{0}'') Title is longer than ''{1}'' characters error.category.duplicateCode=A category with the code ''{0}'' already exists error.category.noParentSelected=No parent category selected! diff --git a/admin-console/src/main/java/com/agiletec/apsadmin/category/package_it.properties b/admin-console/src/main/java/com/agiletec/apsadmin/category/package_it.properties index f2fb057c1..9803a5cd3 100644 --- a/admin-console/src/main/java/com/agiletec/apsadmin/category/package_it.properties +++ b/admin-console/src/main/java/com/agiletec/apsadmin/category/package_it.properties @@ -48,5 +48,6 @@ error.category.deleteWithChildren.notAllowed=Non è consentita l''eliminaz #VALIDATOR'S LABELS categoryCode=Codice Categoria error.category.insertTitle=Titolo per lingua ''{0}'' è richiesto +error.category.title.wrongTitleLength=Il campo Titolo (''{0}'') ha più di ''{1}'' caratteri error.category.duplicateCode=Codice categoria ''{0}'' già presente error.category.noParentSelected=Nessuna categoria padre selezionata! diff --git a/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction-validation.xml b/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction-validation.xml index 15088c94e..58ed9c4da 100644 --- a/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction-validation.xml +++ b/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction-validation.xml @@ -27,12 +27,22 @@ + + 100 + true + + + + 100 + true + + diff --git a/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction.java b/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction.java index f049d6c80..8454c06e3 100644 --- a/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction.java +++ b/admin-console/src/main/java/com/agiletec/apsadmin/portal/WidgetTypeAction.java @@ -48,12 +48,7 @@ public class WidgetTypeAction extends AbstractPortalAction { public void validate() { super.validate(); try { - if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) { - WidgetType type = this.getWidgetType(this.getWidgetTypeCode()); - if (null != type) { - this.addFieldError("widgetTypeCode", this.getText("error.widgetType.guiRequired")); - } - } else if (this.getStrutsAction() == ApsAdminSystemConstants.PASTE) { + if (this.getStrutsAction() == ApsAdminSystemConstants.PASTE) { this.checkWidgetToCopy(); } else if (this.getStrutsAction() == NEW_USER_WIDGET) { this.checkNewUserWidget(); diff --git a/admin-console/src/test/java/com/agiletec/apsadmin/category/TestCategoryAction.java b/admin-console/src/test/java/com/agiletec/apsadmin/category/TestCategoryAction.java index 7cff7dfc4..9d5426e5e 100644 --- a/admin-console/src/test/java/com/agiletec/apsadmin/category/TestCategoryAction.java +++ b/admin-console/src/test/java/com/agiletec/apsadmin/category/TestCategoryAction.java @@ -91,7 +91,7 @@ public void testViewTree() throws Throwable { } public void testValidateAddCategory_1() throws Throwable { - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("parentCategoryCode", this._categoryManager.getRoot().getCode()); params.put("strutsAction", "1"); params.put("categoryCode", ""); @@ -108,7 +108,7 @@ public void testValidateAddCategory_1() throws Throwable { public void testValidateAddCategory_2() throws Throwable { String categoryCode = "veryLongCategoryCode_veryLongCategoryCode"; assertNull(this._categoryManager.getCategory(categoryCode)); - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("parentCategoryCode", this._categoryManager.getRoot().getCode()); params.put("strutsAction", "1"); params.put("categoryCode", categoryCode);//long category code @@ -123,7 +123,7 @@ public void testValidateAddCategory_2() throws Throwable { public void testValidateAddCategory_3() throws Throwable { assertNotNull(this._categoryManager.getCategory("evento")); - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("parentCategoryCode", this._categoryManager.getRoot().getCode()); params.put("strutsAction", "1"); params.put("categoryCode", "evento");//duplicate Code @@ -140,7 +140,7 @@ public void testValidateAddCategory_4() throws Throwable { String categoryCode = "cat_temp2"; assertNull(this._categoryManager.getCategory(categoryCode)); try { - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("parentCategoryCode", this._categoryManager.getRoot().getCode()); params.put("strutsAction", "1"); params.put("categoryCode", categoryCode); @@ -151,6 +151,15 @@ public void testValidateAddCategory_4() throws Throwable { Map> fieldErrors = this.getAction().getFieldErrors(); assertEquals(1, fieldErrors.size()); assertEquals(1, fieldErrors.get("langen").size()); + + String longCategoryTitle = "Titolo di lunghezza maggiore di 70 caratteri - abcdefghi lmnopq rstuvz 1234567890"; + params.put("langen", "Category title"); + params.put("langit", longCategoryTitle); + result = this.executeSaveCategory("admin", params); + assertEquals(Action.INPUT, result); + fieldErrors = this.getAction().getFieldErrors(); + assertEquals(1, fieldErrors.size()); + assertEquals(1, fieldErrors.get("langit").size()); } catch (Throwable t) { this._categoryManager.deleteCategory(categoryCode); assertNotNull(this._categoryManager.getCategory(categoryCode)); diff --git a/admin-console/src/test/java/com/agiletec/apsadmin/portal/TestWidgetTypeAction.java b/admin-console/src/test/java/com/agiletec/apsadmin/portal/TestWidgetTypeAction.java index 5611831cd..f967a5230 100644 --- a/admin-console/src/test/java/com/agiletec/apsadmin/portal/TestWidgetTypeAction.java +++ b/admin-console/src/test/java/com/agiletec/apsadmin/portal/TestWidgetTypeAction.java @@ -35,6 +35,7 @@ import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import java.util.Arrays; +import java.util.Collections; import org.entando.entando.aps.system.services.guifragment.GuiFragment; import org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager; @@ -50,6 +51,63 @@ protected void setUp() throws Exception { this.init(); } + public void testFailureAdd_1() throws Throwable { + String[] invalidCodes = new String[]{null, "", "Code_longher_than_40_characters_1234567890", + "Code_With_Special%$_characters", "Code with spaces", "entando_apis" /* already exists */}; + for (int i = 0; i < invalidCodes.length; i++) { + String invalidCode = invalidCodes[i]; + try { + String result = this.execute(invalidCode, "italian title", + "english title", "admin", null, "*GUI*", ApsAdminSystemConstants.ADD); + assertEquals(Action.INPUT, result); + assertEquals(1, this.getAction().getFieldErrors().size()); + assertEquals(1, this.getAction().getFieldErrors().get("widgetTypeCode").size()); + } catch (Throwable t) { + if (!invalidCode.equals("entando_apis")) { + this.cleanDatabase(invalidCode); + } + throw t; + } + } + } + + public void testFailureAdd_2() throws Throwable { + String widgetTypeCode = "test_widgetType_add_1"; + assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode)); + List fragmentCodes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode); + assertEquals(0, fragmentCodes.size()); + String[] invalidTitles = new String[]{null, "", String.join("", Collections.nCopies(30, "test "))}; + for (int i = 0; i < invalidTitles.length; i++) { + String invalidTitle = invalidTitles[i]; + try { + String result = this.execute(widgetTypeCode, "italian title", + invalidTitle, "admin", null, "*GUI*", ApsAdminSystemConstants.ADD); + assertEquals(Action.INPUT, result); + assertEquals(1, this.getAction().getFieldErrors().size()); + assertEquals(1, this.getAction().getFieldErrors().get("englishTitle").size()); + } catch (Throwable t) { + this.cleanDatabase(widgetTypeCode); + throw t; + } + } + } + + public void testFailureAdd_3() throws Throwable { + String widgetTypeCode = "test_widgetType_add_2"; + assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode)); + List fragmentCodes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode); + assertEquals(0, fragmentCodes.size()); + try { + String result = this.execute(widgetTypeCode, "italian title", + "english title", "admin", null, "", ApsAdminSystemConstants.ADD); + assertEquals(Action.INPUT, result); + assertEquals(1, this.getAction().getFieldErrors().size()); + assertEquals(1, this.getAction().getFieldErrors().get("gui").size()); + } catch (Throwable t) { + this.cleanDatabase(widgetTypeCode); + throw t; + } + } public void testFailureUpdateTitles() throws Throwable { String result = this.executeUpdate("content_viewer", "italian title", "english title", "editorCustomers", "*GUI*"); assertEquals("userNotAllowed", result); @@ -160,7 +218,7 @@ public void testUpdate_3() throws Throwable { this.cleanDatabase(widgetTypeCode); } } - + private void cleanDatabase(String widgetTypeCode) throws Throwable { List fragmentCodes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode); if (null != fragmentCodes) { @@ -174,7 +232,7 @@ private void cleanDatabase(String widgetTypeCode) throws Throwable { } assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode)); } - + public void testFailureTrashType_1() throws Throwable { String result = this.executeTrash("content_viewer", "editorCustomers"); assertEquals("userNotAllowed", result); @@ -263,7 +321,7 @@ public void testTrashType() throws Throwable { assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode)); } } - + private String executeJoinWidget(String pageCode, int frame, String widgetTypeCode, String username) throws Throwable { this.setUserOnSession(username); this.initAction("/do/Page", "joinWidget"); @@ -287,13 +345,18 @@ private String executeUpdate(String widgetTypeCode, String italianTitle, String private String executeUpdate(String widgetTypeCode, String italianTitle, String englishTitle, String username, ApsProperties properties, String gui) throws Throwable { + return this.execute(widgetTypeCode, italianTitle, englishTitle, username, properties, gui, ApsAdminSystemConstants.EDIT); + } + + private String execute(String widgetTypeCode, String italianTitle, String englishTitle, + String username, ApsProperties properties, String gui, int strutsAction) throws Throwable { this.setUserOnSession(username); this.initAction("/do/Portal/WidgetType", "save"); this.addParameter("widgetTypeCode", widgetTypeCode); this.addParameter("italianTitle", italianTitle); this.addParameter("englishTitle", englishTitle); this.addParameter("gui", gui); - this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT); + this.addParameter("strutsAction", String.valueOf(strutsAction)); if (null != properties) { this.addParameters(properties); } @@ -334,7 +397,7 @@ private WidgetType createNewLogicWidgetType(String code) { type.setConfig(config); return type; } - + public void testCopyWidgetType() throws Throwable { String result = this.executeCopyWidgetType("editorCustomers", "customers_page", "2"); assertEquals("userNotAllowed", result); @@ -351,7 +414,7 @@ public void testCopyWidgetType() throws Throwable { result = this.executeCopyWidgetType("admin", "pagina_2", "2"); assertEquals(Action.SUCCESS, result); } - + private String executeCopyWidgetType(String username, String pageCode, String framePos) throws Throwable { this.setUserOnSession(username); this.initAction("/do/Portal/WidgetType", "copy"); @@ -360,7 +423,7 @@ private String executeCopyWidgetType(String username, String pageCode, String fr this.addParameter("strutsAction", ApsAdminSystemConstants.PASTE); return this.executeAction(); } - + public void testNewWidgetType() throws Throwable { String result = this.executeNewUserWidgetType("editorCustomers", "content_viewer_list"); assertEquals("userNotAllowed", result); @@ -610,7 +673,7 @@ public void testAddNewWidgetType() throws Throwable { this._widgetTypeManager.deleteWidgetType(widgetTypeCode); } } - + // private String executePasteUserWidgetType(String username, String code, String englishTitle, String italianTitle, String pageCode, String framePos) throws Throwable {