Example usage for org.apache.http.client.methods RequestBuilder getFirstHeader

List of usage examples for org.apache.http.client.methods RequestBuilder getFirstHeader

Introduction

In this page you can find the example usage for org.apache.http.client.methods RequestBuilder getFirstHeader.

Prototype

public Header getFirstHeader(final String name) 

Source Link

Usage

From source file:com.nexmo.client.auth.JWTAuthMethodTest.java

@Test
public void testApply() throws Exception {
    RequestBuilder req = RequestBuilder.get();
    auth.apply(req);/* w ww.jav  a  2 s .  c o m*/

    assertEquals(1, req.getHeaders("Authorization").length);
    assertEquals("Bearer ", req.getFirstHeader("Authorization").getValue().substring(0, 7));
}

From source file:com.nexmo.client.voice.SendDtmfMethodTest.java

@Test
public void makeRequest() throws Exception {
    HttpWrapper httpWrapper = new HttpWrapper();
    SendDtmfMethod methodUnderTest = new SendDtmfMethod(httpWrapper);

    RequestBuilder request = methodUnderTest.makeRequest(new DtmfRequest("abc-123", "867"));

    assertEquals("PUT", request.getMethod());
    assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
    LOG.info(request.getEntity().getContent());
    assertEquals("867", node.get("digits").asText());
}

From source file:com.nexmo.client.voice.endpoints.ModifyCallMethodTest.java

@Test
public void makeRequest() throws Exception {
    HttpWrapper httpWrapper = new HttpWrapper();
    ModifyCallMethod methodUnderTest = new ModifyCallMethod(httpWrapper);

    RequestBuilder request = methodUnderTest.makeRequest(new CallModifier("abc-123", "hangup"));

    assertEquals("PUT", request.getMethod());
    assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
    LOG.info(request.getEntity().getContent());
    assertEquals("hangup", node.get("action").asText());
}

From source file:com.nexmo.client.voice.endpoints.CreateCallMethodTest.java

@Test
public void testMakeRequest() throws Exception {
    CreateCallMethod methodUnderTest = new CreateCallMethod(null);

    // Execute test call:
    RequestBuilder request = methodUnderTest
            .makeRequest(new Call("447700900903", "447700900904", "https://example.com/answer"));

    assertEquals("POST", request.getMethod());
    assertEquals("application/json", request.getFirstHeader("Content-Type").getValue());

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode node = objectMapper.readValue(request.getEntity().getContent(), JsonNode.class);
    LOG.info(request.getEntity().getContent());
    assertEquals("447700900903", node.get("to").get(0).get("number").asText());
    assertEquals("447700900904", node.get("from").get("number").asText());
    assertEquals("https://example.com/answer", node.get("answer_url").get(0).asText());
}