@Test public void shouldProcessReisterCWCChild() throws ValidationException { form.setMessageFormStatus(IncMessageFormStatus.VALID); form.getIncomingMsgFormDefinition().setFormCode("REGISTERCWCCHILD-JF"); mockWebService.registerCWCChild((Integer) anyObject(), (Integer) anyObject(), (Date) anyObject(), (Integer) anyObject(), (String) anyObject(), (Boolean) anyObject(), (Boolean) anyObject(), (ContactNumberType) anyObject(), (String) anyObject(), (MediaType) anyObject(), (String) anyObject(), (DayOfWeek) anyObject(), (Date) anyObject(), (HowLearned) anyObject()); expectLastCall(); replay(mockWebService); instance.processForm(form); assertEquals(form.getMessageFormStatus(), IncMessageFormStatus.SERVER_VALID); verify(mockWebService); reset(mockWebService); }
public String processForm(IncomingMessageForm form) { Object result = null; MethodSignature methodSignature; if(form.getMessageFormStatus() != IncMessageFormStatus.VALID) return "Invalid form"; SimpleDateFormat dFormat = new SimpleDateFormat(defaultDateFormat); dFormat.setLenient(true); if (getServiceMethods().containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { methodSignature = getServiceMethods().get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } else { return form.getMessageFormStatus().toString(); } String methodName = methodSignature.getMethodName(); Class[] paramTypes = new Class[methodSignature.getMethodParams().size()]; Object[] paramObjs = new Object[methodSignature.getMethodParams().size()]; int idx = 0; try { for (Entry<String, Class> e : methodSignature.getMethodParams().entrySet()) { logger.debug("Param: "+e.getKey()+" Class:"+e.getValue()); paramTypes[idx] = e.getValue(); if (form.getIncomingMsgFormParameters().containsKey(e.getKey().toLowerCase())) { if(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().isEmpty()){ paramObjs[idx] = null; } else if (e.getValue().equals(Date.class)) { paramObjs[idx] = dFormat.parse(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().isEnum()) { paramObjs[idx] = Enum.valueOf(e.getValue(), form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().equals(String.class)) { paramObjs[idx] = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue(); } else if (e.getValue().isArray()) { String[] a = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().split(" "); Class baseType = e.getValue().getComponentType(); Object arrayObj = Array.newInstance(baseType, a.length); for (int i = 0; i < a.length; i++) { Constructor constr = baseType.getConstructor(String.class); Object val = constr.newInstance(a[i]); Array.set(arrayObj, i, val); } paramObjs[idx] = arrayObj; } else { Constructor constr = e.getValue().getConstructor(String.class); paramObjs[idx] = constr.newInstance(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } } else { paramObjs[idx] = null; } idx++; } Method method = regWS.getClass().getDeclaredMethod(methodName, paramTypes); result = method.invoke(regWS, paramObjs); form.setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); } catch (NoSuchMethodException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not find web service method " + methodName, ex); } catch (SecurityException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not access method " + methodName + " due to SecurityException", ex); } catch (IllegalAccessException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not invoke method " + methodName + " due to IllegalAccessException", ex); } catch (InvocationTargetException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); if (ex.getCause().getClass().equals(ValidationException.class)) { parseValidationErrors(form, (ValidationException) ex.getCause()); } else { logger.fatal("Could not invoke method " + methodName + " due to InvocationTargetException", ex); } } catch (Exception ex) { logger.error("Form could not be processed on server", ex); form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); return "An error occurred on the server"; } if (methodSignature.getCallback() == null) { return (result == null) ? null : String.valueOf(result); } return executeCallback(methodSignature.getCallback(), result); }
FormProcessorImpl implements FormProcessor { public String processForm(IncomingMessageForm form) { Object result = null; MethodSignature methodSignature; if(form.getMessageFormStatus() != IncMessageFormStatus.VALID) return "Invalid form"; SimpleDateFormat dFormat = new SimpleDateFormat(defaultDateFormat); dFormat.setLenient(true); if (getServiceMethods().containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { methodSignature = getServiceMethods().get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } else { return form.getMessageFormStatus().toString(); } String methodName = methodSignature.getMethodName(); Class[] paramTypes = new Class[methodSignature.getMethodParams().size()]; Object[] paramObjs = new Object[methodSignature.getMethodParams().size()]; int idx = 0; try { for (Entry<String, Class> e : methodSignature.getMethodParams().entrySet()) { logger.debug("Param: "+e.getKey()+" Class:"+e.getValue()); paramTypes[idx] = e.getValue(); if (form.getIncomingMsgFormParameters().containsKey(e.getKey().toLowerCase())) { if(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().isEmpty()){ paramObjs[idx] = null; } else if (e.getValue().equals(Date.class)) { paramObjs[idx] = dFormat.parse(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().isEnum()) { paramObjs[idx] = Enum.valueOf(e.getValue(), form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().equals(String.class)) { paramObjs[idx] = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue(); } else if (e.getValue().isArray()) { String[] a = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().split(" "); Class baseType = e.getValue().getComponentType(); Object arrayObj = Array.newInstance(baseType, a.length); for (int i = 0; i < a.length; i++) { Constructor constr = baseType.getConstructor(String.class); Object val = constr.newInstance(a[i]); Array.set(arrayObj, i, val); } paramObjs[idx] = arrayObj; } else { Constructor constr = e.getValue().getConstructor(String.class); paramObjs[idx] = constr.newInstance(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } } else { paramObjs[idx] = null; } idx++; } Method method = regWS.getClass().getDeclaredMethod(methodName, paramTypes); result = method.invoke(regWS, paramObjs); form.setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); } catch (NoSuchMethodException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not find web service method " + methodName, ex); } catch (SecurityException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not access method " + methodName + " due to SecurityException", ex); } catch (IllegalAccessException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not invoke method " + methodName + " due to IllegalAccessException", ex); } catch (InvocationTargetException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); if (ex.getCause().getClass().equals(ValidationException.class)) { parseValidationErrors(form, (ValidationException) ex.getCause()); } else { logger.fatal("Could not invoke method " + methodName + " due to InvocationTargetException", ex); } } catch (Exception ex) { logger.error("Form could not be processed on server", ex); form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); return "An error occurred on the server"; } if (methodSignature.getCallback() == null) { return (result == null) ? null : String.valueOf(result); } return executeCallback(methodSignature.getCallback(), result); } }
FormProcessorImpl implements FormProcessor { public String processForm(IncomingMessageForm form) { Object result = null; MethodSignature methodSignature; if(form.getMessageFormStatus() != IncMessageFormStatus.VALID) return "Invalid form"; SimpleDateFormat dFormat = new SimpleDateFormat(defaultDateFormat); dFormat.setLenient(true); if (getServiceMethods().containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { methodSignature = getServiceMethods().get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } else { return form.getMessageFormStatus().toString(); } String methodName = methodSignature.getMethodName(); Class[] paramTypes = new Class[methodSignature.getMethodParams().size()]; Object[] paramObjs = new Object[methodSignature.getMethodParams().size()]; int idx = 0; try { for (Entry<String, Class> e : methodSignature.getMethodParams().entrySet()) { logger.debug("Param: "+e.getKey()+" Class:"+e.getValue()); paramTypes[idx] = e.getValue(); if (form.getIncomingMsgFormParameters().containsKey(e.getKey().toLowerCase())) { if(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().isEmpty()){ paramObjs[idx] = null; } else if (e.getValue().equals(Date.class)) { paramObjs[idx] = dFormat.parse(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().isEnum()) { paramObjs[idx] = Enum.valueOf(e.getValue(), form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().equals(String.class)) { paramObjs[idx] = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue(); } else if (e.getValue().isArray()) { String[] a = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().split(" "); Class baseType = e.getValue().getComponentType(); Object arrayObj = Array.newInstance(baseType, a.length); for (int i = 0; i < a.length; i++) { Constructor constr = baseType.getConstructor(String.class); Object val = constr.newInstance(a[i]); Array.set(arrayObj, i, val); } paramObjs[idx] = arrayObj; } else { Constructor constr = e.getValue().getConstructor(String.class); paramObjs[idx] = constr.newInstance(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } } else { paramObjs[idx] = null; } idx++; } Method method = regWS.getClass().getDeclaredMethod(methodName, paramTypes); result = method.invoke(regWS, paramObjs); form.setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); } catch (NoSuchMethodException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not find web service method " + methodName, ex); } catch (SecurityException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not access method " + methodName + " due to SecurityException", ex); } catch (IllegalAccessException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not invoke method " + methodName + " due to IllegalAccessException", ex); } catch (InvocationTargetException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); if (ex.getCause().getClass().equals(ValidationException.class)) { parseValidationErrors(form, (ValidationException) ex.getCause()); } else { logger.fatal("Could not invoke method " + methodName + " due to InvocationTargetException", ex); } } catch (Exception ex) { logger.error("Form could not be processed on server", ex); form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); return "An error occurred on the server"; } if (methodSignature.getCallback() == null) { return (result == null) ? null : String.valueOf(result); } return executeCallback(methodSignature.getCallback(), result); }  }
FormProcessorImpl implements FormProcessor { public String processForm(IncomingMessageForm form) { Object result = null; MethodSignature methodSignature; if(form.getMessageFormStatus() != IncMessageFormStatus.VALID) return "Invalid form"; SimpleDateFormat dFormat = new SimpleDateFormat(defaultDateFormat); dFormat.setLenient(true); if (getServiceMethods().containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { methodSignature = getServiceMethods().get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } else { return form.getMessageFormStatus().toString(); } String methodName = methodSignature.getMethodName(); Class[] paramTypes = new Class[methodSignature.getMethodParams().size()]; Object[] paramObjs = new Object[methodSignature.getMethodParams().size()]; int idx = 0; try { for (Entry<String, Class> e : methodSignature.getMethodParams().entrySet()) { logger.debug("Param: "+e.getKey()+" Class:"+e.getValue()); paramTypes[idx] = e.getValue(); if (form.getIncomingMsgFormParameters().containsKey(e.getKey().toLowerCase())) { if(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().isEmpty()){ paramObjs[idx] = null; } else if (e.getValue().equals(Date.class)) { paramObjs[idx] = dFormat.parse(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().isEnum()) { paramObjs[idx] = Enum.valueOf(e.getValue(), form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().equals(String.class)) { paramObjs[idx] = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue(); } else if (e.getValue().isArray()) { String[] a = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().split(" "); Class baseType = e.getValue().getComponentType(); Object arrayObj = Array.newInstance(baseType, a.length); for (int i = 0; i < a.length; i++) { Constructor constr = baseType.getConstructor(String.class); Object val = constr.newInstance(a[i]); Array.set(arrayObj, i, val); } paramObjs[idx] = arrayObj; } else { Constructor constr = e.getValue().getConstructor(String.class); paramObjs[idx] = constr.newInstance(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } } else { paramObjs[idx] = null; } idx++; } Method method = regWS.getClass().getDeclaredMethod(methodName, paramTypes); result = method.invoke(regWS, paramObjs); form.setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); } catch (NoSuchMethodException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not find web service method " + methodName, ex); } catch (SecurityException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not access method " + methodName + " due to SecurityException", ex); } catch (IllegalAccessException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not invoke method " + methodName + " due to IllegalAccessException", ex); } catch (InvocationTargetException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); if (ex.getCause().getClass().equals(ValidationException.class)) { parseValidationErrors(form, (ValidationException) ex.getCause()); } else { logger.fatal("Could not invoke method " + methodName + " due to InvocationTargetException", ex); } } catch (Exception ex) { logger.error("Form could not be processed on server", ex); form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); return "An error occurred on the server"; } if (methodSignature.getCallback() == null) { return (result == null) ? null : String.valueOf(result); } return executeCallback(methodSignature.getCallback(), result); }  String processForm(IncomingMessageForm form); void parseValidationErrors(IncomingMessageForm form, ValidationException ex); void setDefaultDateFormat(String defaultDateFormat); void setRegWS(RegistrarService regWS); void setOmiManager(OMIManager omiManager); void setCoreManager(CoreManager coreManager); void setServerErrors(Map<Integer, String> serverErrors); Map<String, MethodSignature> getServiceMethods(); void setServiceMethods(Map<String, MethodSignature> serviceMethods); }
FormProcessorImpl implements FormProcessor { public String processForm(IncomingMessageForm form) { Object result = null; MethodSignature methodSignature; if(form.getMessageFormStatus() != IncMessageFormStatus.VALID) return "Invalid form"; SimpleDateFormat dFormat = new SimpleDateFormat(defaultDateFormat); dFormat.setLenient(true); if (getServiceMethods().containsKey(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase())) { methodSignature = getServiceMethods().get(form.getIncomingMsgFormDefinition().getFormCode().toUpperCase()); } else { return form.getMessageFormStatus().toString(); } String methodName = methodSignature.getMethodName(); Class[] paramTypes = new Class[methodSignature.getMethodParams().size()]; Object[] paramObjs = new Object[methodSignature.getMethodParams().size()]; int idx = 0; try { for (Entry<String, Class> e : methodSignature.getMethodParams().entrySet()) { logger.debug("Param: "+e.getKey()+" Class:"+e.getValue()); paramTypes[idx] = e.getValue(); if (form.getIncomingMsgFormParameters().containsKey(e.getKey().toLowerCase())) { if(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().isEmpty()){ paramObjs[idx] = null; } else if (e.getValue().equals(Date.class)) { paramObjs[idx] = dFormat.parse(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().isEnum()) { paramObjs[idx] = Enum.valueOf(e.getValue(), form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } else if (e.getValue().equals(String.class)) { paramObjs[idx] = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue(); } else if (e.getValue().isArray()) { String[] a = form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue().split(" "); Class baseType = e.getValue().getComponentType(); Object arrayObj = Array.newInstance(baseType, a.length); for (int i = 0; i < a.length; i++) { Constructor constr = baseType.getConstructor(String.class); Object val = constr.newInstance(a[i]); Array.set(arrayObj, i, val); } paramObjs[idx] = arrayObj; } else { Constructor constr = e.getValue().getConstructor(String.class); paramObjs[idx] = constr.newInstance(form.getIncomingMsgFormParameters().get(e.getKey().toLowerCase()).getValue()); } } else { paramObjs[idx] = null; } idx++; } Method method = regWS.getClass().getDeclaredMethod(methodName, paramTypes); result = method.invoke(regWS, paramObjs); form.setMessageFormStatus(IncMessageFormStatus.SERVER_VALID); } catch (NoSuchMethodException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not find web service method " + methodName, ex); } catch (SecurityException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not access method " + methodName + " due to SecurityException", ex); } catch (IllegalAccessException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); logger.fatal("Could not invoke method " + methodName + " due to IllegalAccessException", ex); } catch (InvocationTargetException ex) { form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); if (ex.getCause().getClass().equals(ValidationException.class)) { parseValidationErrors(form, (ValidationException) ex.getCause()); } else { logger.fatal("Could not invoke method " + methodName + " due to InvocationTargetException", ex); } } catch (Exception ex) { logger.error("Form could not be processed on server", ex); form.setMessageFormStatus(IncMessageFormStatus.SERVER_INVALID); return "An error occurred on the server"; } if (methodSignature.getCallback() == null) { return (result == null) ? null : String.valueOf(result); } return executeCallback(methodSignature.getCallback(), result); }  String processForm(IncomingMessageForm form); void parseValidationErrors(IncomingMessageForm form, ValidationException ex); void setDefaultDateFormat(String defaultDateFormat); void setRegWS(RegistrarService regWS); void setOmiManager(OMIManager omiManager); void setCoreManager(CoreManager coreManager); void setServerErrors(Map<Integer, String> serverErrors); Map<String, MethodSignature> getServiceMethods(); void setServiceMethods(Map<String, MethodSignature> serviceMethods);  }