Example usage for org.springframework.http HttpMethod PUT

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

Introduction

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

Prototype

HttpMethod PUT

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

Click Source Link

Usage

From source file:com.orange.ngsi.client.NgsiRestClient.java

/**
 * Update the attribute of a context element
 * @param url the URL of the broker/* w  w  w  .java2 s.  com*/
 * @param httpHeaders the HTTP header to use, or null for default
 * @param entityID the ID of the entity
 * @param attributeName the name of the attribute
 * @param updateContextAttribute attribute to update
 * @return a future for a StatusCode
 */
public ListenableFuture<StatusCode> updateContextAttribute(String url, HttpHeaders httpHeaders, String entityID,
        String attributeName, UpdateContextAttribute updateContextAttribute) {
    return request(HttpMethod.PUT, url + entitiesPath + entityID + attributesPath + attributeName, httpHeaders,
            updateContextAttribute, StatusCode.class);
}

From source file:com.orange.ngsi.client.NgsiRestClientTest.java

@Test
public void testUpdateContextElement_JSON() throws Exception {
    String responseBody = json(jsonConverter, createUpdateContextElementResponseTemperature());

    mockServer.expect(requestTo(baseUrl + "/ngsi10/contextEntities/123")).andExpect(method(HttpMethod.PUT))
            .andExpect(jsonPath("$.attributes").isArray())
            .andExpect(jsonPath("$.attributes[0].name").value("temp"))
            .andExpect(jsonPath("$.attributes[0].type").value("float"))
            .andExpect(jsonPath("$.attributes[0].value").value("15.5"))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    UpdateContextElementResponse response = ngsiRestClient
            .updateContextElement(baseUrl, null, "123", Util.createUpdateContextElementTemperature()).get();

    this.mockServer.verify();

    assertNull(response.getErrorCode());
    assertNotNull(response.getContextAttributeResponses());
    assertEquals(1, response.getContextAttributeResponses().size());
    assertNotNull(response.getContextAttributeResponses().get(0).getContextAttributeList());
    assertEquals(1, response.getContextAttributeResponses().get(0).getContextAttributeList().size());
    assertNotNull(response.getContextAttributeResponses().get(0).getContextAttributeList().get(0));
    assertEquals("temp",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getName());
    assertEquals("float",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getType());
    assertEquals("15.5",
            response.getContextAttributeResponses().get(0).getContextAttributeList().get(0).getValue());
    assertEquals(CodeEnum.CODE_200.getLabel(),
            response.getContextAttributeResponses().get(0).getStatusCode().getCode());
}

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImplTest.java

@Test
public void testUpdatePageWithPaginationModeSingleAndNoTableOfContents() {
    final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig();
    swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage(false);

    final String xhtml = IOUtils.readFull(
            AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream("/swagger-petstore-xhtml-example.html"));

    final ResponseEntity<String> postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)))
            .thenReturn(responseEntity);
    when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND);
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), any(RequestEntity.class), eq(String.class)))
            .thenReturn(postResponseEntity);

    final ArgumentCaptor<HttpEntity> httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class);

    xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml);

    verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class),
            eq(String.class));
    verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.PUT), httpEntityCaptor.capture(),
            eq(String.class));

    final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getValue();

    final String expectedPostBody = IOUtils.readFull(AsciiDocToXHtmlServiceImplTest.class
            .getResourceAsStream("/swagger-confluence-update-json-body-example.json"));

    assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity);
    assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody());
}

From source file:org.openbaton.common.vnfm_sdk.rest.VnfmRestHelper.java

private void put(String path, String json) {
    HttpEntity<String> requestEntity = new HttpEntity<>(json, headers);
    ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.PUT, requestEntity,
            String.class);
    this.setStatus(responseEntity.getStatusCode());
}

From source file:org.kurento.repository.test.RangePutTests.java

private ResponseEntity<String> putContent(String url, byte[] info, int firstByte) {

    RestTemplate httpClient = getRestTemplate();

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Range", "bytes " + firstByte + "-" + (firstByte + info.length) + "/*");
    requestHeaders.set("Content-Length", Integer.toString(info.length));

    HttpEntity<byte[]> requestEntity = new HttpEntity<byte[]>(info, requestHeaders);

    ResponseEntity<String> response = httpClient.exchange(url, HttpMethod.PUT, requestEntity, String.class);

    log.info("Put " + info.length + " bytes from " + firstByte + " to " + (firstByte + info.length));

    return response;

}

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

@Test
public void testPut() throws PublishException {
    stubFor(put(urlEqualTo("/eventId/1234567"))
            .withHeader("Content-Type", equalTo("application/json; charset=UTF-8"))
            .withRequestBody(equalTo("{}")).willReturn(aResponse().withStatus(HttpStatus.OK.value())
                    .withHeader("Content-Type", "text/xml").withBody("<response>Some content</response>")));
    publisher.setMethod(HttpMethod.PUT);
    publisher.setBodyMimeType("application/json");
    publisher.setUrl("http://localhost:" + port + "/eventId/1234567");
    publisher.setBody("{}");
    Event event = new Event();
    event.setId("123");
    publisher.publish(event);/*from  w  w  w. j  a  v a2s.c o m*/
}

From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java

public synchronized int updateTraceabilityRecord(String serviceId, String traceabilityRecordURI,
        String traceabilityNewEntryData) {

    logger.info("URI to the updated record: " + traceabilityRecordURI);
    //String restURI = "http://" + server_add + ":" + port_no + "/" + service
    //   + "/" + resource + "/" + serviceId + "/"
    //+ this.TRACEABILITY_TYPE + "/" + traceabilityExistingEntryId;

    RestTemplate restTemplate = new RestTemplate();

    HttpEntity<String> entityContent = new HttpEntity<String>(traceabilityNewEntryData, null);

    ResponseEntity<String> response = restTemplate.exchange(traceabilityRecordURI, HttpMethod.PUT,
            entityContent, String.class);

    // int responseNo = restTemplate.getForObject(restURI, Integer.class);
    //      restTemplate.put(traceabilityRecordURI, traceabilityNewEntryData);

    // TODO - how do I get the header value

    return response.getStatusCode().value();
}

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

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

From source file:org.cloudfoundry.identity.uaa.integration.PasswordChangeEndpointIntegrationTests.java

@Test
@OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.Implicit.class, initialize = false)
public void testUserChangesOwnPassword() throws Exception {

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    parameters.set("source", "credentials");
    parameters.set("username", joe.getUserName());
    parameters.set("password", "password");
    context.getAccessTokenRequest().putAll(parameters);

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setOldPassword("password");
    change.setPassword("newpassword");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId());
    assertEquals(HttpStatus.OK, result.getStatusCode());

    // Now try logging in with the new credentials
    headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    String credentials = String.format("{ \"username\":\"%s\", \"password\":\"%s\" }", joe.getUserName(),
            "newpassword");

    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("credentials", credentials);
    result = serverRunning.postForResponse(implicitUrl(), headers, formData);

    assertNotNull(result.getHeaders().getLocation());
    assertTrue(result.getHeaders().getLocation().toString()
            .matches("https://uaa.cloudfoundry.com/redirect/vmc#access_token=.+"));
}

From source file:net.nfpj.webcounter.api.CounterIT.java

/**
 * Test of incCounter method, of class CounterRestService.
 *///  w  w w  .  j a  va2  s  .c o m
@Test
public void testIncCounter() {
    String name = "C1Inc";
    createCounter(name);
    ResponseEntity<Counter> entity = restTemplate.exchange("/counter/{name}/", HttpMethod.PUT, null,
            Counter.class, name);
    assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), 200,
            entity.getStatusCodeValue());
    assertEquals(new Counter(name, 1), entity.getBody());
}