diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImpl.java index 48aef529db..d6588b987d 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImpl.java @@ -17,6 +17,7 @@ package com.adobe.cq.forms.core.components.internal.models.v1.form; import javax.annotation.Nullable; +import javax.annotation.PostConstruct; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; @@ -30,6 +31,7 @@ import com.adobe.cq.forms.core.components.internal.form.FormConstants; import com.adobe.cq.forms.core.components.models.form.Password; import com.adobe.cq.forms.core.components.util.AbstractFieldImpl; +import com.adobe.cq.forms.core.components.util.ComponentUtils; @Model( adaptables = { SlingHttpServletRequest.class, Resource.class }, @@ -40,6 +42,9 @@ extensions = ExporterConstants.SLING_MODEL_EXTENSION) public class PasswordImpl extends AbstractFieldImpl implements Password { + private Object exclusiveMinimumVaue; + private Object exclusiveMaximumValue; + @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) @Nullable private String validationPattern; @@ -70,23 +75,36 @@ public Long getMaximum() { } @Override - public Long getExclusiveMaximum() { - return exclusiveMaximum; + public String getFormat() { + return displayFormat; } @Override - public Long getExclusiveMinimum() { - return exclusiveMinimum; + public String getValidationPattern() { + return validationPattern; } @Override - public String getFormat() { - return displayFormat; + public Long getExclusiveMaximum() { + return (Long) exclusiveMaximumValue; } @Override - public String getValidationPattern() { - return validationPattern; + public Long getExclusiveMinimum() { + return (Long) exclusiveMinimumVaue; + } + + @PostConstruct + private void initTextInput() { + exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximum, null); + exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimum, null); + // in json either, exclusiveMaximum or maximum should be present + if (exclusiveMaximumValue != null) { + maximum = null; + } + if (exclusiveMinimumVaue != null) { + minimum = null; + } } } diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImplTest.java index 2ccc2f4803..cf75eed440 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v1/form/PasswordImplTest.java @@ -30,6 +30,7 @@ import io.wcm.testing.mock.aem.junit5.AemContextExtension; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; @ExtendWith(AemContextExtension.class) public class PasswordImplTest { @@ -38,6 +39,8 @@ public class PasswordImplTest { private static final String CONTENT_ROOT = "/content"; private static final String PATH_PASSWORD_DATALAYER = CONTENT_ROOT + "/password-datalayer"; private static final String PATH_PASSWORD_CUSTOMIZED = CONTENT_ROOT + "/password-customized"; + private static final String PATH_NUMBER_PASSWORD_EXCLUSIVE = CONTENT_ROOT + "/number-password-exclusive"; + private static final String PATH_NUMBER_PASSWORD_INPUT = CONTENT_ROOT + "/number-password"; private final AemContext context = FormsCoreComponentTestContext.newAemContext(); @@ -137,26 +140,28 @@ void testMaxLength() { @Test void testGetExclusiveMinimum() { - Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context); - assertEquals(8, password.getExclusiveMinimum().intValue()); + Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_EXCLUSIVE, Password.class, context); + assertNull(password.getMinimum()); + assertEquals(8L, password.getExclusiveMinimum().longValue()); } @Test void testGetExclusiveMaximum() { - Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context); - assertEquals(16, password.getExclusiveMaximum().intValue()); + Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_EXCLUSIVE, Password.class, context); + assertNull(password.getMaximum()); + assertEquals(16L, password.getExclusiveMaximum().longValue()); } @Test void testGetMinimum() { - Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context); - assertEquals(1, password.getMinimum().intValue()); + Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context); + assertEquals(8, password.getMinimum().intValue()); } @Test void testGetMaximum() { - Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context); - assertEquals(6, password.getMaximum().intValue()); + Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context); + assertEquals(16, password.getMaximum().intValue()); } @Test diff --git a/bundles/af-core/src/test/resources/form/password/exporter-password-customized.json b/bundles/af-core/src/test/resources/form/password/exporter-password-customized.json index 0222bd54e2..02bd02f46b 100644 --- a/bundles/af-core/src/test/resources/form/password/exporter-password-customized.json +++ b/bundles/af-core/src/test/resources/form/password/exporter-password-customized.json @@ -17,6 +17,10 @@ "readOnly": false, "minLength": 5, "maxLength": 10, + "maximum" : 16, + "minimum" : 1, + "exclusiveMinimum" : 8, + "exclusiveMaximum" : 16, "validationPattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/", "label": { "value": "Password", diff --git a/bundles/af-core/src/test/resources/form/password/test-content.json b/bundles/af-core/src/test/resources/form/password/test-content.json index 31c2c2f1e2..10748c1807 100644 --- a/bundles/af-core/src/test/resources/form/password/test-content.json +++ b/bundles/af-core/src/test/resources/form/password/test-content.json @@ -22,10 +22,6 @@ "required": true, "minLength": 5, "maxLength": 10, - "maximum" : 6, - "minimum" : 1, - "exclusiveMinimum":8, - "exclusiveMaximum":16, "displayFormat" : "password", "assistPriority" : "custom", "dataRef" : "a.b", @@ -41,6 +37,46 @@ "visible": true } }, + "number-password" : { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType" : "core/fd/components/form/textinput/v1/textinput", + "name" : "abc", + "type" : "password", + "jcr:title" : "def", + "hideTitle" : false, + "description" : "dummy", + "visible" : false, + "assistPriority" : "custom", + "dataRef" : "a.b", + "custom" : "Custom screen reader text", + "typeMessage" : "incorrect type", + "tooltip": "test-short-description", + "fieldType": "text-input", + "maximum" : 16, + "minimum" : 8, + "default" : 150 + }, + "number-password-exclusive" : { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType" : "core/fd/components/form/password/v1/password", + "name" : "abc", + "type" : "password", + "jcr:title" : "def", + "hideTitle" : false, + "description" : "dummy", + "visible" : false, + "assistPriority" : "custom", + "dataRef" : "a.b", + "custom" : "Custom screen reader text", + "typeMessage" : "incorrect type", + "tooltip": "test-short-description", + "fieldType": "text-input", + "maximum" : 16, + "minimum" : 8, + "exclusiveMinimum" : true, + "exclusiveMaximum" : true, + "default" : 150 + }, "password-format" : { "jcr:primaryType": "nt:unstructured", "sling:resourceType" : "core/fd/components/form/password/v1/password",