ZenclusiveImpl { public boolean sendReward(String email, Incentive incentive) { if ( email == null || email.trim().isEmpty() ) { logger.warn("Cannot send any reward to an unspecified email"); return false; } else if ( incentive == null ) { logger.warn("Cannot send any reward to an unspecified incentive"); return false; } HttpEntity entity; try { List<NameValuePair> parameters = new ArrayList<NameValuePair>(0); parameters.add(new BasicNameValuePair("email", email)); parameters.add(new BasicNameValuePair("incentivename", incentive.getName())); parameters.add(new BasicNameValuePair("incentivevalue", String.valueOf(incentive.getValue()))); entity = new UrlEncodedFormEntity(parameters, Constants.DEFAULT_CHARSET); } catch ( Exception ex ) { logger.error("", ex); return false; } HttpPost request = new HttpPost(ZENCLUSIVE_REWARDS_ADDRESS); request.setHeader("Authorization", authorization); request.setEntity(entity); try { HttpResponse response = httpClient.execute(request); entity = response.getEntity(); if (entity == null) { logger.warn("The returned response is null"); return false; } JSONParser parser = new JSONParser(); Object obj = parser.parse(new InputStreamReader(entity.getContent())); JSONObject jsonObject = (JSONObject) obj; boolean success = (Boolean) jsonObject.get("success"); logger.warn("The returned result after send reward: " + success); return success; } catch (IOException ex) { logger.error("Exception thrown when trying to send reward from zenclusive", ex); } catch (ParseException ex) { logger.error("Exception thrown when trying to parse response of sent reward from zenclusive", ex); } finally { try { EntityUtils.consume(entity); } catch (IOException ex) { logger.error("Exception when consuming entity", ex); } } return false; }  @PostConstruct void init(); Incentive getIncentiveByParams(String name, String value); boolean sendReward(String email, Incentive incentive); String buildZenclusiveEmail(Long requestId);  }
@Test public void testSendReward() { boolean success = zenclusiveImpl.sendReward("venefica.labs@yatko.com", new ZenclusiveImpl.Incentive("David's Cookies", 10L)); System.out.println("send reward success: " + success); }