Skip to content

Commit

Permalink
AF-password||Resolved test cases and password java for exclusive max …
Browse files Browse the repository at this point in the history
…and min values update
  • Loading branch information
kum-sushil authored and dgurjar committed Sep 4, 2024
1 parent d5d4481 commit fdcdfb9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 },
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 40 additions & 4 deletions bundles/af-core/src/test/resources/form/password/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit fdcdfb9

Please sign in to comment.