@Test
  public void formal_accepted() throws Exception {

    request.withArg(RequestParameter.DOMAIN_MODEL, "formal");
    final RestfulResponse<ListRepresentation> restfulResponse = request.executeT();

    assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));
  }
  @Test
  public void simple_rejected() throws Exception {

    request.withArg(RequestParameter.DOMAIN_MODEL, "simple");
    final RestfulResponse<ListRepresentation> restfulResponse = request.executeT();

    assertThat(restfulResponse.getStatus(), is(HttpStatusCode.BAD_REQUEST));
    assertThat(
        restfulResponse.getHeader(RestfulResponse.Header.WARNING),
        is("x-ro-domain-model of 'simple' is not supported"));
  }
  @Test
  public void ok() throws Exception {
    // given
    final Response resp = resource.service("JdkValuedEntities");

    // when
    final RestfulResponse<DomainObjectRepresentation> jsonResp = RestfulResponse.ofT(resp);

    // then
    assertThat(jsonResp.getStatus(), is(HttpStatusCode.OK));
  }
  @Test
  public void applicationJson_profileIncorrect_returns406() throws Exception {

    // given
    final RestfulRequest request = client.createRequest(RestfulHttpMethod.GET, "user");
    request.withHeader(RestfulRequest.Header.ACCEPT, RepresentationType.VERSION.getMediaType());

    // when
    final RestfulResponse<UserRepresentation> restfulResponse = request.executeT();

    // then
    assertThat(restfulResponse.getStatus(), is(RestfulResponse.HttpStatusCode.NOT_ACCEPTABLE));
  }
  @Test
  public void incorrectMediaType_returns406() throws Exception {

    // given
    final ClientRequest clientRequest =
        client.getClientRequestFactory().createRelativeRequest("user");
    clientRequest.accept(MediaType.APPLICATION_ATOM_XML_TYPE);

    // when
    final ClientResponse<?> resp = clientRequest.get();
    final RestfulResponse<JsonRepresentation> restfulResponse = RestfulResponse.of(resp);

    // then
    assertThat(restfulResponse.getStatus(), is(RestfulResponse.HttpStatusCode.NOT_ACCEPTABLE));
  }
  @Ignore("TODO")
  @Test
  public void thenCollections() throws Exception {

    // when
    final Response jaxrsResponse = domainObjectResource.object("PRMV", "29");
    final RestfulResponse<DomainObjectRepresentation> restfulResponse =
        RestfulResponse.ofT(jaxrsResponse);
    assertThat(restfulResponse.getStatus(), is(HttpStatusCode.OK));

    // then

    domainObjectRepr = restfulResponse.getEntity();
    assertThat(domainObjectRepr, is(not(nullValue())));

    // then collections

  }
예제 #7
0
  @Ignore("to get working again")
  @Test
  public void actionPrompt() throws Exception {

    // when
    final Response actionPromptResp = domainObjectResource.actionPrompt("OID", "1", "list");
    final RestfulResponse<ObjectActionRepresentation> actionPromptJsonResp =
        RestfulResponse.ofT(actionPromptResp);
    assertThat(actionPromptJsonResp.getStatus().getFamily(), is(Family.SUCCESSFUL));

    // then
    final ObjectActionRepresentation actionPromptRepr = actionPromptJsonResp.getEntity();

    // _self.link
    final LinkRepresentation selfLink = actionPromptRepr.getLink("_self.link");
    assertThat(selfLink.getRel(), is("member"));
    assertThat(selfLink.getHref(), matches(".+objects/OID:1/actions/list"));
    assertThat(selfLink.getHttpMethod(), is(RestfulHttpMethod.GET));

    // _self.object
    final LinkRepresentation selfObject = actionPromptRepr.getLink("_self.object");
    assertThat(selfObject.getRel(), is("object"));
    assertThat(selfObject.getHref(), matches(".+objects/OID:1"));
    assertThat(selfObject.getHttpMethod(), is(RestfulHttpMethod.GET));

    // type
    final LinkRepresentation type = actionPromptRepr.getLink("type");
    assertThat(type.getRel(), is("type"));
    assertThat(type.getHref(), matches(".+vnd\\.list\\+json"));
    assertThat(type.getHttpMethod(), is(RestfulHttpMethod.GET));

    assertThat(actionPromptRepr.getString("memberType"), is("action"));
    assertThat(actionPromptRepr.getString("actionType"), is("USER"));
    assertThat(actionPromptRepr.getInt("numParameters"), is(0));
    assertThat(actionPromptRepr.getArray("parameters").size(), is(0));

    final LinkRepresentation invokeLink = actionPromptRepr.getLink("invoke");
    assertThat(invokeLink.getRel(), is("invoke"));
    assertThat(invokeLink.getHref(), matches(".+objects/OID:1/actions/list/invoke"));
    assertThat(invokeLink.getHttpMethod(), is(RestfulHttpMethod.POST));
    assertThat(invokeLink.getArguments(), is(not(nullValue())));
    assertThat(invokeLink.getArguments().isArray(), is(true));
    assertThat(invokeLink.getArguments().size(), is(0));
  }