Ejemplo n.º 1
0
  @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 ok() throws Exception {
    // given
    final Response resp = resource.version();

    // when
    final RestfulResponse<VersionRepresentation> restfulResponse = RestfulResponse.ofT(resp);

    // then
    final CacheControl cacheControl = restfulResponse.getHeader(Header.CACHE_CONTROL);
    assertThat(cacheControl, hasMaxAge(24 * 60 * 60));
    assertThat(cacheControl.getMaxAge(), is(24 * 60 * 60));
  }
  @Test
  public void ok() throws Exception {

    // given
    final Response resp = resource.user();

    // when
    final RestfulResponse<UserRepresentation> restfulResponse = RestfulResponse.ofT(resp);

    // then
    final MediaType contentType = restfulResponse.getHeader(Header.CONTENT_TYPE);
    assertThat(contentType, hasMediaType("application"));
    assertThat(contentType, hasSubType("json"));
    assertThat(contentType, hasParameter("profile", "urn:org.restfulobjects:repr-types/user"));
    assertThat(contentType, is(RepresentationType.USER.getMediaType()));
  }
  @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

  }
Ejemplo n.º 5
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));
  }