@Override public Affordance withSelfRel() { if (!linkParams.get(REL.paramName) .contains(Link.REL_SELF)) { linkParams.add(REL.paramName, Link.REL_SELF); } return new Affordance(this.getHref(), linkParams, actionDescriptors); }
@Override public Affordance withSelfRel() { if (!linkParams.get(REL.paramName) .contains(Link.REL_SELF)) { linkParams.add(REL.paramName, Link.REL_SELF); } return new Affordance(this.getHref(), linkParams, actionDescriptors); }
@Override public Affordance withRel(String rel) { linkParams.set(REL.paramName, rel); return new Affordance(this.getHref(), linkParams, actionDescriptors); }
@Override public Affordance withRel(String rel) { linkParams.set(REL.paramName, rel); return new Affordance(this.getHref(), linkParams, actionDescriptors); }
@Test public void expandsSimpleStringVariablesPartially() { final Affordance affordance = new Affordance("/protected/res/documents/index.html?focus={contractId}&caller=BLUE&referrer=/protected/res/my_contracts/index.html&fragment=/contractDetails/{ref}", "thing"); Map<String, Object> args = new HashMap<String, Object>(); args.put("ref", 1234567890); assertEquals("/protected/res/documents/index.html?focus={contractId}&caller=BLUE&referrer=/protected/res/my_contracts/index.html&fragment=/contractDetails/1234567890", affordance.expandPartially(args).getHref()); }
@Test public void testExpandWithArgumentsMap() { final Affordance affordance = new Affordance("http://localhost/things{?id}", "thing"); Map<String, Object> arguments = new HashMap<String, Object>(); arguments.put("id", 101); assertEquals("http://localhost/things?id=101", affordance.expand(101) .getHref()); }
@Test public void testLinkToMethodWithInputBean() throws Exception { final Method getEventMethod = ReflectionUtils.findMethod(EventControllerSample.class, "queryEvent", EventControllerSample.EventQbe.class); final Affordance affordance = factory.linkTo(getEventMethod, new Object[0]) .rel("foo") .build(); assertEquals("http://example.com/events/query{?description,status}", affordance.getHref()); }
@Test public void testExpand() { final Affordance affordance = new Affordance("http://localhost/things{/id}", "thing"); assertEquals("http://localhost/things/100", affordance.expand(100) .getHref()); }
@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())); }
@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 testLinkToControllerClass() throws Exception { final Affordance affordance = factory.linkTo(EventControllerSample.class, new Object[0]) .rel("foo") .build(); assertEquals("http://example.com/events", affordance.getHref()); }
@Test public void testIsTemplated() { final Affordance affordance = new Affordance("http://localhost/things/{id}", "thing", "http://example.net/relation/other"); assertEquals("http://localhost/things/{id}", affordance.getHref()); Assert.assertTrue("must recognize template", affordance.isTemplated()); }
@Test public void testLinkToMethodInvocation() 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()); }
@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 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 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 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 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()); } }