Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dgurjar committed Nov 27, 2024
1 parent 5ef33dc commit a7b5e04
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.FieldType;
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;
Expand All @@ -47,11 +48,11 @@ public class PasswordImpl extends AbstractFieldImpl implements Password {

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private String validationPattern;
private String pattern;

@Override
public String getFieldType() {
return super.getFieldType();
return getFieldType(FieldType.PASSWORD);
}

@Override
Expand All @@ -64,34 +65,14 @@ public Integer getMaxLength() {
return maxLength;
}

@Override
public Long getMinimum() {
return minimum;
}

@Override
public Long getMaximum() {
return maximum;
}

@Override
public String getFormat() {
return displayFormat;
}

@Override
public String getValidationPattern() {
return validationPattern;
}

@Override
public Long getExclusiveMaximum() {
return (Long) exclusiveMaximumValue;
}

@Override
public Long getExclusiveMinimum() {
return (Long) exclusiveMinimumVaue;
public String getPattern() {
return pattern;
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public enum FieldType {
FORM("form"),
CHECKBOX_GROUP("checkbox-group"),
IMAGE("image"),

TELEPHONE("tel"),
PASSWORD("password"),
RANGE("range"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,9 @@
/**
* Interface for {@code Password} Sling Model used for the {@code /apps/core/fd/components/form/password/v1/password} component.
*
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
* @since com.adobe.cq.forms.core.components.models.form 5.9.6
*/
@ConsumerType
public interface Password extends Field, StringConstraint, NumberConstraint {

/**
* Returns the validation pattern (regex) for the password field.
*
* @return the validation pattern
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
*/
String getValidationPattern();
public interface Password extends Field, StringConstraint {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.adobe.cq.forms.core.components.internal.models.v1.form;

import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.TextInput;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -28,6 +30,7 @@
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand All @@ -39,8 +42,10 @@ 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 static final String PATH_PASSWORD = CONTENT_ROOT + "/password";

private static final String PATH_PASSWORD_PATTERN = CONTENT_ROOT + "/password-pattern";

private final AemContext context = FormsCoreComponentTestContext.newAemContext();

Expand All @@ -49,6 +54,21 @@ void setUp() {
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
}

@Test
void testExportedType() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(FormConstants.RT_FD_FORM_PASSWORD_V1, password.getExportedType());
TextInput textInputMock = Mockito.mock(TextInput.class);
Mockito.when(textInputMock.getExportedType()).thenCallRealMethod();
assertEquals("", textInputMock.getExportedType());
}

@Test
void testJSONExport() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_PATTERN, Password.class, context);
Utils.testJSONExport(password, Utils.getTestExporterJSONPath(BASE, PATH_PASSWORD));
}

@Test
void testFieldType() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
Expand Down Expand Up @@ -98,7 +118,7 @@ void testGetRequired() {
@Test
void testGetValidationPattern() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/", password.getValidationPattern());
assertEquals("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/", password.getPattern());

}

Expand Down Expand Up @@ -138,38 +158,18 @@ void testMaxLength() {
assertEquals(10, password.getMaxLength().intValue());
}

@Test
void testGetExclusiveMinimum() {
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_NUMBER_PASSWORD_EXCLUSIVE, Password.class, context);
assertNull(password.getMaximum());
assertEquals(16L, password.getExclusiveMaximum().longValue());
}

@Test
void testGetMinimum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context);
assertEquals(8, password.getMinimum().intValue());
}

@Test
void testGetMaximum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context);
assertEquals(16, password.getMaximum().intValue());
}

@Test
void testGetDisplayFormat() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password", password.getFormat());
}

@Test
void testGetPattern() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_PATTERN, Password.class, context);
assertEquals("^(?=.*\\d.*\\d)[A-Za-z\\d!@]+$", password.getPattern());
}

@Test
void testDataLayerProperties() throws IllegalAccessException {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_DATALAYER, Password.class, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"minimum" : 1,
"exclusiveMinimum" : 8,
"exclusiveMaximum" : 16,
"validationPattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"pattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"label": {
"value": "Password",
"visible": true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "password-1c7bc238a6",
"fieldType": "password",
"name": "Full Name",
"name": "password1732094911597",
"visible": true,
"description": "Enter Full Name",
"tooltip": "Full Name",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "password-91417957c6",
"fieldType": "password",
"name": "password1732174214265",
"visible": true,
"type": "string",
"enabled": true,
"readOnly": false,
"pattern": "^(?=.*\\d.*\\d)[A-Za-z\\d!@]+$",
"label": {
"value": ""
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
":type": "forms-components-examples/components/form/password",
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/password-pattern"
},
":type": "nt:unstructured"
}
70 changes: 30 additions & 40 deletions bundles/af-core/src/test/resources/form/password/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,44 @@
"typeMessage" : "incorrect type",
"tooltip": "test-short-description",
"placeholder": "Enter valid password",
"validationPattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"pattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"default" : "password",
"fieldType": "password",
"label": {
"value": "Password",
"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-pattern" : {
"id": "password-91417957c6",
"fieldType": "password",
"name": "password1732174214265",
"visible": true,
"type": "string",
"enabled": true,
"constraintMessages": {
"pattern": "Enter valid password"
},
"readOnly": false,
"pattern": "^(?=.*\\d.*\\d)[A-Za-z\\d!@]+$",
"label": {
"visible": true,
"value": "Password"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/forms/af/testcheckboaf2/jcr:content/guideContainer/password"
},
":type": "forms-components-examples/components/form/password"
},

"password-format" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "core/fd/components/form/password/v1/password",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Password"
fieldType="password"/>
jcr:title="Password"/>
Loading

0 comments on commit a7b5e04

Please sign in to comment.