Class Start
- java.lang.Object
-
- com.adobe.cq.testing.client.components.AbstractComponent
-
- com.adobe.cq.testing.client.components.foundation.form.Start
-
public class Start extends AbstractComponent
-
-
Field Summary
Fields Modifier and Type Field Description static CharsetCHARSET_UTF8static StringOPT_ACTION_TYPE_STOREstatic StringPROP_ACTION_STORE_CONTENT_PATHstatic StringPROP_ACTION_TYPEstatic StringPROP_CLIENT_VALIDATIONstatic StringPROP_FORM_IDstatic StringPROP_REDIRECTstatic StringPROP_VALIDATION_RTstatic StringPROP_WORKFLOWstatic StringRESOURCE_TYPE-
Fields inherited from class com.adobe.cq.testing.client.components.AbstractComponent
changeProperties, client, componentPath, DEFAULT_LOCATION, jsonNode, location, pagePath
-
-
Constructor Summary
Constructors Constructor Description Start(ComponentClient client, String pagePath, String location, String nameHint)The constructor stores all the component path information like parentPage, name etc.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.sling.testing.clients.SlingHttpResponsecreate(String order, int... expectedStatus)We override the default create call, so we can capture the reference to the end component.org.apache.http.HttpEntitycreateMultipartEntity()Create a MultiPartEntity out of the all the values of the Form components which are between this Start component and its End component in the page paragraph list.org.apache.sling.testing.clients.util.FormEntityBuildergetCreateFormEntity(String order)Returns the FormEntityBuilder used for the create request inAbstractComponent.create(String,int...).StringgetFormActionStore()Get the action property value (which is the action store content path) from this start component.EndgetFormEndComponent()Returns the end form component that belongs to this start component.StringgetFormId()Convenience method that returns the form idStringgetFormValue(String componentName)returns the string value set for this form elementStringgetResourceType()The resource type for the component, e.g.voidsetActionType(String actionTypeHandle)Defines what type of action should be executed upon form submission.voidsetClientValidation(boolean validate)Defines if the form should get validated client side before submissionvoidsetClientValidationResourceType(String resourceType)Defines a form validation resource type if you want to validate the entire form (instead of individual fields).voidsetFormActionStore(String contentPath)Sets action type to 'Store Content', and sets the 'Action' path where the data will get stored.voidsetFormId(String formId)Sets the form idvoidsetFormValueToSubmit(String componentName, Object value)The value we want to submit for a form field.voidsetRedirect(String pageHandle)Sets the handle for the redirect after form submit.voidsetWorkflowModel(String modelHandle)Set workflow model that should be started on form submission.voidsubmit()this method will 'emulate' the submit of this form by rebuilding the multipart/form-data request, collecting all the values from the form fields found between the start and end componentorg.apache.sling.testing.clients.SlingHttpResponsesubmit2()this method will 'emulate' the submit of this form by rebuilding the multipart/form-data request, collecting all the values from the form fields found between the start and end component-
Methods inherited from class com.adobe.cq.testing.client.components.AbstractComponent
getClient, getComponentNode, getComponentPath, getFirstChild, getLocation, getName, getNext, getNextNodePath, getPagePath, getParentPath, getPrevious, getPreviousNodePath, getProperty, getPropertyAsString, getPropertyAsStringArray, reorder, save, setProperty, setProperty
-
-
-
-
Field Detail
-
RESOURCE_TYPE
public static final String RESOURCE_TYPE
- See Also:
- Constant Field Values
-
PROP_REDIRECT
public static final String PROP_REDIRECT
- See Also:
- Constant Field Values
-
PROP_WORKFLOW
public static final String PROP_WORKFLOW
- See Also:
- Constant Field Values
-
PROP_ACTION_TYPE
public static final String PROP_ACTION_TYPE
- See Also:
- Constant Field Values
-
PROP_FORM_ID
public static final String PROP_FORM_ID
- See Also:
- Constant Field Values
-
PROP_CLIENT_VALIDATION
public static final String PROP_CLIENT_VALIDATION
- See Also:
- Constant Field Values
-
PROP_VALIDATION_RT
public static final String PROP_VALIDATION_RT
- See Also:
- Constant Field Values
-
OPT_ACTION_TYPE_STORE
public static final String OPT_ACTION_TYPE_STORE
- See Also:
- Constant Field Values
-
PROP_ACTION_STORE_CONTENT_PATH
public static final String PROP_ACTION_STORE_CONTENT_PATH
- See Also:
- Constant Field Values
-
CHARSET_UTF8
public static final Charset CHARSET_UTF8
-
-
Constructor Detail
-
Start
public Start(ComponentClient client, String pagePath, String location, String nameHint)
The constructor stores all the component path information like parentPage, name etc.- Parameters:
client- The ComponentClient that will be used for sending the requests.pagePath- path to the page that will contain the component.location- relative location to the parent node inside the page that will contain the component node.nameHint- name to be used for the component node. Might get altered by the server if a naming conflict occurs. TheAbstractComponent.getName()method will return the correct name after(order,int...)has been called.
-
-
Method Detail
-
getResourceType
public String getResourceType()
Description copied from class:AbstractComponentThe resource type for the component, e.g. foundation/components/text. this will be set in thesling:resourceTypeproperty of the node.- Specified by:
getResourceTypein classAbstractComponent- Returns:
- the resource type
-
getCreateFormEntity
public org.apache.sling.testing.clients.util.FormEntityBuilder getCreateFormEntity(String order)
Description copied from class:AbstractComponentReturns the FormEntityBuilder used for the create request inAbstractComponent.create(String,int...). This method can be overridden in a subclass to extend the parameters that need to sent with the creation request.- Overrides:
getCreateFormEntityin classAbstractComponent- Parameters:
order- Defines where the component should be added in relation to its siblings. Possible values arefirst,last,before [nodeName],after [nodeName].- Returns:
- An FormEntityBuilder with
_charset_,./sling:resourceTypeand:nameHintset.
-
create
public org.apache.sling.testing.clients.SlingHttpResponse create(String order, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException, InterruptedException
We override the default create call, so we can capture the reference to the end component. The end component is created right after the start component.- Overrides:
createin classAbstractComponent- Parameters:
order- Defines where the component should be added in relation to its siblings. Possible values arefirst,last,before [nodeName],after [nodeName].expectedStatus- list of expected HTTP Status to be returned, if not set, 201 is assumed.- Returns:
- Sling response
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
getFormEndComponent
public End getFormEndComponent()
Returns the end form component that belongs to this start component.- Returns:
- The end component for this start component
-
setRedirect
public void setRedirect(String pageHandle)
Sets the handle for the redirect after form submit. e.g. /content/site/thank_you- Parameters:
pageHandle- handle to redirect page
-
setWorkflowModel
public void setWorkflowModel(String modelHandle)
Set workflow model that should be started on form submission.- Parameters:
modelHandle- handle of of the workflow model
-
setActionType
public void setActionType(String actionTypeHandle)
Defines what type of action should be executed upon form submission. actions are implemented as components so this value must be a handle to a node in the repository that has sling:resourceType set to foundation/components/form/action.- Parameters:
actionTypeHandle- handle to the action component
-
setFormId
public void setFormId(String formId)
Sets the form id- Parameters:
formId- name for the form id
-
getFormId
public String getFormId()
Convenience method that returns the form id- Returns:
- the form id set, otherwise null
-
setClientValidation
public void setClientValidation(boolean validate)
Defines if the form should get validated client side before submission- Parameters:
validate- set true if client validation of form should occur.
-
setClientValidationResourceType
public void setClientValidationResourceType(String resourceType)
Defines a form validation resource type if you want to validate the entire form (instead of individual fields).- Parameters:
resourceType- the validation resource type
-
setFormActionStore
public void setFormActionStore(String contentPath)
Sets action type to 'Store Content', and sets the 'Action' path where the data will get stored.- Parameters:
contentPath- path where the data will be stored
-
getFormActionStore
public String getFormActionStore() throws org.apache.sling.testing.clients.ClientException, InterruptedException
Get the action property value (which is the action store content path) from this start component.- Returns:
- the action property value
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
submit
public void submit() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionthis method will 'emulate' the submit of this form by rebuilding the multipart/form-data request, collecting all the values from the form fields found between the start and end component- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
submit2
public org.apache.sling.testing.clients.SlingHttpResponse submit2() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionthis method will 'emulate' the submit of this form by rebuilding the multipart/form-data request, collecting all the values from the form fields found between the start and end component- Returns:
- the sling http response
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
createMultipartEntity
public org.apache.http.HttpEntity createMultipartEntity() throws org.apache.sling.testing.clients.ClientException, InterruptedExceptionCreate a MultiPartEntity out of the all the values of the Form components which are between this Start component and its End component in the page paragraph list. This MultiPartEntity is used to submit the form data to the server. Accepted as Form values are: - String for single value parameter if the parameter name is the same as the component name - String Array for multi value parameters if the parameter name is the same as the component name - File for File Uploads - Map of Strings for Form components which are sending several parameters (e.g Captcha)- Returns:
- the MultipartEntity with the Form values.
- Throws:
org.apache.sling.testing.clients.ClientException- if the request failsInterruptedException- to mark this method as waiting
-
setFormValueToSubmit
public void setFormValueToSubmit(String componentName, Object value)
The value we want to submit for a form field. The value is only submitted if the corresponding form field component still exists at time whensubmit()gets called and is located between the form start and end component. If the the value is not set or set to null at the time of submitting then the form field is not added at all. If set to an empty String, it will submitted as such.- Parameters:
componentName- the name of the form field component, associated with this valuevalue- the value send upon submit of the form
-
getFormValue
public String getFormValue(String componentName) throws org.apache.sling.testing.clients.ClientException
returns the string value set for this form element- Parameters:
componentName- component name- Returns:
- the string value set
- Throws:
org.apache.sling.testing.clients.ClientException- if the request fails
-
-