From dc90d23da77a84fafe2e725067f13429558574d9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 9 Mar 2015 23:30:24 +0100 Subject: [PATCH] #314 - HalLinkDiscoverer now also works for URI rels. Relation names can be fully qualified URIs. HalLinkDiscoverer now quotes the relation name handed into the constructor so that the expression parsing works as expected. --- .../hateoas/hal/HalLinkDiscoverer.java | 2 +- .../hal/HalLinkDiscovererUnitTest.java | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/hal/HalLinkDiscoverer.java b/src/main/java/org/springframework/hateoas/hal/HalLinkDiscoverer.java index 288142f2..49c230d3 100644 --- a/src/main/java/org/springframework/hateoas/hal/HalLinkDiscoverer.java +++ b/src/main/java/org/springframework/hateoas/hal/HalLinkDiscoverer.java @@ -27,6 +27,6 @@ import org.springframework.hateoas.core.JsonPathLinkDiscoverer; public class HalLinkDiscoverer extends JsonPathLinkDiscoverer { public HalLinkDiscoverer() { - super("$._links..%s..href", MediaTypes.HAL_JSON); + super("$._links..['%s']..href", MediaTypes.HAL_JSON); } } diff --git a/src/test/java/org/springframework/hateoas/hal/HalLinkDiscovererUnitTest.java b/src/test/java/org/springframework/hateoas/hal/HalLinkDiscovererUnitTest.java index 09fea7b0..c42f945c 100644 --- a/src/test/java/org/springframework/hateoas/hal/HalLinkDiscovererUnitTest.java +++ b/src/test/java/org/springframework/hateoas/hal/HalLinkDiscovererUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,10 @@ */ package org.springframework.hateoas.hal; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; import org.springframework.hateoas.LinkDiscoverer; import org.springframework.hateoas.core.AbstractLinkDiscovererUnitTest; @@ -26,10 +30,17 @@ import org.springframework.hateoas.core.AbstractLinkDiscovererUnitTest; public class HalLinkDiscovererUnitTest extends AbstractLinkDiscovererUnitTest { static final LinkDiscoverer discoverer = new HalLinkDiscoverer(); - static final String SAMPLE = "{ _links : { " + // - "self : { href : 'selfHref' }, " + // - "relation : [ " + // - "{ href : 'firstHref' }, { href : 'secondHref' }]}}"; + static final String SAMPLE = "{ _links : { self : { href : 'selfHref' }, " + // + "relation : [ { href : 'firstHref' }, { href : 'secondHref' }], " + // + "'http://foo.com/bar' : { href : 'fullRelHref' }, " + "}}"; + + /** + * @see #314 + */ + @Test + public void discoversFullyQualifiedRel() { + assertThat(getDiscoverer().findLinkWithRel("http://foo.com/bar", SAMPLE), is(notNullValue())); + } @Override protected LinkDiscoverer getDiscoverer() {