コード例 #1
0
 @Test
 public void getTest() {
   try {
     URI uri = new URI(dirFrontEnd + "/empresa/nifPrueba");
     Resource<Empresa> resource =
         restTemplate
             .exchange(
                 uri, HttpMethod.GET, null, new ParameterizedTypeReference<Resource<Empresa>>() {})
             .getBody();
     assertTrue(resource.getContent().getNombre().equals("nombrePrueba"));
   } catch (Exception e) {
     e.printStackTrace();
     fail();
   }
 }
コード例 #2
0
    /**
     * Returns whether the given {@link Resource} matches the given target {@link ResolvableType}.
     * We inspect the {@link Resource}'s value to determine the match.
     *
     * @param resource
     * @param target must not be {@literal null}.
     * @return whether the given {@link Resource} can be assigned to the given target {@link
     *     ResolvableType}
     */
    private static boolean isValueTypeMatch(Resource<?> resource, ResolvableType target) {

      if (resource == null || !isRawTypeAssignable(target, resource.getClass())) {
        return false;
      }

      Object content = resource.getContent();

      if (content == null) {
        return false;
      }

      ResolvableType type = findGenericType(target, Resource.class);
      return type != null
          && type.getGeneric(0).isAssignableFrom(ResolvableType.forClass(content.getClass()));
    }
コード例 #3
0
  @Test
  public void getCompany() throws Exception {

    ResponseEntity<Resource<Company>> responseEntity =
        restTemplate.exchange(
            "http://localhost:{port}/api/companies/1",
            HttpMethod.GET,
            null,
            new ParameterizedTypeReference<Resource<Company>>() {},
            port);

    if (responseEntity.getStatusCode() == HttpStatus.OK) {
      Resource<Company> companyResource = responseEntity.getBody();
      Company company = companyResource.getContent();

      assertEquals("Microsoft 0", company.getName());

      // TODO the company object has no owners in its collection, how can I test this

    } else {
      fail();
    }
  }