/** Test delete entity. */
  @Test
  public void testDeleteEntity() {
    HttpStatus status = deleteEntity(deleteEntityUrl(), getEntity().getId());
    assertEquals(status.toString(), "204");

    // set the Entity to null so we don't try to delete it again in @After
    setEntity(null);
  }
  /** Test put entity. */
  @Test
  public void testPutEntity() {
    Map<String, String> uriVariables = new HashMap<String, String>();
    uriVariables.put("id", String.valueOf(getEntity().getId()));

    // call the update for the RESTful API
    HttpStatus status = putEntity(putEntityUrl(), uriVariables, getEntity());
    assertEquals(status.toString(), "204");

    // double-check the Entity info was updated by re-pulling the Entity
    E retrievedEntity = getEntity(getEntityUrl(), getEntity().getId(), getClazz());
    assertEquals(retrievedEntity.getId(), getEntity().getId());
  }
  @Background
  void sendAuthRequest(SingupRequestEntity requestEntity) {

    try {
      TokenResponseEntity response = restClient.authSignupUser(requestEntity);

      if (response == null) {
        showErrorNotification("sign up fail");
        return;
      }

      Log.w(TAG, "token: " + response.getToken());
      prefs.edit().bookfusionAccessToken().put(response.getToken()).apply();

      ProfileDataResponseEntity profile =
          restClient.getProfileData(
              CommonUtils.getDeviceID(getActivity()), prefs.bookfusionAccessToken().get());
      prefs.edit().currentUserId().put(profile.getId()).apply();

      showSignInNotification();

    } catch (RestClientException clientException) {
      HttpStatus status = null;
      if (clientException instanceof HttpClientErrorException) {
        status = ((HttpClientErrorException) clientException).getStatusCode();
      } else if (clientException instanceof HttpServerErrorException) {
        status = ((HttpServerErrorException) clientException).getStatusCode();
      }

      String errorMessage;
      if (status != null) {
        errorMessage = HttpUtils.getHttpErrorMessage(status.toString());
      } else {
        errorMessage = "Error happened, try again please";
      }

      showErrorNotification(errorMessage);
      Log.e(TAG, "Error happened: " + clientException.getMessage());
    }
  }
Пример #4
0
  /** Execute updateEntity. */
  @Test
  public void testUpdateEntity() {
    Long id = getEntity().getId();
    String updatedValue = "updated value";

    TagDto entity = new TagDto();
    entity.setName(updatedValue);

    // build the URL
    String apiUrl = getServerAddress() + ResourceUrls.tagUpdate;

    // set the URL parameter
    Map<String, String> vars = Collections.singletonMap("id", String.valueOf(id));

    // make the REST call
    HttpStatus status = updateEntity(apiUrl, vars, entity);
    assertEquals(status.toString(), "204");

    // double-check the Entity info was updated by re-pulling the Entity
    TagDto retrievedEntity = getEntity(getEntityUrl(), getEntity().getId(), getClazz());
    assertEquals(updatedValue, retrievedEntity.getName());
  }
  public GoogleSearchResponse search(String searchString, String referer) {
    try {
      if (ValidatorUtil.isNull(referer)) {
        referer = "http://longfalcon.net";
      }

      String v = "1.0";
      String userip = "192.168.0.1";
      HttpHeaders httpHeaders = new HttpHeaders();
      httpHeaders.set("Referer", referer);

      HttpEntity<?> requestEntity = new HttpEntity(httpHeaders);

      UriComponents uriComponents =
          UriComponentsBuilder.fromUriString(_SEARCH_URL)
              .queryParam("v", v)
              .queryParam("q", searchString)
              .queryParam("userip", userip)
              .build();
      ResponseEntity<GoogleSearchResponse> responseEntity =
          restTemplate.exchange(
              uriComponents.toUri(), HttpMethod.GET, requestEntity, GoogleSearchResponse.class);
      HttpStatus statusCode = responseEntity.getStatusCode();
      if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) {
        return responseEntity.getBody();
      } else {
        _log.error(
            String.format(
                "Search request: \n%s\n failed with HTTP code %s : %s",
                uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase()));
        return null;
      }
    } catch (Exception e) {
      _log.error(e);
    }

    return null;
  }