Skip to content

Instantly share code, notes, and snippets.

@pgpx
Forked from anonymous/SpringHateoasLinkTest.java
Last active December 10, 2015 12:48
Show Gist options
  • Save pgpx/4436408 to your computer and use it in GitHub Desktop.
Save pgpx/4436408 to your computer and use it in GitHub Desktop.
import static org.junit.Assert.assertEquals;
import static org.springframework.hateoas.mvc.BasicLinkBuilder.linkToCurrentMapping;
import org.junit.Before;
import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
public class SpringHateoasLinkTest {
@Before
public void setup() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}
@Test
public void specialCharactersInPathShouldNotBeDoubleEncoded() {
Link l = linkToCurrentMapping().slash("first").slash("sec%ond").slash("thi%rd").slash("fourth").withSelfRel();
assertEquals("http://localhost/first/sec%25ond/thi%25rd/fourth", l.getHref());
}
@Test
public void slashInPathPathShouldBeEncoded() {
Link l = linkToCurrentMapping().slash("first").slash("sec/ond").slash("third").withSelfRel();
assertEquals("http://localhost/first/sec%2Fond/third/fourth", l.getHref());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment