1 package com.atlassian.marketplace.client.api;
2
3 import java.net.URI;
4
5 import com.google.common.collect.ImmutableMap;
6
7 import org.junit.Test;
8
9 import static org.hamcrest.MatcherAssert.assertThat;
10 import static org.hamcrest.Matchers.equalTo;
11
12 public class UriTemplateTest
13 {
14 @Test
15 public void templateWithPlaceholdersIsValid()
16 {
17 String s = "/this/is/{good}";
18 assertThat(UriTemplate.create(s).getValue(), equalTo(s));
19 }
20
21 @Test
22 public void simplePlaceholdersCanBeSubstituted()
23 {
24 UriTemplate t = UriTemplate.create("/my/{a}/path/is/my/{b}/{a}/path/{c}");
25 assertThat(t.resolve(ImmutableMap.of("a", "favorite", "b", "very")),
26 equalTo(URI.create("/my/favorite/path/is/my/very/favorite/path/")));
27 }
28
29 @Test
30 public void queryParamsCanBeSubstituted()
31 {
32 UriTemplate t = UriTemplate.create("/my/{a}/path{?b,c,d}");
33 assertThat(t.resolve(ImmutableMap.of("a", "special", "b", "bee", "d", "do thing")),
34 equalTo(URI.create("/my/special/path?b=bee&d=do+thing")));
35 }
36 }