Notifications
Clear all

Can a unit test access model MDFs?

0 Posts
1 Users
0 Reactions
12 Views
0
Topic starter

I have a unit test (AbstractUnitTest) that is using a model object to get and set values to a field of type Float. The purpose of the test is to validate that certain values can be set on that field without losing precision.

The model field is defined as a MDFs and when calling getMDFs(), we get the following RuntimeException:

[junit] Testcase: testFloatField took 1.468 sec
[junit]     Caused an ERROR
[junit] java.lang.reflect.InvocationTargetException
[junit] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[junit]     at com.onenetwork.platform.common.Model.getMDFs(Model.java:552)
[junit]     at com.onenetwork.platform.common.Model.getMDFs(Model.java:561)
[junit]     at com.onenetwork.test.unit.ItemUnitTest.testFloatField(ItemUnitTest.java:13)
[junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] Caused by: java.lang.reflect.InvocationTargetException
[junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[junit]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit]     at com.onenetwork.platform.common.Model.getMDFs(Model.java:549)
[junit] Caused by: java.lang.NullPointerException: Cannot invoke "com.transcendsys.platform.base.bo.helper.LevelMappingHelper.getMapping()" because "lvlHelper" is null
[junit]     at com.transcendsys.platform.base.bo.helper.ModelHelper.getMDFs(ModelHelper.java:74)

Example of the getMDFs() call:

Item actual = new Item();
ItemMDFs actualTestMdfs = actual.getMDFs(com.onenetwork.test.model.ItemMDFs.class);

The test is not expected to write data to the database and we are just using the model object field to store data. The same test works when implemented as a server test (AbstractServerTest).

Is it possible to use the model class and get its MDFs in a unit test or is the server required for getting the MDFs class?