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...

    1 answer

    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...