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.ngsi2.client.Ngsi2ClientTest.java

@Test
public void testUpdateAttribute_OK() throws Exception {

    mockServer.expect(requestTo(baseURL + "/v2/entities/room1/attrs/temperature?type=Room"))
            .andExpect(method(HttpMethod.PUT))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.value").value(35.6))
            .andExpect(jsonPath("$.metadata.timestamp.type").value("date"))
            .andExpect(jsonPath("$.metadata.timestamp.value").value("2015-06-04T07:20:27.378Z"))
            .andRespond(withNoContent());

    Attribute attribute = new Attribute(35.6);
    attribute.addMetadata("timestamp", new Metadata("date", "2015-06-04T07:20:27.378Z"));
    ngsiClient.updateAttribute("room1", "Room", "temperature", attribute).get();
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void compareAndSwapWithPrevValue() throws EtcdException {
    server.expect(/*from w w w.j a  v a 2  s  .  c o m*/
            MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevValue=Hello%20etcd"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.compareAndSwap("sample", "Hello world", "Hello etcd");
    Assert.assertNotNull("response", response);

    server.verify();
}

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

@Test
public void testUpdateContextAttributeValue_JSON() throws Exception {
    String responseBody = json(jsonConverter, new StatusCode(CodeEnum.CODE_200));

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

    StatusCode response = ngsiRestClient.updateContextAttributeValue(baseUrl, null, "123", "temp", "1",
            Util.createUpdateContextAttributeTemperature()).get();

    this.mockServer.verify();

    assertEquals(CodeEnum.CODE_200.getLabel(), response.getCode());
}

From source file:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public DeviceAssignment updateDeviceAssignmentState(String token, DeviceEventBatch batch)
        throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("token", token);
    return sendRest(getBaseUrl() + "assignments/{token}/state", HttpMethod.PUT, batch, DeviceAssignment.class,
            vars);/*from w ww .j  a v  a  2  s .  c o m*/
}

From source file:org.cbioportal.session_service.SessionServiceTest.java

@Test
public void updateSession() throws Exception {
    String data = "\"portal-session\":\"my session information\"";
    ResponseEntity<String> response = addData("msk_portal", "main_session", data);

    // get id//ww w .  j a v a 2  s  .co  m
    List<String> ids = parseIds(response.getBody());
    assertThat(ids.size(), equalTo(1));
    String id = ids.get(0);

    // get record
    response = template.getForEntity(base.toString() + "msk_portal/main_session/" + id, String.class);
    assertThat(expectedResponse(response.getBody(), "msk_portal", "main_session", data), equalTo(true));

    // update record
    data = "\"portal-session\":\"my session UPDATED information\"";
    HttpEntity<String> entity = prepareData(data);
    response = template.exchange(base.toString() + "msk_portal/main_session/" + id, HttpMethod.PUT, entity,
            String.class);
    assertThat(response.getBody(), equalTo(null));

    // get updated record
    response = template.getForEntity(base.toString() + "msk_portal/main_session/" + id, String.class);
    assertThat(expectedResponse(response.getBody(), "msk_portal", "main_session", data), equalTo(true));
    assertThat(response.getBody(), containsString("UPDATED"));
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * Atomically updates a key-value pair in etcd.
 * /* w w  w  .  j  a va 2s .c o  m*/
 * @param key
 *            the key
 * @param value
 *            the value
 * @param prevIndex
 *            the modified index of the key
 * @return the response from etcd with the node
 * @throws EtcdException
 *             in case etcd returned an error
 */
public EtcdResponse compareAndSwap(String key, String value, int prevIndex) throws EtcdException {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE);
    builder.pathSegment(key);
    builder.queryParam("prevIndex", prevIndex);

    MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1);
    payload.set("value", value);

    return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class);
}

From source file:com.all.ultrapeer.services.UserProfileService.java

@MessageMethod(UPDATE_USER_PROFILE_TYPE)
public void processUpdateProfileMessage(AllMessage<User> message) {
    log.info("Processing an update profile request.");
    User user = message.getBody();/*from ww w . j  av  a 2 s  .  c  o m*/
    String[] urlVars = BackendProxy.urlVars(message.getProperty(SENDER_ID));
    String[][] headers = BackendProxy.headers(
            BackendProxy.header(MessEngineConstants.PUSH_TO, message.getProperty(MessEngineConstants.PUSH_TO)));
    userBackend.send("updateProfileUrl", HttpMethod.PUT, user, urlVars, headers);
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void compareAndSwapWithPrevValueAndSetTtl() throws EtcdException {
    server.expect(MockRestRequestMatchers
            .requestTo("http://localhost:2379/v2/keys/sample?ttl=60&prevValue=Hello%20etcd"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.compareAndSwap("sample", "Hello world", 60, "Hello etcd");
    Assert.assertNotNull("response", response);

    server.verify();//w w  w  .  j a v  a 2  s .c  om
}

From source file:com.all.ultrapeer.services.UserProfileService.java

@MessageMethod(UPDATE_USER_AVATAR_TYPE)
public void processUpdateAvatarMessage(AllMessage<Avatar> message) {
    try {/*  w  w w .j  a  va 2  s. c om*/
        log.info("Processing an avatar update request");
        // user/avatar
        String[][] headers = BackendProxy.headers(BackendProxy.header(MessEngineConstants.PUSH_TO,
                message.getProperty(MessEngineConstants.PUSH_TO)));
        userBackend.send("updateAvatarUrl", HttpMethod.PUT, message.getBody(), null, headers);
    } catch (RestClientException e) {
        log.error("error in update avatar", e);
    }
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java

private void updateUIApp(String orgId, String username, String uiCallback, String uiAppGuid, String password,
        String gearpumpMaster, String uaaClientName) throws IOException {
    LOGGER.info("Updating App Environments Instance");
    String body = String.format(UPDATE_APP_ENV_BODY_TEMPLATE, username, password, gearpumpMaster, uaaClientName,
            password, loginHost(), cfApiEndpoint, orgId, uiCallback);
    LOGGER.debug("Update app body: {}", body);
    execute(UPDATE_APP_URL, HttpMethod.PUT, body, cfApiEndpoint, uiAppGuid);
}