@Override public String toString() { return "Step [key=" + key + ", link=" + (link != null ? link.getHref() : "(null)") + ", error=" + error + "]"; }
@Test public void equalDoesNotDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("something"); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("else"); assertThat(link, is(equalTo(link2))); }
@Override public String toString() { return "Link [rel=" + getRel() + ", href=" + getHref() + ", method=" + getHttpMethod() + ", type=" + getType() + "]"; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getHref() == null) ? 0 : getHref().hashCode()); result = prime * result + ((getHttpMethod() == null) ? 0 : getHttpMethod().hashCode()); return result; }
public boolean isLink(final JsonNode node) { if (representsNull(node) || isArray(node) || node.isValueNode()) { return false; } final LinkRepresentation link = new LinkRepresentation(node); if (link.getHref() == null) { return false; } return true; }
@Test public void equalDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final LinkRepresentation link3 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.PUT); final LinkRepresentation link4 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:456").withMethod(RestfulHttpMethod.GET); assertThat(link, is(equalTo(link2))); assertThat(link, is(not(equalTo(link3)))); assertThat(link, is(not(equalTo(link4)))); }
public LinkRepresentation withRel(Rel rel) { return withRel(rel.getName()); }
public LinkRepresentation() { this(new ObjectNode(JsonNodeFactory.instance)); withMethod(RestfulHttpMethod.GET); }
@Test public void equalDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final LinkRepresentation link3 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.PUT); final LinkRepresentation link4 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:456").withMethod(RestfulHttpMethod.GET); assertThat(link, is(equalTo(link2))); assertThat(link, is(not(equalTo(link3)))); assertThat(link, is(not(equalTo(link4)))); }
private LinkRepresentation getLink(final String path, final JsonNode node) { if (representsNull(node)) { return null; } if (isArray(node)) { throw new IllegalArgumentException(formatExMsg(path, "is an array that does not represent a link")); } if (node.isValueNode()) { throw new IllegalArgumentException(formatExMsg(path, "is a value that does not represent a link")); } final LinkRepresentation link = new LinkRepresentation(node); if (link.getHref() == null) { throw new IllegalArgumentException(formatExMsg(path, "is a map that does not fully represent a link")); } return link; }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final LinkRepresentation other = (LinkRepresentation) obj; if (getHref() == null) { if (other.getHref() != null) { return false; } } else if (!getHref().equals(other.getHref())) { return false; } if (getHttpMethod() != other.getHttpMethod()) { return false; } return true; }
@Test public void forLink_whenSimpleKey() throws IOException { link.withRel("someRel"); assertThat(jsonRepresentation.isLink("aLink"), is(true)); assertThat(jsonRepresentation.getLink("aLink"), is(link)); }
@Test public void equalDoesNotDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("something"); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("else"); assertThat(link, is(equalTo(link2))); }
@Before public void setUp() throws Exception { link = new LinkRepresentation().withHref("http://foo/bar").withMethod(RestfulHttpMethod.GET); jsonRepresentation = new JsonRepresentation(readJson("map.json")); }
private static String linkFromFormalArgs(final String argumentsQueryString, final String paramName) { final JsonRepresentation arguments = DomainResourceHelper.readQueryStringAsMap(argumentsQueryString); if (!arguments.isLink(paramName)) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Args should contain a link '%s'", paramName); } return arguments.getLink(paramName).getHref(); }
public <T extends JsonRepresentation> RestfulResponse<T> follow(final ClientExecutor executor, final JsonRepresentation requestArgs) throws Exception { final ClientRequestConfigurer clientRequestConfigurer = ClientRequestConfigurer.create(executor, getHref()); clientRequestConfigurer.accept(MediaType.APPLICATION_JSON_TYPE); clientRequestConfigurer.setHttpMethod(getHttpMethod()); clientRequestConfigurer.configureArgs(requestArgs); final RestfulRequest restfulRequest = new RestfulRequest(clientRequestConfigurer); return restfulRequest.executeT(); }
@Test public void forLink_whenMultipartKey() throws JsonParseException, JsonMappingException, IOException { link.withRel("someSubRel"); assertThat(jsonRepresentation.isLink("aSubMap.aLink"), is(true)); assertThat(jsonRepresentation.getLink("aSubMap.aLink"), is(link)); }
@Test public void test() throws UnsupportedEncodingException { final LinkRepresentation l = new LinkRepresentation().withRel("object").withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final String expectedValue = "%7B%22method%22%3A%22GET%22%2C%22rel%22%3A%22object%22%2C%22href%22%3A%22http%3A%2F%2Flocalhost%3A8080%2Fobjects%2FABC%3A123%22%7D"; @SuppressWarnings("unused") final String decoded = URLDecoder.decode(expectedValue, Charsets.UTF_8.name()); assertThat(l.asUrlEncoded(), is(expectedValue)); } }
@Before public void setUp() throws Exception { link = new LinkRepresentation().withHref("http://foo/bar").withMethod(RestfulHttpMethod.GET); jsonRepresentation = new JsonRepresentation(readJson("map.json")); }
private static String linkFromFormalArgs(final String argumentsAsQueryString, final String paramName) { final JsonRepresentation arguments = Util.readQueryStringAsMap(argumentsAsQueryString); if (!arguments.isLink(paramName)) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Args should contain a link '%s'", paramName); } return arguments.getLink(paramName).getHref(); }