Exemple #1
0
  /** @see HttpHeaderTestService#getLanguage(javax.ws.rs.core.HttpHeaders) */
  public void testLanguage() throws IOException {
    final List<Preference<Language>> acceptedLanguages = new ArrayList<Preference<Language>>();
    acceptedLanguages.add(new Preference<Language>(Language.ENGLISH));
    final ClientInfo clientInfo = new ClientInfo();
    clientInfo.setAcceptedLanguages(acceptedLanguages);

    final Request request =
        new Request(Method.POST, createReference(HttpHeaderTestService.class, "language"));
    request.setClientInfo(clientInfo);
    request.setEntity(new StringRepresentation("entity", Language.ENGLISH));
    final Response response = accessServer(request);

    assertEquals(Status.SUCCESS_OK, response.getStatus());
    assertEquals("en", response.getEntity().getText());
  }
  protected Request createRequest(Method method, String path) {
    // TODO: in restlet 1.1.1 the Reference is broken, (it works great in 1.1.2, but that has other
    // problems)
    // so we need to a working solution
    String uri = repositoryRoot + (repositoryRoot.endsWith("/") ? "" : "/") + path;
    Reference reference = new Reference(uri);

    Request request = new Request(method, reference);

    ClientInfo ci = new ClientInfo();

    ci.setAgent("NexusRM/1.0.0");

    ci.setAcceptedMediaTypes(
        Collections.singletonList(new Preference<MediaType>(MediaType.APPLICATION_XML)));

    request.setClientInfo(ci);

    return request;
  }