@Override
  public void deletePurchase(Long purchaseId) {
    Map requestVariables = new HashMap<String, String>();
    requestVariables.put("id", purchaseId.toString());

    restTemplate.delete(urlDeletePurchase, requestVariables);
  }
示例#2
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);
    }
  }
  @RequestMapping(value = "/delete/{reservationId}")
  public String deleteReservation(@PathVariable(value = "reservationId") Integer reservationId) {
    RestTemplate restTemplate = new RestTemplate();
    // final String uri1 = "http://localhost:8082/rest-service/reservation/delete/{reservationId}";

    Map<String, Integer> params = new HashMap<String, Integer>();
    params.put("reservationId", reservationId);
    restTemplate.delete(uriDeleteReservation, params);
    return "redirect:/ReservationHomePage";
  }
 @Override
 protected Void doInBackground(String... params) {
   try {
     final String url = params[0];
     RestTemplate restTemplate = RestUtils.getInstance();
     restTemplate.delete(url);
   } catch (Exception e) {
     this.exception = e;
     Log.e(TAG, e.getMessage(), e);
   }
   return null;
 }
示例#5
0
  /** Tests the removal of an existing product */
  @Test
  public void removeProduct() {
    String uri =
        "http://localhost:8080/rest_test/spring/warehouses/{warehouseId}/products/{productId}";
    restTemplate.delete(uri, WAREHOUSE_ID, PRODUCT_ID);

    try {
      restTemplate.getForObject(uri, Product.class, WAREHOUSE_ID, PRODUCT_ID);
      throw new AssertionError("Should have returned an 404 error code");
    } catch (HttpClientErrorException e) {
      assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
    }
  }
  /**
   * Mapping for delete submit
   *
   * @param id id of the entry or
   * @param title title of the entry
   * @param model model
   * @return template name
   */
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  public String deletePost(
      @RequestParam(value = "entryid", required = false, defaultValue = "") String id,
      @RequestParam(value = "title", required = false, defaultValue = "") String title,
      Model model) {
    Map<String, String> params = new HashMap<>();
    if (!id.isEmpty()) {
      params.put("id", id);
      restTemplate.delete(GET_ENTRY, params);

      model.addAttribute("resultmessage", "Eintrag mit id " + id + " erfolgreich entfernt!");
    } else if (!title.isEmpty()) {
      params.put("title", title);
      Entry[] entries = restTemplate.getForObject(GET_BY_TITLE, Entry[].class, params);
      StringBuilder sb = new StringBuilder();
      for (Entry cur : entries) {
        params.clear();
        params.put("id", String.valueOf(cur.getId()));
        restTemplate.delete(GET_ENTRY, params);
        sb.append(cur.getId()).append(", ");
      }

      if (entries.length == 0) {
        model.addAttribute("resultmessage", "Keine Eintraege entfernt!");
      } else if (entries.length == 1) {
        model.addAttribute(
            "resultmessage", "Eintrag mit id " + entries[0].getId() + " erfolgreich entfernt!");
      } else {
        model.addAttribute(
            "resultmessage", "Eintraege mit ids " + sb.toString() + " erfolgreich entfernt!");
      }
    } else {
      model.addAttribute("resultmessage", "Weder ID noch Titel angegeben!");
    }
    return "result_special";
  }
 @Test
 public void deleteTest() {
   try {
     String nombreEmpresa =
         (String)
             jdbcTemplate.queryForObject(
                 "SELECT NOMBRE FROM EMPRESA WHERE NIF= ?",
                 new Object[] {"nifPrueba"},
                 String.class);
     assertTrue(nombreEmpresa.equals("nombrePrueba"));
     URI uri = new URI(dirFrontEnd.toString() + "/empresa/nifPrueba");
     restTemplate.delete(uri);
   } catch (Exception e) {
     e.printStackTrace();
     fail();
   }
   assertTrue(empresaService.findByNif("nifPrueba") == null);
 }
示例#8
0
  @RequestMapping(value = "/doQuit", method = RequestMethod.POST)
  public ModelAndView doQuit(@Valid HelloModel helloModel, BindingResult bindingResult) {
    ApplicationContext context =
        new ClassPathXmlApplicationContext("controller/webservice/spring.xml");
    String ERROR = (String) context.getBean("ERROR");

    List<FieldError> feeErrors = new ArrayList<FieldError>();

    if (bindingResult.hasErrors()) {
      return new ModelAndView(ERROR, "ErrorModel", bindingResult.getFieldErrors());
    }

    String fee_service = (String) context.getBean("fee_service");
    String fee_provider = fee_service.split("/")[3].split("_")[0];

    String name = helloModel.getName();

    FeeModel feeModel = (FeeModel) context.getBean("feeModel");
    feeModel.setName(name);

    int count;

    try {
      try {
        feeModel =
            restTemplate.getForObject(
                new StringBuilder(fee_service)
                    .append("/findByName?name=")
                    .append(feeModel.getName())
                    .toString(),
                FeeModel.class);
      } catch (RestClientException restClientException) {
        String statusCode = restClientException.getMessage();

        if (statusCode.equals("404 Not Found")) {
          throw new NullAccountException();
        } else {
          throw restClientException;
        }
      }

      count = feeModel.getCount();

      if (count > 0) {
        throw new FeeNotPaidException();
      } else if (count == 0) {
        restTemplate.delete(
            new StringBuilder(fee_service).append("/").append(feeModel.getId()).toString());
      }
    } catch (NullAccountException e) {
      feeErrors.add(
          new FieldError("QuitController", e.getMessage(), resource.getString(e.getMessage())));
      return new ModelAndView(ERROR, "ErrorModel", feeErrors);
    } catch (FeeNotPaidException e) {
      feeErrors.add(
          new FieldError("QuitController", e.getMessage(), resource.getString(e.getMessage())));
      return new ModelAndView(ERROR, "ErrorModel", feeErrors);
    } catch (RestClientException e) {
      feeErrors.add(
          new FieldError(
              "QuitController",
              "error.http",
              resource.getString("error.http") + "<br>" + e.getMessage()));
      return new ModelAndView(ERROR, "ErrorModel", feeErrors);
    } catch (Exception e) {
      feeErrors.add(
          new FieldError(
              "QuitController",
              "error.database",
              resource.getString("error.database") + "<br>" + e.getMessage()));
      return new ModelAndView(ERROR, "ErrorModel", feeErrors);
    }

    FeeProviderModel feeProviderModel = (FeeProviderModel) context.getBean("feeProviderModel");
    feeProviderModel.setFeeModel(feeModel);
    feeProviderModel.setFeeProvider(fee_provider);

    String SUCCESS = (String) context.getBean("quitSUCCESS");
    return new ModelAndView(SUCCESS, "FeeProviderModel", feeProviderModel);
  }