1
0
-1

Hi,

we need to make some changes to our greenID service to handle new endpoints. Before I make changes I want to develop a unit test to verify behaviour before and after the changes.

However, the test fails with a NullPointerException at the point where the code tries to:

submission.setSubmissionPropertyValue(name, value)

In the test code I provide a submission object as follows:

def request = new MockRequest()
def form = new Form()
def submission = new Submission()

Is that sufficient, or do I need a different approach for testing Dynamic Data services?

Thanks

    CommentAdd your comment...

    3 answers

    1.  
      2
      1
      0

      Hi Mark,

      In your code you are using the TM Java APIs and you use the Fluent API's instead.

      You can't use the Submission entity like this, and it need to be connected to a submission data storage service to perform data encryption and storage operations.

      regards Malcolm

      1. Mark Murray

        Hi Malcolm,

        thanks for the comment. That makes sense (now!).

        I'll have to do some more work to set up the legacy unit test to work with legacy code rather than Fluent services.

        I don't have many examples of unit tests for legacy code - is there any good resource you can recommend to find examples? One would be enough to give me a head start.

        Thanks

        Mark

      2. Malcolm Edgar

        Hi Mark,

        Please see the example below to get you started.

        Please note you should perform these unit tests in the Service Unit Test tab and not the Groovy Console, as the MockEntityService creates database entities which need to be rolled back.  If you dont you will start seeing lots of UNIT-TEST-* entities being created in your database.

        regarsd Malcolm

        import com.avoka.fc.core.entity.Submission;
        import com.avoka.fc.core.service.test.MockEntityService;
        MockEntityService mes = new MockEntityService();
        mes.loadCoreConfiguration();

        Submission submission = mes.createSubmissionOpened();
      3. Mark Murray

        Hi Malcolm,

        I'm now working with the code you suggested above, however, I'm getting an SQL error:

        com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'Local Security Manager' for key 'ui_security_manager_name'

        This occurs immediately that I run the unit test.

        How do I overcome that error?

        Thanks

      4. Malcolm Edgar

        Hi Mark,

        That looks like a bug in the MockEntityService, hmm... what TM build are you running?

        regards Malcolm

      5. Malcolm Edgar

        We are currently creating a TM 5.0.10 maintenance release, we can include this fix in that build.

        regards Malcolm

      6. Malcolm Edgar

        Hi Mark,

        Actually thinking about this you can actually skip the line:

        mes.loadCoreConfiguration();

        When running on a TM server and your code should work fine.  This method support unit testing without a TM server.

        regards Malcolm

      7. Mark Murray

        Hi Malcolm,

        green is good. I managed to get the unit test to work.

        Thanks for your suggestions. Much appreciated.


      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Mark,

      Are you developing a Fluent Delivery Process or a Groovy Delivery Process ?  Both of these have standard unit test templates as the starting point to develop unit test code.  It this what you are using ?

      regards Malcolm

      1. Mark Murray

        Hi Malcolm,

        this is a Groovy Delivery Process and I have used the default unit test code as a starting point.

        Once I get the basic test working I plan to add more test cases, but I can't get past step 1 just at the moment.

        I have added the test parameter 'Test XML Data', so could it be that the mock service is not behaving properly, even before we get to the service code?

        Thanks

      2. Malcolm Edgar

        What version of TM are you using ?

        regards Malcolm

      3. Malcolm Edgar

        The Groovy Delivery Process template already includes a test parameter "Test XML Data" for use in the unit test.  Is this what you are using ?

      4. Mark Murray

        Hi Malcolm,

        we are using TM 5.0.2.

        Yes, I'm using the default test parameter 'Test XML Data'; I've populated it with some xml from a form submission.

        Thanks

      5. Malcolm Edgar

        Hi Mark,

        Can you attach the service archive zip, so I can take a look at what is going on.

        regards Malcolm

      6. Mark Murray

        Hi Malcolm,

        the forum won't let me attach a file, so I sent an email.

        Thanks

      7. Malcolm Edgar

        Hi Murray,

        I have identified the issue here being due to security policies prevent access to the submission XML. I have raise a JIRA (TPD-5644) and will get this fixed in TM 5.1.7 which is a couple of weeks.  

        In the mean time you can work around this issue by using the updated unit test code below which sets up the submission using the service definitions client (org) security context.

        regards Malcolm

        -------------------------------------------------------

        /* Unit Test Groovy script.

           Script parameters include:
               serviceName : String
               serviceDefinition : com.avoka.fc.core.entity.ServiceDefinition
               serviceParameters : Map<String, String>
               testParameters : Map<String, String>

            Script throws:
                exception if unit test fails
        */
        import com.avoka.core.groovy.GroovyLogger as logger
        import com.avoka.fc.core.entity.*
        import com.avoka.fc.core.service.*
        import com.avoka.fc.core.service.impl.GroovyDeliveryProcessService
        import com.avoka.fc.core.service.test.*

        def xmlData = testParameters['Test XML Data']

        // Create a mock submission
        def mockEntityService = new MockEntityService()

        String testName = mockEntityService.createRandomTestName();
        Portal portal = mockEntityService.createPortal(testName);
        Client client = serviceDefinition.client;
        Form form = mockEntityService.createForm(testName, client, portal);

        def submission = mockEntityService.createSubmissionDeliveryReadyWithFormAndXml(form, xmlData)
        def deliveryDetails = submission.client.deliveryDetails[0]

        // Perform delivery process
        GroovyDeliveryProcessService service = ServiceLocator.getServiceForDefinition(serviceDefinition)
        service.deliverSubmission(submission, deliveryDetails)

        // Check results
        logger.info 'Delivery Checkpoint Results:'

        for (SubmissionDeliveryCheckpoint sdc : submission.deliveryCheckpoints) {
          logger.info '   ' + sdc.name + ' - ' + sdc.status
        }

        assert 4 == submission.deliveryCheckpoints.size()

        assert 'Registered' == submission.deliveryCheckpoints.get(0).status
        assert 'Completed'  == submission.deliveryCheckpoints.get(1).status
        assert 'Registered' == submission.deliveryCheckpoints.get(2).status
        assert 'Completed'  == submission.deliveryCheckpoints.get(3).status

      8. Mark Murray

        Hi Malcolm,

        great work; I don't think I would have discovered that one.

        I'll get a chance to work on this tomorrow, so I'll give you some feedback once I make some progress.

        thanks for the code example; that will be a great starting point.

        Much appreciated.

        Thanks

        Mark

      CommentAdd your comment...
    3.  
      1
      0
      -1

      Hi Malcolm,

      I'm now working on a unit test for a delivery service and getting an error:

      java.lang.IllegalArgumentException: Null source parameter

      which is related to the delivery service trying to create an XmlDoc from the 'submissionXml'.

      it seems that the parameter 'submissionXml' that is usually supplied to the service is null.

      I'm not sure how to generate that, or even confirm that is what is causing the error.

      Any ideas wold eb appreciated.


      Thanks

      Mark

        CommentAdd your comment...