@Test public void testSendMessage() { System.out.println("sendMessage"); GatewayRequest messageDetails = new GatewayRequestImpl(); messageDetails.setDateFrom(new Date()); messageDetails.setDateTo(new Date()); messageDetails.setRecipientsNumber("000000000000"); messageDetails.setGatewayRequestDetails(mockGatewayRequestDetails); expect( mockHandler.parseMessageResponse((GatewayRequest) anyObject(), (String) anyObject()) ).andReturn(new HashSet<GatewayResponse>()); replay(mockHandler); Set<GatewayResponse> result = instance.sendMessage(messageDetails); assertNotNull(result); verify(mockHandler); }
public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { if (log.isInfoEnabled()) { log.info(messageDetails.getId() + "|" + messageDetails.getRecipientsNumber() + "|" + messageDetails.getMessage()); } String msgResponse = (messageDetails.getRecipientsNumber().length() < 8) ? "failed" : "ID: " + MotechIDGenerator.generateID(10); if (sleepTime > 0) { try { log.debug("going to sleep to simulate latency"); Thread.sleep(sleepTime); log.debug("finished simulated latency"); } catch (InterruptedException ie) { log.debug("interrupted while sleeping"); } } if(isThrowRandomExceptions() && getExceptionPoints().contains(new Integer((int)(Math.random() * exceptionPointRange)))){ log.error("Throwing Exception to mimic possible fault behaviour"); throw new RuntimeException("Arbitrary exception thrown to mimic fault behaviour"); } return messageHandler.parseMessageResponse(messageDetails, msgResponse); }
DummyGatewayManagerImpl implements GatewayManager { public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { if (log.isInfoEnabled()) { log.info(messageDetails.getId() + "|" + messageDetails.getRecipientsNumber() + "|" + messageDetails.getMessage()); } String msgResponse = (messageDetails.getRecipientsNumber().length() < 8) ? "failed" : "ID: " + MotechIDGenerator.generateID(10); if (sleepTime > 0) { try { log.debug("going to sleep to simulate latency"); Thread.sleep(sleepTime); log.debug("finished simulated latency"); } catch (InterruptedException ie) { log.debug("interrupted while sleeping"); } } if(isThrowRandomExceptions() && getExceptionPoints().contains(new Integer((int)(Math.random() * exceptionPointRange)))){ log.error("Throwing Exception to mimic possible fault behaviour"); throw new RuntimeException("Arbitrary exception thrown to mimic fault behaviour"); } return messageHandler.parseMessageResponse(messageDetails, msgResponse); } }
DummyGatewayManagerImpl implements GatewayManager { public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { if (log.isInfoEnabled()) { log.info(messageDetails.getId() + "|" + messageDetails.getRecipientsNumber() + "|" + messageDetails.getMessage()); } String msgResponse = (messageDetails.getRecipientsNumber().length() < 8) ? "failed" : "ID: " + MotechIDGenerator.generateID(10); if (sleepTime > 0) { try { log.debug("going to sleep to simulate latency"); Thread.sleep(sleepTime); log.debug("finished simulated latency"); } catch (InterruptedException ie) { log.debug("interrupted while sleeping"); } } if(isThrowRandomExceptions() && getExceptionPoints().contains(new Integer((int)(Math.random() * exceptionPointRange)))){ log.error("Throwing Exception to mimic possible fault behaviour"); throw new RuntimeException("Arbitrary exception thrown to mimic fault behaviour"); } return messageHandler.parseMessageResponse(messageDetails, msgResponse); }  }
DummyGatewayManagerImpl implements GatewayManager { public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { if (log.isInfoEnabled()) { log.info(messageDetails.getId() + "|" + messageDetails.getRecipientsNumber() + "|" + messageDetails.getMessage()); } String msgResponse = (messageDetails.getRecipientsNumber().length() < 8) ? "failed" : "ID: " + MotechIDGenerator.generateID(10); if (sleepTime > 0) { try { log.debug("going to sleep to simulate latency"); Thread.sleep(sleepTime); log.debug("finished simulated latency"); } catch (InterruptedException ie) { log.debug("interrupted while sleeping"); } } if(isThrowRandomExceptions() && getExceptionPoints().contains(new Integer((int)(Math.random() * exceptionPointRange)))){ log.error("Throwing Exception to mimic possible fault behaviour"); throw new RuntimeException("Arbitrary exception thrown to mimic fault behaviour"); } return messageHandler.parseMessageResponse(messageDetails, msgResponse); }  Set<GatewayResponse> sendMessage(GatewayRequest messageDetails); void setSleepTime(long sleepTime); long getSleepTime(); String getMessageStatus(GatewayResponse response); MStatus mapMessageStatus(GatewayResponse response); GatewayMessageHandler getMessageHandler(); void setMessageHandler(GatewayMessageHandler messageHandler); boolean isThrowRandomExceptions(); void setThrowRandomExceptions(boolean throwRandomExceptions); ArrayList<Integer> getExceptionPoints(); void setExceptionPoints(ArrayList<Integer> exceptionPoints); int getExceptionPointRange(); void setExceptionPointRange(int exceptionPointRange); }
DummyGatewayManagerImpl implements GatewayManager { public Set<GatewayResponse> sendMessage(GatewayRequest messageDetails) { if (log.isInfoEnabled()) { log.info(messageDetails.getId() + "|" + messageDetails.getRecipientsNumber() + "|" + messageDetails.getMessage()); } String msgResponse = (messageDetails.getRecipientsNumber().length() < 8) ? "failed" : "ID: " + MotechIDGenerator.generateID(10); if (sleepTime > 0) { try { log.debug("going to sleep to simulate latency"); Thread.sleep(sleepTime); log.debug("finished simulated latency"); } catch (InterruptedException ie) { log.debug("interrupted while sleeping"); } } if(isThrowRandomExceptions() && getExceptionPoints().contains(new Integer((int)(Math.random() * exceptionPointRange)))){ log.error("Throwing Exception to mimic possible fault behaviour"); throw new RuntimeException("Arbitrary exception thrown to mimic fault behaviour"); } return messageHandler.parseMessageResponse(messageDetails, msgResponse); }  Set<GatewayResponse> sendMessage(GatewayRequest messageDetails); void setSleepTime(long sleepTime); long getSleepTime(); String getMessageStatus(GatewayResponse response); MStatus mapMessageStatus(GatewayResponse response); GatewayMessageHandler getMessageHandler(); void setMessageHandler(GatewayMessageHandler messageHandler); boolean isThrowRandomExceptions(); void setThrowRandomExceptions(boolean throwRandomExceptions); ArrayList<Integer> getExceptionPoints(); void setExceptionPoints(ArrayList<Integer> exceptionPoints); int getExceptionPointRange(); void setExceptionPointRange(int exceptionPointRange);  }