Ejemplo n.º 1
0
  /**
   * Update the list of allowed countries for this job to Crowdflower (the list is set in the job)
   *
   * @param job
   * @throws HttpServerErrorException
   */
  void updateAllowedCountries(CrowdJob job) throws HttpServerErrorException {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());

    if (job.getExcludedCountries().size() > 0) {
      restTemplate.put(baseJobURL, job.getExcludedCountriesMap(), job.getId(), apiKey);
    }

    if (job.getIncludedCountries().size() > 0) {
      restTemplate.put(baseJobURL, job.getIncludedCountriesMap(), job.getId(), apiKey);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void updatePurchase(Long purchaseId, Purchase purchase) {
    Map requestVariables = new HashMap<String, String>();
    requestVariables.put("id", purchaseId.toString());

    restTemplate.put(urlUpdatePurchase, purchase, requestVariables);
  }
Ejemplo n.º 3
0
  @Test
  public void invalidInput() {

    // create
    Task titleBlankTask = new Task();
    try {
      restTemplate.postForLocation(resourceUrl, titleBlankTask);
      fail("Create should fail while title is blank");
    } catch (HttpStatusCodeException e) {
      assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
      Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class);
      assertThat(messages).hasSize(1);
      assertThat(messages.get("title")).isIn("may not be empty", "不能为空");
    }

    // update
    titleBlankTask.setId(1L);
    try {
      restTemplate.put(resourceUrl + "/1", titleBlankTask);
      fail("Update should fail while title is blank");
    } catch (HttpStatusCodeException e) {
      assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
      Map messages = jsonMapper.fromJson(e.getResponseBodyAsString(), Map.class);
      assertThat(messages).hasSize(1);
      assertThat(messages.get("title")).isIn("may not be empty", "不能为空");
    }
  }
Ejemplo n.º 4
0
  /** 创建/更新/删除任务. */
  @Test
  @Category(Smoke.class)
  public void createUpdateAndDeleteTask() {

    // create
    Task task = TaskData.randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(new Long(id));
    task.setTitle(TaskData.randomTitle());

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);

    try {
      restTemplate.getForObject(createdTaskUri, Task.class);
      fail("Get should fail while feth a deleted task");
    } catch (HttpStatusCodeException e) {
      assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
  }
  @Test
  public void putFailsWith404() {
    TestObject object = new TestObject();

    object.setData("data");
    template.put(baseUrl + "update", object);
  }
 /**
  * Upload an app using the legacy API used for older vcap versions like Micro Cloud Foundry 1.1
  * and older As of Micro Cloud Foundry 1.2 and for any recent CloudFoundry.com deployment the
  * current method of setting the content type as JSON works fine.
  *
  * @param path app path
  * @param entity HttpEntity for the payload
  * @param appName name of app
  * @throws HttpServerErrorException
  */
 private void uploadAppUsingLegacyApi(String path, HttpEntity<?> entity, String appName)
     throws HttpServerErrorException {
   RestTemplate legacyRestTemplate = new RestTemplate();
   legacyRestTemplate.setRequestFactory(this.getRestTemplate().getRequestFactory());
   legacyRestTemplate.setErrorHandler(new ErrorHandler());
   legacyRestTemplate.setMessageConverters(getLegacyMessageConverters());
   legacyRestTemplate.put(path, entity, appName);
 }
Ejemplo n.º 7
0
 public boolean requestToAddMyAssistantToRoster(String userName) {
   Address imbotRestAddress = m_addressManager.getSingleAddress(ImBot.REST_API);
   try {
     m_restTemplate.put(ADD_TO_ROSTER_URL, null, imbotRestAddress.toString(), userName);
   } catch (RestClientException ex) {
     return false;
   }
   return true;
 }
Ejemplo n.º 8
0
  /**
   * Sets a single key in Crowdflowers job with a given value
   *
   * @param job
   * @param key
   * @param value
   */
  void updateVariable(CrowdJob job, String Url, String key, String value) {
    MultiValueMap<String, String> argumentMap = new LinkedMultiValueMap<String, String>();
    argumentMap.add(key, value);

    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());

    restTemplate.put(Url, argumentMap, job.getId(), apiKey);
  }
  @Test
  public void testPathVariable() throws Exception {

    String restUrl = "/job/{jobExecutionId}/step/{stepId}/name/{stepName}";
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("jobExecutionId", "1");
    vars.put("stepId", "2");
    vars.put("stepName", "test");
    restTemplate.put(restUrl, null, vars);
    // Test will fail if status is not ok
  }
  /**
   * Mapping for update submit (POST)
   *
   * @param entry the entry which should be updated
   * @param model model
   * @return template name
   */
  @RequestMapping(value = "/updateSubmit", method = RequestMethod.POST)
  public String updateSubmitPost(@ModelAttribute Entry entry, Model model) {
    Map<String, String> params = new HashMap<>();
    params.put("id", String.valueOf(entry.getId()));

    RestTemplate restTemplate = new RestTemplate();
    restTemplate.put(GET_ENTRY, entry, params);
    model.addAttribute("resultmessage", "Eintrag erfolgreich aktualisiert!");
    model.addAttribute("entry", entry);
    return "result";
  }
Ejemplo n.º 11
0
 @RequestMapping(value = "/editReservation}")
 public String updateReservation(@RequestBody Reservation reservation) {
   LOG.debug("Update reservation with id" + reservation.getReservationId());
   RestTemplate restTemplate = new RestTemplate();
   String url = "http://localhost:8082/rest-service/reservation/updateReservation";
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("reservationId", reservation.getReservationId());
   map.put("reservationNumber", reservation.getReservationNumber());
   map.put("movieTitle", reservation.getMovieTitle());
   map.put("sessionTime", reservation.getSessionTime());
   map.put("place", reservation.getPlace());
   map.put("ticketPrice", reservation.getTicketPrice());
   map.put("clientId", reservation.getClientId());
   restTemplate.put(url, null, map);
   return "redirect:/ReservationHomePage";
 }
Ejemplo n.º 12
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 public void changePassword(OAuth2AccessToken token, String oldPassword, String newPassword) {
   HttpHeaders headers = new HttpHeaders();
   headers.add(AUTHORIZATION_HEADER_KEY, token.getTokenType() + " " + token.getValue());
   HttpEntity info = new HttpEntity(headers);
   ResponseEntity<String> response =
       restTemplate.exchange(authorizationUrl + "/userinfo", HttpMethod.GET, info, String.class);
   Map<String, Object> responseMap = JsonUtil.convertJsonToMap(response.getBody());
   String userId = (String) responseMap.get("user_id");
   Map<String, Object> body = new HashMap<String, Object>();
   body.put("schemas", new String[] {"urn:scim:schemas:core:1.0"});
   body.put("password", newPassword);
   body.put("oldPassword", oldPassword);
   HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers);
   restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId);
 }