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:
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?
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.
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.
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.
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();
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?
That looks like a bug in the MockEntityService, hmm... what TM build are you running?
We are currently creating a TM 5.0.10 maintenance release, we can include this fix in that build.
Actually thinking about this you can actually skip the line:
When running on a TM server and your code should work fine. This method support unit testing without a TM server.
green is good. I managed to get the unit test to work.
Thanks for your suggestions. Much appreciated.