コード例 #1
0
 private SmsHttpTemplate createSmsHttpTemplate(Request request) {
   SmsHttpTemplate smsHttpTemplate = new SmsHttpTemplate();
   Outgoing outgoing = new Outgoing();
   outgoing.setRequest(request);
   smsHttpTemplate.setOutgoing(outgoing);
   return smsHttpTemplate;
 }
コード例 #2
0
  @Test
  public void shouldSetBodyParametersForPOSTRequestType() {
    Map<String, String> params = new HashMap<String, String>();
    params.put("key1", "value1");
    params.put("key2", "value2");
    params.put("recipients", "$recipients");
    params.put("message", "$message");
    Request request =
        new SmsSendTemplateBuilder.RequestBuilder()
            .withType(HttpMethodType.POST)
            .withBodyParameters(params)
            .withRecipientSeperator(",")
            .build();

    SmsHttpTemplate smsHttpTemplate = createSmsHttpTemplate(request);

    PostMethod httpMethod =
        (PostMethod)
            smsHttpTemplate.generateRequestFor(Arrays.asList("123", "456", "789"), "someMessage");
    assertEquals(4, httpMethod.getParameters().length);
    assertEquals("value1", httpMethod.getParameter("key1").getValue());
    assertEquals("value2", httpMethod.getParameter("key2").getValue());
    assertEquals("123,456,789", httpMethod.getParameter("recipients").getValue());
    assertEquals("someMessage", httpMethod.getParameter("message").getValue());
  }
コード例 #3
0
 @Test
 public void shouldCreateCorrectRequestTypeBasedOnConfiguration_GET() {
   TemplateReader templateReader = createTemplateReader("templates/sms-http-get-template.json");
   SmsHttpTemplate smsHttpGETTemplate = templateReader.getTemplate();
   assertEquals(
       GetMethod.class,
       smsHttpGETTemplate
           .generateRequestFor(Arrays.asList("123", "456", "789"), "Hello World")
           .getClass());
 }
コード例 #4
0
  @Test
  public void shouldReplaceMessageVariableWithValue() throws URIException {
    Request request = new Request();
    request.setUrlPath("http://smshost.com/sms/send");
    Map<String, String> queryParameters =
        new HashMap<String, String>() {
          {
            put("message", "$message");
          }
        };
    request.setQueryParameters(queryParameters);

    SmsHttpTemplate smsHttpTemplate = createSmsHttpTemplate(request);

    HttpMethod httpMethod = smsHttpTemplate.generateRequestFor(Arrays.asList("123"), "foobar");
    assertEquals("http://smshost.com/sms/send?message=foobar", httpMethod.getURI().getURI());
  }
コード例 #5
0
  @Test
  public void shouldReplaceReciepientsVariableWithValue() throws URIException {
    Request request = new Request();
    request.setUrlPath("http://smshost.com/sms/send");
    request.setRecipientsSeparator(",");
    Map<String, String> queryParameters =
        new HashMap<String, String>() {
          {
            put("recipients", "$recipients");
          }
        };
    request.setQueryParameters(queryParameters);

    SmsHttpTemplate smsHttpTemplate = createSmsHttpTemplate(request);

    HttpMethod httpMethod =
        smsHttpTemplate.generateRequestFor(Arrays.asList("123", "456", "789"), "some message");
    assertEquals(
        "http://smshost.com/sms/send?recipients=123,456,789", httpMethod.getURI().getURI());
  }