1
0
-1

Using Transact SDK 17.10, how can I write a test case to validate form prefill actually prefills the data at correct xml location? I am using ObjectMapper to update vo mapped to form xml elements. Since I am using Transact Functions, Form Open trigger assigned to a form that replaces conventional Form Prefill service. After updating form vo, I use "result.includeFormData = true" so data gets merged into a form. I can confirm that form is prefilled with correct information. However, I cannot write test case that I can interrogate param.appDoc to confirm document reflects with correct values. I have tried both param.txn.formXml and param.appDoc but have no luck. param.txn.formXml is null and param.appDoc returns the original seed file. I want access the form xml with the updated data after execution of Form Update function so that I can write assets on. What is the best way to write test cases for this scenario?

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi Nirmal,

      With the "Form Open" trigger you just need to update the param.appDoc XML document and this value will be used to prefill the form with.  You don't need to set the result.includeFormData in this context.

      An example For Open function is provided below:

      package com.maguire.svc.open;
      
      import com.avoka.tm.func.*
      import com.avoka.tm.svc.*
      import com.avoka.tm.util.*
      import com.avoka.tm.vo.*
      import javax.servlet.http.*
      
      public class Open {
      
          // Injected at runtime
          public Logger logger
      
          /*
           * Perform Fluent Function call.
           *
           * returns: FuncResult
           */
          FuncResult invoke(FuncParam param) {
      
              XmlDoc xmlDoc = new XmlDoc(param.appDoc)
              xmlDoc.setText('/Root/AvokaSmartForm/Test', "true")
      
              FormFuncResult result = new FormFuncResult()
      
              return result
          }
      }

      The corresponding test case is provided below:

      package com.maguire.svc.open;
      
      import com.avoka.tm.func.*
      import com.avoka.tm.svc.*
      import com.avoka.tm.test.*
      import com.avoka.tm.util.*
      import com.avoka.tm.vo.*
      import org.junit.*
      
      public class OpenTest extends TransactSDKUnitTest {
      
          /*
           * Perform service unit test
           *
           * throws exception if unit test fails
           */
          @Test
          void testFunction() throws Exception {
      
              FuncParam funcParam = new MockVoBuilder()
                  .createFuncParam(FuncParam.TRIGGER_FORM_UPDATE, Txn.FORM_SAVED, svcDef, testParams);
      
              FormFuncResult result = (FormFuncResult) new ServiceInvoker(svcDef)
                  .setLogger(logger)
                  .invoke("funcParam", funcParam)
      
              logger.info new XmlDoc(funcParam.appDoc).toString()
      
              assert result != null
          }
      }
      1. Nirmal Solanki

        Thanks Mal. I realized that would work for Form Open. How about other triggers or a standard Form Function where I need to merge the data back to the form using ObjectMapper. Do you have an example for those scenarios? 

      2. Malcolm Edgar

        Hi Nirmal,

        There is a new topic in the Transact SDK doco., which provides a full example.  A short example is provided below.

        The typical trigger you should use is the 'Form Update' trigger which is called on page changes (roughly equivalent to a traditional background save).  With this trigger you have to specify the:

        result.includeFormData = true;

        To tell the server to include the form XML data in the response back to the form. The Maestro form will see the included form data and bind it back into the Maestro data model, updating your fields.

        package com.maguire.svc.controller;
        
        import com.avoka.tm.func.*
        import com.avoka.tm.svc.*
        import com.avoka.tm.util.*
        import com.avoka.tm.vo.*
        import com.maguire.vo.Applicant
        import com.maguire.vo.Address
        
        import javax.servlet.http.*
        
        public class Controller {
        
            // Injected at runtime
            public Logger logger
        
            /*
             * Perform Fluent Function call.
             *
             * returns: FuncResult
             */
            FuncResult invoke(FuncParam param) {
        
                Applicant applicant = new ObjectMapper()
                    .setDoc(param.appDoc)
                    .setFormXPath("/Applicant")
                    .create(Applicant.class);
        
                logger.info("person: " + applicant)
        
                applicant.address = new Address()
                applicant.address.line1 = "123 Berry Street";
                applicant.address.line2 = "Avalon";
                applicant.address.postCode = "2121";
                applicant.address.state = "NSW";
        
                new ObjectMapper()
                    .setObject(applicant)
                    .setFormXPath("/Applicant")
                    .update(param.appDoc);
        
                FormFuncResult result = new FormFuncResult()
                result.includeFormData = true;
        
                return result
            }
        }
      3. Nirmal Solanki

        Yes, this is what I do to update form xml using ObjectMapper and result.includeFormData=true to merge data back to the form. My question is more to write a test case around this function execution. It seems I cannot get updated param.appDoc in the Test function after executing this script in order to validate if it has updated form xml.

      CommentAdd your comment...