Alissa Bonas has uploaded a new change for review. Change subject: restapi: solve InstantiationException - BigDecimal ......................................................................
restapi: solve InstantiationException - BigDecimal Solve InstantiationException when creating a BigDecimal in *MapperTests. Change-Id: I81d064661f3bf0baeeae2e1c71323cdd719fc6ef Signed-off-by: Alissa Bonas <abo...@redhat.com> --- M backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java 1 file changed, 24 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/61/18761/1 diff --git a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java index aac5d98..462a8ec 100644 --- a/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java +++ b/backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java @@ -1,16 +1,21 @@ package org.ovirt.engine.api.restapi.types; import java.lang.reflect.Method; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.ovirt.engine.api.restapi.utils.GuidUtils; +import org.apache.log4j.Logger; +import org.ovirt.engine.api.restapi.utils.GuidUtils; public class MappingTestHelper { private static final String SET_ROOT = "set"; private static final String GET_ROOT = "get"; + + // The log: + private static final Logger logger = Logger.getLogger(MappingTestHelper.class); /** * Populate a JAXB model type by recursively walking element tree and @@ -44,7 +49,11 @@ random(method, model); } else if (takesEnum(method)) { shuffle(method, model); - } else { + } + else if(takesBigDecimal(method)) { + populateBigDecimal(method,model); + } + else { descend(method, model, scope(seen)); } } else if (isGetter(method) && returnsList(method)) { @@ -54,12 +63,21 @@ return model; } + private static void populateBigDecimal(Method method, Object model) { + try { + method.invoke(model, new BigDecimal(rand(100))); + } catch (Exception e) { + logger.error("Failed to populate big decimal in " + method.getDeclaringClass() + "." + method.getName(),e); + } + } + private static Object instantiate(Class<?> clz) { Object model = null; try { model = clz.newInstance(); } catch (Exception e) { // should never occur, trivial instantiation + logger.error("Failed to instantiate class " + clz.getSimpleName(),e); } return model; } @@ -171,6 +189,10 @@ || Boolean.class.equals(m.getParameterTypes()[0]); } + private static boolean takesBigDecimal(Method m) { + return BigDecimal.class.equals(m.getParameterTypes()[0]); + } + private static boolean takesEnum(Method m) { return m.getParameterTypes()[0].isEnum(); } -- To view, visit http://gerrit.ovirt.org/18761 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I81d064661f3bf0baeeae2e1c71323cdd719fc6ef Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alissa Bonas <abo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches