Exemplo n.º 1
0
  public Frete calculaFrete(Pedido p) throws Throwable {
    Frete frete = null;

    URL obj =
        new URL(
            "http://localhost:8090/calcularFrete?peso="
                + p.getPeso()
                + "&largura="
                + p.getLargura()
                + "&altura="
                + p.getAltura()
                + "&comprimento="
                + p.getComprimento()
                + "&tipoEntrega="
                + p.getTipoEntrega()
                + "&cep="
                + p.getCep());
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("GET");

    int responseCode = con.getResponseCode();

    if (responseCode == 200) {
      BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
      String inputLine;
      StringBuffer response = new StringBuffer();

      while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
      }
      in.close();

      JSONObject json = (JSONObject) new JSONParser().parse(response.toString());

      String valorResp = json.get("Valor").toString();
      String tempoEntregaResp = json.get("PrazoEntrega").toString();

      frete = new Frete();
      frete.setTempoEntrega(Integer.valueOf(tempoEntregaResp));
      frete.setValor(Double.valueOf(valorResp));

      dao.saveDadosDeEntrega(frete.getValor(), frete.getTempoEntrega());
    } else if (responseCode == 400) {
      throw new Throwable("The zipcode is not valid");
    } else if (responseCode == 500) {
      throw new Throwable("CorreioServices is offline right now");
    }
    return frete;
  }
Exemplo n.º 2
0
 @And("^shipping time should be (\\d+)$")
 public void shipping_time_should_be__tempoEntrega(int param1) {
   assertEquals(param1, frete.getTempoEntrega());
 }
Exemplo n.º 3
0
 @Then("^the shipping cost should be (\\d+)$")
 public void the_shipping_cost_should_be__valor(double param1) {
   assertEquals(Double.valueOf(param1), frete.getValor());
 }