@Test
  public void whenSignUpTwiceWithSameEmail_shouldFailOnSecondSignUp() throws Exception {
    HttpRequest signUpRequest = signUpRequest("*****@*****.**", "pass");
    assertThat(signUpRequest.code()).isEqualTo(CREATED.getStatusCode());

    HttpRequest signUpRequest2 = signUpRequest("*****@*****.**", "pass");
    assertThat(signUpRequest2.code()).isEqualTo(CONFLICT.getStatusCode());
  }
  @Test
  public void signOut_shouldReturnTrue_ifSignsOutBeingSignedIn() throws Exception {
    HttpRequest signUpRequest = signUpRequest("*****@*****.**", "pass");
    assertThat(signUpRequest.code()).isEqualTo(CREATED.getStatusCode());
    String token = signUpRequest.body().toString();
    assertThat(token).isNotEmpty();

    HttpRequest signOutRequest = signOutRequest(token);
    assertThat(signOutRequest.code()).isEqualTo(OK.getStatusCode());
    assertThat(signOutRequest.body()).isEqualTo("true");
  }
 @Override
 public void run() {
   try {
     HttpRequest request = HttpRequest.put(this.getUrlString());
     this.setupSecurity(request);
     request.acceptCharset(CHARSET);
     request.headers(this.getHeaders());
     request.form(this.getParams());
     int code = request.code();
     String body = request.body(CHARSET);
     JSONObject response = new JSONObject();
     response.put("status", code);
     if (code >= 200 && code < 300) {
       response.put("data", body);
       this.getCallbackContext().success(response);
     } else {
       response.put("error", body);
       this.getCallbackContext().error(response);
     }
   } catch (JSONException e) {
     this.respondWithError("There was an error generating the response");
   } catch (HttpRequestException e) {
     if (e.getCause() instanceof UnknownHostException) {
       this.respondWithError(0, "The host could not be resolved");
     } else if (e.getCause() instanceof SSLHandshakeException) {
       this.respondWithError("SSL handshake failed");
     } else {
       this.respondWithError("There was an error with the request");
     }
   }
 }
 @Override
 public ActionPlan create(NewActionPlan newActionPlan) {
   HttpRequest request = requestFactory.post(NewActionPlan.BASE_URL, newActionPlan.urlParams());
   if (!request.ok()) {
     throw new IllegalStateException(
         "Fail to create action plan. Bad HTTP response status: " + request.code());
   }
   return createActionPlanResult(request);
 }
 private HttpRequest executeSimpleAction(String actionPlanKey, String action) {
   HttpRequest request =
       requestFactory.post(
           "/api/action_plans/" + action, EncodingUtils.toMap("key", actionPlanKey));
   if (!request.ok()) {
     throw new IllegalStateException(
         "Fail to " + action + " action plan. Bad HTTP response status: " + request.code());
   }
   return request;
 }
    @Override
    // 1.data 통신
    public ArrayList<String> call() throws Exception {
      JSONResultString result = null;
      ArrayList<String> arrayList1 = new ArrayList<String>();
      try {

        HttpRequest request = post("http://192.168.0.5:8088/bitin/api/class/start-attd ");

        // reiquest 설정
        request.connectTimeout(2000).readTimeout(2000);
        // JSON  포맷으로 보내기  => POST 방식
        request.acceptCharset("UTF-8");
        request.acceptJson();
        request.accept(HttpRequest.CONTENT_TYPE_JSON);
        request.contentType("application/json", "UTF-8");

        // 데이터 세팅
        JSONObject params1 = new JSONObject();
        params1.put("classNo", classNo);
        params1.put("startTime", endTime);
        params1.put("timer", count_timer);

        Log.d("JoinData-->", params1.toString());
        request.send(params1.toString());

        // 3. 요청
        int responseCode = request.code();
        if (HttpURLConnection.HTTP_OK != responseCode) {
          Log.e("HTTP fail-->", "Http Response Fail:" + responseCode);
          return null;
        } else {
          Log.e("HTTPRequest-->", "정상");
        }

        // 4. JSON 파싱
        Reader reader = request.bufferedReader();
        // Log.d("Reader",reader);
        result = GSON.fromJson(reader, JSONResultString.class);
        reader.close();

        // 5. 사용하기
        Log.d("---> ResponseResult-->", result.getResult()); // "success"? or "fail"?
        Log.d("--->Data-->", result.getData().toString());

        return result.getData();

      } catch (Exception e3) {
        e3.printStackTrace();
      }
      return result.getData();
    }
  @Test
  public void testFind() throws Exception {
    expect(client.get("products/70")).andReturn(request);
    expect(request.code()).andReturn(200);
    expect(request.body()).andReturn(productResponse(true));
    replayAll();

    Response<Product> response = Product._find(client, 70);
    Product product = response.getResource();

    assertEquals("Wrong product name", "Basic", product.getName());
    assertEquals("Wrong product handle", "basic", product.getHandle());
  }
 @Override
 public List<ActionPlan> find(String projectKey) {
   HttpRequest request =
       requestFactory.get(ActionPlanQuery.BASE_URL, EncodingUtils.toMap("project", projectKey));
   if (!request.ok()) {
     throw new IllegalStateException(
         "Fail to search for action plans. Bad HTTP response status: " + request.code());
   }
   List<ActionPlan> result = new ArrayList<ActionPlan>();
   String json = request.body("UTF-8");
   Map jsonRoot = (Map) JSONValue.parse(json);
   List<Map> jsonActionPlans = (List) jsonRoot.get("actionPlans");
   if (jsonActionPlans != null) {
     for (Map jsonActionPlan : jsonActionPlans) {
       result.add(new ActionPlan(jsonActionPlan));
     }
   }
   return result;
 }
  public Drawable getDrawable(String source) {
    File output = null;
    try {
      output = File.createTempFile("image", ".jpg", dir);
      HttpRequest request = createRequest(source);
      if (!request.ok()) throw new IOException("Unexpected response code: " + request.code());
      request.receive(output);
      Bitmap bitmap = ImageUtils.getBitmap(output, width, MAX_VALUE);
      if (bitmap == null) return loading.getDrawable(source);

      BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
      drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
      return drawable;
    } catch (IOException e) {
      return loading.getDrawable(source);
    } catch (HttpRequestException e) {
      return loading.getDrawable(source);
    } finally {
      if (output != null) output.delete();
    }
  }
 @Test
 public void signOut_shouldReturnFalse_ifSignsOutWithoutBeingSignedIn() throws Exception {
   HttpRequest signOutRequest = signOutRequest("TOKEN");
   assertThat(signOutRequest.code()).isEqualTo(UNAUTHORIZED.getStatusCode());
   assertThat(signOutRequest.body()).isEqualTo("false");
 }
  @Test
  public void signIn_shouldReturnUnauthorizedStatusCode_ifNotLoggedIn() throws Exception {
    HttpRequest signInRequest = signInRequest("notLoggedInEmail", "pass");

    assertThat(signInRequest.code()).isEqualTo(UNAUTHORIZED.getStatusCode());
  }
  @Test
  public void signIn_shouldReturnBadRequestStatusCode_ifNullParameters() throws Exception {
    HttpRequest signInRequest = signInRequest("", "");

    assertThat(signInRequest.code()).isEqualTo(BAD_REQUEST.getStatusCode());
  }
 @Test
 public void signUp_shouldCreateAnUser() throws Exception {
   HttpRequest signUpRequest = signUpRequest("*****@*****.**", "pass");
   assertThat(signUpRequest.code()).isEqualTo(CREATED.getStatusCode());
 }
 @Test
 public void signUpWithEmptyFormData_shouldFail() throws Exception {
   HttpRequest signUpRequest = signUpRequest("", "");
   assertThat(signUpRequest.code()).isEqualTo(BAD_REQUEST.getStatusCode());
 }
 /**
  * Execute request
  *
  * @param request
  * @return request
  * @throws IOException
  */
 protected HttpRequest execute(final HttpRequest request) throws IOException {
   if (!configure(request).ok())
     throw new IOException("Unexpected response code: " + request.code());
   return request;
 }