Example usage for org.springframework.http HttpMethod HEAD

List of usage examples for org.springframework.http HttpMethod HEAD

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod HEAD.

Prototype

HttpMethod HEAD

To view the source code for org.springframework.http HttpMethod HEAD.

Click Source Link

Usage

From source file:cucumber.api.spring.test.web.servlet.MockMvcStepdefs.java

@When("^I perform a HEAD request on \"(.*?)\"$")
public void i_perform_a_head_request_on(String uri) throws Throwable {
    i_perform_a_request_on(HttpMethod.HEAD, uri);
}

From source file:net.eusashead.hateoas.response.argumentresolver.AsyncEntityControllerITCase.java

@Test
public void testOptions() throws Exception {

    // Expected result
    HttpHeaders headers = new HttpHeaders();
    Set<HttpMethod> allowedMethods = new TreeSet<HttpMethod>();
    allowedMethods.addAll(Arrays.asList(HttpMethod.GET, HttpMethod.HEAD));
    headers.setAllow(allowedMethods);/*from w w  w . j av  a  2s . co  m*/
    ResponseEntity<Entity> expectedResult = new ResponseEntity<Entity>(new Entity("foo"), headers,
            HttpStatus.OK);

    // Execute asynchronously
    MvcResult mvcResult = this.mockMvc
            .perform(request(HttpMethod.OPTIONS, "http://localhost/async/foo")
                    .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
            .andExpect(request().asyncStarted()).andExpect(request().asyncResult(expectedResult)).andReturn();

    // Perform asynchronous dispatch
    this.mockMvc.perform(asyncDispatch(mvcResult)).andDo(print()).andExpect(status().isOk())
            .andExpect(content().contentType(new MediaType("application", "json", Charset.forName("UTF-8"))));

}

From source file:net.eusashead.hateoas.springhalbuilder.controller.CustomerControllerITCase.java

@Test
public void testPut() throws Exception {

    // Get the ETag
    this.mockMvc//from  w ww  . j a  v  a2s  .c  o  m
            .perform(request(HttpMethod.HEAD, "http://localhost/customer/1")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON))
            .andExpect(status().isNoContent()).andExpect(header().string("ETag", "\"3\"")).andReturn();

    // Create the request body
    Customer customer = new Customer();
    customer.setBirthday(new Date(0L));
    customer.setCustomerId(1);
    customer.setFirstName("New");
    customer.setLastName("Last");
    customer.setEmail("new.last@email.com");
    customer.setVersion(3);

    // Perform the update
    this.mockMvc
            .perform(put("http://localhost/customer/1").content(mapper.writeValueAsBytes(customer))
                    .header("If-Match", "\"3\"").contentType(MediaType.APPLICATION_JSON)
                    .characterEncoding(Charset.forName("UTF-8").toString()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent()).andReturn();

}

From source file:net.eusashead.hateoas.springhalbuilder.controller.OrderControllerITCase.java

@Test
public void testPut() throws Exception {

    // Get the ETag
    this.mockMvc//from  w ww .  j  av  a  2  s.com
            .perform(request(HttpMethod.HEAD, "http://localhost/order/1")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON))
            .andExpect(status().isNoContent()).andExpect(header().string("ETag", "\"1\"")).andReturn();

    // Create the request body
    Customer customer = new Customer();
    customer.setCustomerId(1);
    customer.setVersion(3);
    Order order = new Order();
    order.setCustomer(customer);
    order.setOrderId(1);
    order.setVersion(1);
    order.setDate(new Date());

    // Perform the PUT
    this.mockMvc
            .perform(put("http://localhost/order/1").content(mapper.writeValueAsBytes(order))
                    .header("If-Match", "\"1\"").contentType(MediaType.APPLICATION_JSON)
                    .characterEncoding(Charset.forName("UTF-8").toString()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent()).andReturn();

}

From source file:net.eusashead.hateoas.response.impl.HalPageResponseBuilderITCase.java

@Test
public void testHeadNotModified() throws Exception {
    // Execute controller method
    this.mockMvc/*from w  ww  .  j a  v a2 s. c om*/
            .perform(request(HttpMethod.HEAD, "http://localhost/customer/?page=1&size=15")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON)
                    .header("If-None-Match", "W/\"123456789\""))
            .andExpect(status().isNotModified()).andReturn();
}

From source file:net.eusashead.hateoas.springhalbuilder.controller.CustomerControllerITCase.java

@Test
public void testPutConcurrent() throws Exception {

    // Get the ETag
    this.mockMvc// w ww  .  j a  v  a 2  s  . c o m
            .perform(request(HttpMethod.HEAD, "http://localhost/customer/1")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON))
            .andExpect(status().isNoContent()).andExpect(header().string("ETag", "\"3\"")).andReturn();

    // Create the request body
    Customer customer = new Customer();
    customer.setBirthday(new Date(0L));
    customer.setCustomerId(1);
    customer.setFirstName("New");
    customer.setLastName("Last");
    customer.setEmail("new.last@email.com");
    customer.setVersion(2);

    // Perform the update
    this.mockMvc
            .perform(put("http://localhost/customer/1").content(mapper.writeValueAsBytes(customer))
                    .header("If-Match", "\"2\"").contentType(MediaType.APPLICATION_JSON)
                    .characterEncoding(Charset.forName("UTF-8").toString()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isPreconditionFailed()).andReturn();

}

From source file:net.eusashead.hateoas.springhalbuilder.controller.OrderControllerITCase.java

@Test
public void testDelete() throws Exception {

    // We need to get the ETag first
    this.mockMvc//from  ww  w . j  a  v a  2s  .  c  om
            .perform(request(HttpMethod.HEAD, "http://localhost/order/3")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON))
            .andExpect(status().isNoContent()).andExpect(header().string("ETag", "\"1\"")).andReturn();

    // Delete 
    this.mockMvc.perform(delete("http://localhost/order/3").contentType(HalHttpMessageConverter.HAL_JSON)
            .header("If-Match", "\"1\"").characterEncoding(Charset.forName("UTF-8").toString())
            .accept(HalHttpMessageConverter.HAL_JSON)).andExpect(status().isNoContent()).andReturn();

}

From source file:com.logsniffer.event.publisher.http.HttpPublisherTest.java

@Test
public void testHead() throws PublishException {
    stubFor(head(urlEqualTo("/eventId/12345678901")).willReturn(aResponse().withStatus(201)));
    publisher.setMethod(HttpMethod.HEAD);
    publisher.setUrl("http://localhost:" + port + "/eventId/12345678901");
    Event event = new Event();
    event.setId("123");
    publisher.publish(event);/*from w w  w. java  2s.co  m*/
}

From source file:net.eusashead.hateoas.springhalbuilder.controller.CustomerControllerITCase.java

@Test
public void testDelete() throws Exception {

    // We need to get the ETag first
    this.mockMvc/*from  w w w  .  j  av  a 2  s  .c o m*/
            .perform(request(HttpMethod.HEAD, "http://localhost/customer/4")
                    .contentType(HalHttpMessageConverter.HAL_JSON).accept(HalHttpMessageConverter.HAL_JSON))
            .andExpect(status().isNoContent()).andExpect(header().string("ETag", "\"1\"")).andReturn();

    // Delete 
    this.mockMvc.perform(delete("http://localhost/customer/4").contentType(HalHttpMessageConverter.HAL_JSON)
            .header("If-Match", "\"1\"").characterEncoding(Charset.forName("UTF-8").toString())
            .accept(HalHttpMessageConverter.HAL_JSON)).andExpect(status().isNoContent()).andReturn();

}

From source file:com.netflix.genie.web.services.impl.HttpFileTransferImplTest.java

/**
 * Make sure can get the last update time of a file.
 *
 * @throws GenieException On error//w ww.  ja  v a  2  s  . com
 */
@Test
public void canGetLastModifiedTime() throws GenieException {
    final long lastModified = 28424323000L;
    final HttpHeaders headers = new HttpHeaders();
    headers.setLastModified(lastModified);
    this.server.expect(MockRestRequestMatchers.requestTo(TEST_URL))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.HEAD))
            .andRespond(MockRestResponseCreators.withSuccess().headers(headers));

    Assert.assertThat(this.httpFileTransfer.getLastModifiedTime(TEST_URL), Matchers.is(lastModified));
    this.server.verify();
    Mockito.verify(this.metadataTimerId, Mockito.times(1)).withTags(MetricsUtils.newSuccessTagsMap());
    Mockito.verify(this.metadataTimer, Mockito.times(1)).record(Mockito.anyLong(),
            Mockito.eq(TimeUnit.NANOSECONDS));
}