Class MockEntityService


  • public class MockEntityService
    extends CayenneService
    Provides service to generate persistent TM entities for use in Groovy Unit Tests.
    Since:
    4.3.0
    • Constructor Detail

      • MockEntityService

        public MockEntityService()
    • Method Detail

      • setFormType

        public MockEntityService setFormType​(String formType)
        Set the form type.
        Parameters:
        formType - the form type
        Returns:
        the mock entity service
        Since:
        17.10.0
      • setForm

        public MockEntityService setForm​(Form form)
        Set the form to be used when creating submission entities.
        Parameters:
        form - the form record
        Returns:
        the mock entity service
        Since:
        17.10.0
      • setFormHttpApi2

        public MockEntityService setFormHttpApi2​(boolean formHttpApi2)
        Set the form template version to use the Form HTTP API 2.
        Parameters:
        formHttpApi2 - specify whether to use the Form HTTP API 2
        Returns:
        the mock entity service
        Since:
        17.10.0
      • setPortal

        public MockEntityService setPortal​(Portal portal)
        Set the portal to be used when creating submission entities.
        Parameters:
        portal - the portal record
        Returns:
        the mock entity service
        Since:
        17.10.0
      • setTestName

        public MockEntityService setTestName​(String testName)
        Set the test name used for creating entities.
        Parameters:
        testName - the test name used for creating entities
        Returns:
        the mock entity service
        Since:
        17.10.0
      • createProject

        public Project createProject​(Client client,
                                     String name)
        Create project with given name for a client.
        Parameters:
        client - client
        name - project name
        Returns:
        project with given name for a client
        Since:
        17.10.0
      • createPortal

        public Portal createPortal​(String name)
        Create forms Portal with the given name and of type 'Web Plugin'.
        Parameters:
        name - the name of the portal
        Returns:
        forms Portal with the given name and of type 'Web Plugin'
      • createClient

        public Client createClient​(String name)
        Create a client with the given name.
        Parameters:
        name - the name of the client.
        Returns:
        a client with the given name
      • createClient

        public Client createClient​(String name,
                                   String code)
        Create a client with the given name and code.
        Parameters:
        name - the name of the client.
        code - the code of the client.
        Returns:
        a client with the given name and code
        Since:
        5.1.4
      • getOrCreateClient

        public Client getOrCreateClient​(String testName)
        Get the current client if executing in GroovyScript Unit Test context with a client defined, or create a new test client otherwise.
        Parameters:
        testName - the test name for the client
        Returns:
        a existing client or create a new test client
        Since:
        5.1.7
      • createCategory

        public Category createCategory​(Client client,
                                       String name,
                                       String description)
        Create a category.
        Parameters:
        client - the client (required)
        name - the name (required)
        description - the description (optional)
        Returns:
        the category
        Since:
        18.11.0
      • addCategoryToVersion

        public FormCategory addCategoryToVersion​(TemplateVersion formVersion,
                                                 Category category)
        Add a category to a form version.
        Parameters:
        formVersion - the form version (required)
        category - the category (required)
        Returns:
        the form category
        Since:
        18.11.0
      • createPropertyType

        public PropertyType createPropertyType​(String name,
                                               String scope,
                                               String dataType,
                                               Client client)
        Create a property type, optionally associated with a client
        Parameters:
        name - the property name
        scope - the scope (e.g. PropertyType.SCOPE_Client)
        dataType - the data type (e.g. PropertyType.DATA_TYPE_String)
        client - the client that the property type belongs to (optional)
        Returns:
        the property type
      • createClientProperty

        public ClientProperty createClientProperty​(Client client,
                                                   PropertyType propertyType,
                                                   String value)
        Create a client property value for a client and property type.
        Parameters:
        client - the client (required)
        propertyType - the property type (required)
        value - the value
        Returns:
        the client property value
      • createPortalProperty

        public PortalProperty createPortalProperty​(Portal portal,
                                                   String name,
                                                   String dataType,
                                                   String value)
        Create a portal property value.
        Parameters:
        portal - the portal (required)
        name - the property name (required)
        dataType - the data type (required)
        value - the value
        Returns:
        the portal property value
        Since:
        5.1.4
      • createVersionProperty

        public VersionPropertyValue createVersionProperty​(TemplateVersion version,
                                                          PropertyType propertyType,
                                                          String value)
        Create a version property value for a form version and property type. Note that this method doesn't support properties without an associated property type.
        Parameters:
        version - the form version (required)
        propertyType - the property type (required)
        value - the value
        Returns:
        the version property value
      • createUserProperty

        public UserProperty createUserProperty​(UserProfile userProfile,
                                               PropertyType propertyType,
                                               String value)
        Create a user property value for a user profile and property type.
        Parameters:
        userProfile - the user profile (required)
        propertyType - the property type (required)
        value - the value
        Returns:
        the user property value
      • createApplicationPackage

        public ApplicationPackage createApplicationPackage​(String name,
                                                           Client client)
        Create an application package with the given name and client
        Parameters:
        name - the application name
        client - the owning client
        Returns:
        a new application package
      • createTPac

        public TPac createTPac​(String projectCode,
                               Client client)
        Create a tpac with the given code and client
        Parameters:
        projectCode - the project code
        client - the owning client
        Returns:
        a new manage package
        Since:
        17.10.0
      • createServiceDefinition

        public ServiceDefinition createServiceDefinition​(String name,
                                                         String versionNumber,
                                                         String serviceType,
                                                         String className,
                                                         Client client)
        Create an active service definition with the given name, version number, type, class and optionally client This method sets the active flag and potentially the current version flag (if no other version of the same service exists) Other settings have to be set on the service definition after creation, e.g. type default flag, service connection and parameters.
        Parameters:
        name - the name (required)
        versionNumber - the version number (required)
        serviceType - the service type (required)
        className - the class that the service is based on (required)
        client - the client (optional)
        Returns:
        the service definition
        Since:
        5.1.7
      • createServiceParameter

        public ServiceParameter createServiceParameter​(ServiceDefinition serviceDefinition,
                                                       String name,
                                                       String type,
                                                       boolean bindParameterFlag,
                                                       boolean unitTestFlag,
                                                       String value)
        Create a service parameter
        Parameters:
        serviceDefinition - the service that the parameter belongs to (required)
        name - the parameter name (required)
        type - the data type (required)
        bindParameterFlag - whether the parameter should be bound to an attribute on the service class
        unitTestFlag - whether the parameter is related to unit testing
        value - the parameter value (optional)
        Returns:
        the service parameter
        Since:
        17.10.0
      • createForm

        public Form createForm​(String formCode,
                               Client client,
                               Portal portal)
        Create a new form with the given formCode, client and portal.
        Parameters:
        formCode - the form code
        client - the owning client
        portal - the associated portal
        Returns:
        a new form with the given formCode, client and portal
      • createForm

        public Form createForm​(String formCode,
                               Client client,
                               Collection<Portal> portals)
        Create a new form with the given formCode, client and portal. Note: This method will create a ClientPortal for any portals not already associated with the client.
        Parameters:
        formCode - the form code (required)
        client - the owning client (required)
        portals - the portals (required)
        Returns:
        a new form with the given formCode, client and portal
        Since:
        18.5.0
      • createDataExtractMapping

        public SchemaExtractMap createDataExtractMapping​(SchemaSeed schemaSeed,
                                                         String name,
                                                         String xpath,
                                                         int sequenceNumber)
        Create a data extract mapping for the given schema seed.
        Parameters:
        schemaSeed - the schema seed (required)
        name - the name (required)
        xpath - the XPath (required)
        sequenceNumber - the sequence number (required)
        Returns:
        the data extract mapping
        Since:
        18.11.0
      • createFormGroup

        public Group createFormGroup​(String name)
        Create a new form group with the given name. The created form group will have the following access control policies:
         Form Work Group: true
         Completed Form:  true
         New Form:        true
         Saved Form:      true
         Task Assign:     true
         
        Parameters:
        name - the group name
        Returns:
        a new form group with the given name.
        Since:
        4.3.4
      • createJobGroup

        public Group createJobGroup​(String name)
        Create a new job group with the given name.
        Parameters:
        name - the group name
        Returns:
        a new job group with the given name.
        Since:
        17.10.0
      • createGroup

        public Group createGroup​(String name,
                                 String type)
        Create a new group with the given name and type.
        Parameters:
        name - the group name (required)
        type - the group type (required)
        Returns:
        a new group with the given name and type.
        Since:
        18.11.0
      • addUserToGroup

        public UserGroup addUserToGroup​(Group group,
                                        UserAccount userAccount,
                                        Date expiryDatetime)
        Create a user group association.
        Parameters:
        group - the group (required)
        userAccount - the user (required)
        expiryDatetime - the time at which the group association will become invalid (optional)
        Returns:
        the user group
        Since:
        18.11.0
      • createPaymentLog

        public PaymentLog createPaymentLog​(Submission sub)
        Create a payment log entity.
        Parameters:
        sub - the submission record (required)
        Returns:
        a peyment log entity
        Since:
        19.5.0
      • createSecurityManager

        public SecurityManager createSecurityManager()
        Create a default local Security Manager entity.
        Returns:
        a default local Security Manager entity
      • createSubmissionDataBean

        public SubmissionDataBean createSubmissionDataBean​(String formXmlData)
        Create a SubmissionDataBean from the given form XML data.

        A backing submission record will be created with the status values:

         Form Status:     Submitted
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the submission form XML data (required)
        Returns:
        a SubmissionDataBean
      • createSubmissionOpened

        public Submission createSubmissionOpened()
        Create a opened Submission entity. This is useful for mocking up Dynamic Data calls. The submission record will have the status values:
         Form Status:     Opened
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Returns:
        a opened Submission entity
      • createSubmissionOpened

        public Submission createSubmissionOpened​(Client client)
        Create a opened Submission entity with the given client. This is useful for mocking up Dynamic Data calls. The submission record will have the status values:
         Form Status:     Opened
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        client - the test client (required)
        Returns:
        a opened Submission entity
        Since:
        5.0.0
      • createSubmissionSavedWithXml

        public Submission createSubmissionSavedWithXml​(String formXmlData)
        Create a saved Submission entity with the given XML form data. The submission record will have the status values:
         Form Status:     Saved
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        Returns:
        a saved Submission entity with the given XML form data
      • createSubmissionSavedWithXml

        public Submission createSubmissionSavedWithXml​(String formXmlData,
                                                       Client client)
        Create a saved Submission entity with the given XML form data and client. The submission record will have the status values:
         Form Status:     Saved
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        client - the test client (required)
        Returns:
        a saved Submission entity with the given XML form data
        Since:
        5.0.0
      • createSubmissionTaskWithXml

        public Submission createSubmissionTaskWithXml​(String formXmlData)
        Create an assigned Submission form task entity with the given XML form data. The submission record will have the status values:
         Form Status:     Assigned
         Task Type:       Form
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        Returns:
        a assigned Submission form task entity with the given XML form data
        Since:
        4.3.4
      • createSubmissionTaskWithXml

        public Submission createSubmissionTaskWithXml​(String formXmlData,
                                                      Client client)
        Create an assigned Submission form task entity with the given XML form data and client. The submission record will have the status values:
         Form Status:     Assigned
         Task Type:       Form
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        client - the test client (required)
        Returns:
        a assigned Submission form task entity with the given XML form data
        Since:
        5.0.0
      • createSubmissionSubmittedWithXml

        public Submission createSubmissionSubmittedWithXml​(String formXmlData)
        Create a submitted Submission entity with the given XML form data. The submission record will have the status values:
         Form Status:     Submitted
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionSubmittedWithXml

        public Submission createSubmissionSubmittedWithXml​(String formXmlData,
                                                           Client client)
        Create a submitted Submission entity with the given XML form data and client. The submission record will have the status values:
         Form Status:     Submitted
         Receipt Status:  null
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        client - the test client (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionSubmittedWithFormAndXml

        public Submission createSubmissionSubmittedWithFormAndXml​(Form form,
                                                                  String formXmlData)
        Create a submitted Submission entity with the given form and XML form data. The submission record will have the status values:
         Form Status:     Submitted
         Receipt Status:  null
         Delivery Status: Not Ready
         

        If the form has form data extract mappings configured, then submission data extracts will be created against the submission.

        Parameters:
        form - the form associated with the submission (required)
        formXmlData - the form XML data for the submission (required)
        Returns:
        a submitted Submission entity with the given XML form data
        Since:
        5.0.0
      • createSubmissionCompletedWithXml

        public Submission createSubmissionCompletedWithXml​(String formXmlData)
        Create a completed Submission entity with the given XML form data. The submission record will have the status values:
         Form Status:     Completed
         Receipt Status:  Ready
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionCompletedWithXml

        public Submission createSubmissionCompletedWithXml​(String formXmlData,
                                                           Client client)
        Create a completed Submission entity with the given XML form data and client. The submission record will have the status values:
         Form Status:     Completed
         Receipt Status:  Ready
         Delivery Status: Not Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        client - the test client (required)
        Returns:
        a completed Submission entity with the given XML form data
        Since:
        5.0.0
      • createSubmissionWithClientStatusXml

        public Submission createSubmissionWithClientStatusXml​(Client client,
                                                              String formStatus,
                                                              String formXmlData)
        Create a Submission entity with the given client, form status and XML form data.
        Parameters:
        client - the test client (required)
        formStatus - the submission form status (required)
        formXmlData - the form XML data for the submission (required)
        Returns:
        the new submission
        Since:
        17.10.3
      • createSubmissionCompletedWithFormAndXml

        public Submission createSubmissionCompletedWithFormAndXml​(Form form,
                                                                  String formXmlData)
        Create a completed Submission entity with the given form and XML form data. The submission record will have the status values:
         Form Status:     Completed
         Receipt Status:  Ready
         Delivery Status: Not Ready
         

        If the form has form data extract mappings configured, then submission data extracts will be created against the submission.

        Parameters:
        form - the form associated with the submission (required)
        formXmlData - the form XML data for the submission (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionDeliveryReadyWithXml

        public Submission createSubmissionDeliveryReadyWithXml​(String formXmlData)
        Create a completed Submission entity with the given form and XML form data. The submission record will have the status values:
         Form Status:     Completed
         Receipt Status:  Completed
         Delivery Status: Ready
         
        Parameters:
        formXmlData - the form XML data for the submission (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionDeliveryReadyWithFormAndXml

        public Submission createSubmissionDeliveryReadyWithFormAndXml​(Form form,
                                                                      String formXmlData)
        Create a completed Submission entity with the given form and XML form data. The submission record will have the status values:
         Form Status:     Completed
         Receipt Status:  Completed
         Delivery Status: Ready
         

        If the form has form data extract mappings configured, then submission data extracts will be created against the submission.

        Parameters:
        form - the form associated with the submission (required)
        formXmlData - the form XML data for the submission (required)
        Returns:
        a completed Submission entity with the given XML form data
      • createSubmissionProperty

        public SubmissionProperty createSubmissionProperty​(Submission submission,
                                                           String name,
                                                           String value)
        Create a non-encrypted submission property.
        Parameters:
        submission - the submission (required)
        name - the property name (required)
        value - the property value (optional)
        Returns:
        the submission property
        Since:
        18.11.0
      • createSubmissionDataStorageService

        public ServiceDefinition createSubmissionDataStorageService()
        Create a default database submission data storage service.
        Returns:
        a default database submission data storage service
      • createUserLocal

        public UserAccount createUserLocal()
        Create a test local user with a random login name.
        Returns:
        a new a test local user with a random login name.
        Since:
        5.0.0
      • createUserLocal

        public UserAccount createUserLocal​(Portal portal)
        Create a test local user with a random login name.
        Parameters:
        portal - the portal to assign to the user.
        Returns:
        a new a test local user with a random login name.
        Since:
        17.10.0
      • createUserSso

        public UserAccount createUserSso()
        Create a test SSO user account with a random login name.
        Returns:
        a new a test SSO user account with a random login name.
        Since:
        5.0.0
      • createUserSso

        public UserAccount createUserSso​(String loginName,
                                         Portal portal)
        Creates a SSO user with a given loginName and portal
        Parameters:
        loginName - the login name for the user
        portal - the portal to assign to the user
        Returns:
        the created SSO user
        Since:
        17.10.0
      • addClientToUser

        public ClientUser addClientToUser​(UserAccount userAccount,
                                          Client client)
        Add a client to the specified user account This method does NOT check if the user already has that client.
        Parameters:
        userAccount - the user account (required)
        client - the client (required)
        Returns:
        the new ClientUser object
      • addClientToPortal

        public ClientPortal addClientToPortal​(Client client,
                                              Portal portal)
        Add a client to the specified portal This method does NOT check if the portal already has that client.
        Parameters:
        client - the client (required)
        portal - the portal (required)
        Returns:
        the new ClientPortal object
        Since:
        17.10.0
      • addPortalToUser

        public PortalUser addPortalToUser​(UserAccount userAccount,
                                          Portal portal)
        Add a portal to the specified user account This method does NOT check if the user already has that portal.
        Parameters:
        userAccount - the user account (required)
        portal - the portal (required)
        Returns:
        the new PortalUser object
        Since:
        5.1.4
      • createJobInProgress

        public Job createJobInProgress​(Client client)
        Create an Job for the given client with an 'In Progress' status.
        Parameters:
        client - the client owning the job (required)
        Returns:
        the job entity
      • createJobInProgress

        public Job createJobInProgress​(Client client,
                                       String formXml)
        Create an Job for the given client with an 'In Progress' status.
        Parameters:
        client - the client owning the job (required)
        formXml - the form XML data of the job start transaction (optional)
        Returns:
        the job entity
        Since:
        17.10.4
      • createJobWithGroupInProgress

        public Job createJobWithGroupInProgress​(Client client,
                                                String formXml)
        Create a Job with a group for the given client with an 'In Progress' status.
        Parameters:
        client - the client owning the job (required)
        formXml - the form XML data of the job start transaction (optional)
        Returns:
        the job entity
        Since:
        21.11.0
      • createJobWithFormXml

        public Job createJobWithFormXml​(Client client,
                                        String jobDefJson,
                                        Form form,
                                        String formXmlData)
        Create a mock collaboration job for the given jobDefinition and Client
        Parameters:
        client - the Client owning the job (required)
        jobDefJson - the job definition as a JSON String
        form - the mock Form entity
        formXmlData - the form XML (String)
        Returns:
        the created job entity
        Since:
        17.10.0
      • createJobWithSubmission

        public Job createJobWithSubmission​(Client client,
                                           String jobDefJson,
                                           Submission submission)
        Create a mock collaboration job for the given jobDefinition and Client
        Parameters:
        client - the Client owning the job (required)
        jobDefJson - the job definition as a JSON String
        submission - the Jobs start submission
        Returns:
        the created job entity
        Since:
        17.10.0
      • createJobServiceDefinition

        public ServiceDefinition createJobServiceDefinition​(Client client,
                                                            String svcName,
                                                            String svcVersion)
        Create JobController Service Definition
        Parameters:
        client - the Client owning the job (required)
        svcName - the service name (required)
        svcVersion - the service version (required)
        Returns:
        the jobControllerService if the jobDefJson
        Since:
        18.11.0
      • createTrackingNumberServie

        public ServiceDefinition createTrackingNumberServie()
        Create a default tracking number service.
        Returns:
        a default tracking number service
      • createDataRetentionManagementService

        public ServiceDefinition createDataRetentionManagementService()
        Create a default data retention management service.
        Returns:
        a default data retention management service
      • createEmailService

        public ServiceDefinition createEmailService()
        Create a default unit test email service (TrashCanEmailService).
        Returns:
        a unit test email service
        Since:
        5.0.0
      • loadCoreConfiguration

        public MockEntityService loadCoreConfiguration()
        Load core server configuration for stand alone build time JUnit Testing. IMPORTANT NOTE this method should not be called in a running TM server.
        Returns:
        this mock entity service
      • createRandomTestName

        public String createRandomTestName()
        Returns:
        a random test name.
        Since:
        5.0.0
      • createRequest

        public MockRequest createRequest​(Submission submission)
        Create a mock request for the given submission object.
        Parameters:
        submission - the submission object (required)
        Returns:
        a mock HTTP request object
        Since:
        17.10.0
      • createSubmissionWithStatusesAndXml

        public Submission createSubmissionWithStatusesAndXml​(Form form,
                                                             String formStatus,
                                                             String receiptStatus,
                                                             String deliveryStatus,
                                                             String formXmlData)
        Create a mock request for the given submission object.
        Parameters:
        form - the form to create the submission form
        formStatus - the submission formStatus
        receiptStatus - the submission receiptStatus
        deliveryStatus - the submission deliveryStatus
        formXmlData - the submission formXmlData
        Returns:
        a mock submission
        Since:
        17.10.4
      • createDeploymentProperty

        public void createDeploymentProperty​(String propertyName,
                                             Boolean isSet)
        Create a boolean DeploymentProperty.
        Parameters:
        propertyName - the name of the deployment property
        isSet - the boolean value to set the property with.
        Since:
        17.10.0
      • addPortalPermission

        public Permission addPortalPermission​(String permissionName,
                                              Portal portal)
        Add a permission for a portal, if it doesn't already exist.
        Parameters:
        permissionName - the permission name (required)
        portal - the portal (required)
        Returns:
        the permission
        Since:
        17.10.6
      • addRoleToUser

        public UserRole addRoleToUser​(UserAccount userAccount,
                                      Role role,
                                      Date roleExpiryDatetime)
        Add a role to a user, with an optional expiry time. No validation is done as to whether the role is already assigned.
        Parameters:
        userAccount - the user (required)
        role - the role (required)
        roleExpiryDatetime - the expiry date/time (optional)
        Returns:
        the newly created user role
        Since:
        17.10.6
      • addFormToGroup

        public void addFormToGroup​(Form form,
                                   Group group)
        Add a form to a group. No validation is done on whether the form already has the group.
        Parameters:
        form - the form (required)
        group - the group (required)
      • createRole

        public Role createRole​(String roleName,
                               Set<Permission> permissionSet)
        Create an active role with the given name and permissions.
        Parameters:
        roleName - the role name (required)
        permissionSet - the set of permissions to include (can be empty but not null)
        Returns:
        the new role
        Since:
        17.10.6
      • grantFormPortalAccess

        public FormPortal grantFormPortalAccess​(Form form,
                                                Portal portal,
                                                boolean allowAnonymousAccess,
                                                boolean allowAuthenticatedAccess)
        Creates or updates the form portal association and sets the anonymous/authenticated access flags as specified. After this method completes, the form will be associated with the portal (it does not matter if that was the case previously). Note: This may also add the portal to the client, if necessary.
        Parameters:
        form - the form (required)
        portal - the portal (required)
        allowAnonymousAccess - whether to grant access to anonymous users
        allowAuthenticatedAccess - whether to grant access to authenticated users
        Returns:
        the form portal entity
        Since:
        18.11.0
      • createPermission

        public Permission createPermission​(String permissionName,
                                           Portal portal)
        Create a permission with the given name and portal.
        Parameters:
        permissionName - the permission name (required)
        portal - the portal (required)
        Returns:
        the new permission
        Since:
        18.11.0