Class Start

    • 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. The AbstractComponent.getName() method will return the correct name after (order,int...) has been called.
    • Method Detail

      • getResourceType

        public String getResourceType()
        Description copied from class: AbstractComponent
        The resource type for the component, e.g. foundation/components/text. this will be set in the sling:resourceType property of the node.
        Specified by:
        getResourceType in class AbstractComponent
        Returns:
        the resource type
      • getCreateFormEntity

        public org.apache.sling.testing.clients.util.FormEntityBuilder getCreateFormEntity​(String order)
        Description copied from class: AbstractComponent
        Returns the FormEntityBuilder used for the create request in AbstractComponent.create(String,int...). This method can be overridden in a subclass to extend the parameters that need to sent with the creation request.
        Overrides:
        getCreateFormEntity in class AbstractComponent
        Parameters:
        order - Defines where the component should be added in relation to its siblings. Possible values are first, last, before [nodeName], after [nodeName].
        Returns:
        An FormEntityBuilder with _charset_,./sling:resourceType and :nameHint set.
      • 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:
        create in class AbstractComponent
        Parameters:
        order - Defines where the component should be added in relation to its siblings. Possible values are first, 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 fails
        InterruptedException - 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 fails
        InterruptedException - to mark this method as waiting
      • submit

        public void submit()
                    throws org.apache.sling.testing.clients.ClientException,
                           InterruptedException
        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
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • submit2

        public org.apache.sling.testing.clients.SlingHttpResponse submit2()
                                                                   throws org.apache.sling.testing.clients.ClientException,
                                                                          InterruptedException
        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
        Returns:
        the sling http response
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request fails
        InterruptedException - to mark this method as waiting
      • createMultipartEntity

        public org.apache.http.HttpEntity createMultipartEntity()
                                                         throws org.apache.sling.testing.clients.ClientException,
                                                                InterruptedException
        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. 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 fails
        InterruptedException - 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 when submit() 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 value
        value - 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