JobCallbackUtil { public static List<HttpRequestBase> parseJobCallbackProperties(final Props props, final JobCallbackStatusEnum status, final Map<String, String> contextInfo, final int maxNumCallback) { return parseJobCallbackProperties(props, status, contextInfo, maxNumCallback, logger); }  static boolean isThereJobCallbackProperty(final Props props,
      final JobCallbackStatusEnum status); static boolean isThereJobCallbackProperty(final Props props,
      final JobCallbackStatusEnum... jobStatuses); static List<HttpRequestBase> parseJobCallbackProperties(final Props props,
      final JobCallbackStatusEnum status, final Map<String, String> contextInfo,
      final int maxNumCallback); static List<HttpRequestBase> parseJobCallbackProperties(final Props props,
      final JobCallbackStatusEnum status, final Map<String, String> contextInfo,
      final int maxNumCallback, final Logger privateLogger); static Header[] parseHttpHeaders(final String headers); static Map<String, String> buildJobContextInfoMap(final Event event,
      final String server); static String replaceTokens(final String value,
      final Map<String, String> contextInfo, final boolean withEncoding);  }
@Test public void parseJobCallbackOneGetTest() { final Props props = new Props(); final String url = "http: props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); final List<HttpRequestBase> result = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); Assert.assertEquals(1, result.size()); Assert.assertEquals(HTTP_GET, result.get(0).getMethod()); Assert.assertEquals(url, result.get(0).getURI().toString()); }
@Test public void parseJobCallbackWithInvalidURLTest() { final Props props = new Props(); final String url = "linkedin.com"; props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); final List<HttpRequestBase> result = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); Assert.assertEquals(1, result.size()); Assert.assertEquals(HTTP_GET, result.get(0).getMethod()); Assert.assertEquals(url, result.get(0).getURI().toString()); }
@Test public void parseJobCallbackTwoGetsTest() { final Props props = new Props(); final String[] urls = {"http: "http: props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", urls[0]); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".2.url", urls[1]); final List<HttpRequestBase> result = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); Assert.assertEquals(2, result.size()); for (int i = 0; i < urls.length; i++) { Assert.assertEquals(HTTP_GET, result.get(i).getMethod()); Assert.assertEquals(urls[i], result.get(i).getURI().toString()); } }
@Test public void parseJobCallbackWithGapTest() { final Props props = new Props(); final String[] urls = {"http: "http: props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", urls[0]); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".3.url", urls[1]); final List<HttpRequestBase> result = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); Assert.assertEquals(1, result.size()); Assert.assertEquals(HTTP_GET, result.get(0).getMethod()); Assert.assertEquals(urls[0], result.get(0).getURI().toString()); }
@Test public void parseJobCallbackWithPostTest() { final Props props = new Props(); final String url = "http: final String bodyText = "{name:\"you\"}"; props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.url", url); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.method", HTTP_POST); props.put("job.notification." + JobCallbackStatusEnum.STARTED.name().toLowerCase() + ".1.body", bodyText); final List<HttpRequestBase> result = JobCallbackUtil.parseJobCallbackProperties(props, JobCallbackStatusEnum.STARTED, contextInfo, 3); Assert.assertEquals(1, result.size()); final HttpPost httpPost = (HttpPost) result.get(0); Assert.assertEquals(url, httpPost.getURI().toString()); Assert.assertEquals(HTTP_POST, httpPost.getMethod()); Assert.assertEquals(bodyText.length(), httpPost.getEntity() .getContentLength()); }