Exemplo n.º 1
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void expansionShouldFailWithIllegalArgumentExceptionForUnknownVarType() {
   // given
   final URI varType = create("http://example.org/vars/bar");
   final TemplatedLink templatedLink =
       templatedLink(
           create("http://example.org/rel/foo"),
           "http://example.org/foo/{bar}",
           asList(hrefVar("bar", varType)),
           null);
   // when
   templatedLink.expandToUri(create("http://example.org/vars/foo"), "42");
   // then an exception is thrown.
 }
Exemplo n.º 2
0
 @Test
 public void shouldExpandUriForExistingVarType() {
   // given
   final URI varType = create("http://example.org/vars/bar");
   final TemplatedLink templatedLink =
       templatedLink(
           create("http://example.org/rel/foo"),
           "http://example.org/foo/{bar}",
           asList(hrefVar("bar", varType)),
           null);
   // when
   final URI uri = templatedLink.expandToUri(varType, "42");
   // then
   assertEquals(uri, create("http://example.org/foo/42"));
 }
Exemplo n.º 3
0
 @Test
 public void expansionShouldTreatMissingVarTypeAsEmptyValue() {
   // given
   final URI fooVarType = create("http://example.org/vars/foo");
   final URI barVarType = create("http://example.org/vars/bar");
   final TemplatedLink templatedLink =
       templatedLink(
           create("http://example.org/rel/foo"),
           "http://example.org/{foo}/{bar}",
           asList(hrefVar("foo", fooVarType), hrefVar("bar", barVarType)),
           null);
   // when
   final URI uri = templatedLink.expandToUri(create("http://example.org/vars/foo"), "42");
   // then
   assertEquals(uri, create("http://example.org/42/"));
 }
Exemplo n.º 4
0
 @Test
 public void shouldExpandUriWithRequestParams() {
   // given
   final URI fooVarType = create("http://example.org/vars/foo");
   final URI barVarType = create("http://example.org/vars/bar");
   final TemplatedLink templatedLink =
       templatedLink(
           create("http://example.org/rel/foo"),
           "http://example.org{?foo,bar}",
           asList(hrefVar("foo", fooVarType), hrefVar("bar", barVarType)),
           null);
   // when
   final URI uri = templatedLink.expandToUri(fooVarType, "42", barVarType, 4711);
   // then
   assertEquals(uri, create("http://example.org?foo=42&bar=4711"));
 }