@Test public void testConstructorWithoutRels() { final Affordance affordance = new Affordance("http://localhost/things/{id}"); assertEquals("http://localhost/things/{id}", affordance.getHref()); Assert.assertNull("rel must be null", affordance.getRel()); assertEquals(0, affordance.getRels() .size()); Assert.assertThat(affordance.getRels(), Matchers.is(Matchers.empty())); }
.hasVariables()) { if ("hydra:search".equals(affordance.getRel()) || Cardinality.SINGLE == affordance .getCardinality()) { jgen.writeStringField("hydra:object", selfRel.getHref()); } else if (collectionAffordance.getRel() != null) { jgen.writeStringField("hydra:property", collectionAffordance.getRel()); if (collectionHolder != null) { final String rel = affordance.getRel(); List<ActionDescriptor> actionDescriptors = affordance.getActionDescriptors();
@Test public void testConstructorWithSingleRel() { final Affordance affordance = new Affordance("http://localhost/things/{id}", "thing"); assertEquals("http://localhost/things/{id}", affordance.getHref()); assertEquals("thing", affordance.getRel()); Assert.assertThat(affordance.getRels(), Matchers.contains("thing")); }
@Test public void testConstructorWithRels() { final Affordance affordance = new Affordance("http://localhost/things/{id}", "start", "http://example.net/relation/other"); assertEquals("http://localhost/things/{id}", affordance.getHref()); assertEquals("start", affordance.getRel()); Assert.assertThat(affordance.getRels(), Matchers.contains("start", "http://example.net/relation/other")); }
@Test public void testLinkToMethodNoArgsBuild() throws Exception { final Method getEventMethod = ReflectionUtils.findMethod(EventControllerSample.class, "getEvent", String.class); final Affordance affordance = factory.linkTo(getEventMethod, new Object[0]) .rel("foo") .build(); assertEquals("http://example.com/events/{eventId}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToControllerClassNoArgsBuild() throws Exception { final Affordance affordance = factory.linkTo(EventControllerSample.class, new Object[0]) .rel("foo") .build(); assertEquals("http://example.com/events", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationBeanInput() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .queryEvent(null)) .rel("foo") .build(); assertEquals("http://example.com/events/query{?description,status}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationNoArgsBuild() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .getEvent((String) null)) .rel("foo") .build(); assertEquals("http://example.com/events/{eventId}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationBeanInputWithIncludes() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .queryEventWithIncludes(null)) .rel("foo") .build(); assertEquals("http://example.com/events/queryincludes{?status}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationMapInput() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .queryEventByMap(null)) .rel("foo") .build(); assertEquals("http://example.com/events/querymap{?description,status,donttouch}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationBeanInputWithExcludes() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .queryEventWithExcludes(null)) .rel("foo") .build(); assertEquals("http://example.com/events/queryexcludes{?description}", affordance.getHref()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationReverseRel() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .getEvent((String) null)) .reverseRel("schema:parent", "ex:children") .build(); assertEquals("http://example.com/events/{eventId}", affordance.getHref()); assertEquals("schema:parent", affordance.getRev()); assertEquals("ex:children", affordance.getRel()); } }
@Test public void testLinkToMethodInvocationNamedRequestParamWithAllValues() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .simpleQueryEvent("foo", 2L)) .rel("foo") .build(); // href must not strip variables with values assertEquals("http://example.com/events/simplequery?q=foo&offset=2", affordance.getHref()); // full uritemplate with all values assertEquals("http://example.com/events/simplequery?q=foo&offset=2", affordance.getUriTemplateComponents().toString()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationNamedRequestParam() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .simpleQueryEvent(null, null)) .rel("foo") .build(); // href strips optional variables assertEquals("http://example.com/events/simplequery{?q}", affordance.getHref()); // full uritemplate assertEquals("http://example.com/events/simplequery{?q,offset}", affordance.getUriTemplateComponents().toString()); assertEquals("foo", affordance.getRel()); }
@Test public void testLinkToMethodInvocationNamedRequestParamWithValue() throws Exception { final Affordance affordance = factory.linkTo(AffordanceBuilder.methodOn(EventControllerSample.class) .simpleQueryEvent("foo", null)) .rel("foo") .build(); // href strips optional variables assertEquals("http://example.com/events/simplequery?q=foo", affordance.getHref()); // full uritemplate assertEquals("http://example.com/events/simplequery?q=foo{&offset}", affordance.getUriTemplateComponents().toString()); assertEquals("foo", affordance.getRel()); }