1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.restapi.application;
import com.yahoo.restapi.Path;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
public class PathTest {
@Test
public void testPath() {
assertFalse(new Path("").matches("/a/{foo}/bar/{b}"));
assertFalse(new Path("///").matches("/a/{foo}/bar/{b}"));
assertFalse(new Path("///foo").matches("/a/{foo}/bar/{b}"));
assertFalse(new Path("///bar/").matches("/a/{foo}/bar/{b}"));
Path path = new Path("/a/1/bar/fuz");
assertTrue(path.matches("/a/{foo}/bar/{b}"));
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
}
@Test
public void testPathWithRest() {
{
Path path = new Path("/a/1/bar/fuz/");
assertTrue(path.matches("/a/{foo}/bar/{b}/{*}"));
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
assertEquals("", path.getRest());
}
{
Path path = new Path("/a/1/bar/fuz/kanoo");
assertTrue(path.matches("/a/{foo}/bar/{b}/{*}"));
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
assertEquals("kanoo", path.getRest());
}
{
Path path = new Path("/a/1/bar/fuz/kanoo/trips");
assertTrue(path.matches("/a/{foo}/bar/{b}/{*}"));
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
assertEquals("kanoo/trips", path.getRest());
}
{
Path path = new Path("/a/1/bar/fuz/kanoo/trips/");
assertTrue(path.matches("/a/{foo}/bar/{b}/{*}"));
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
assertEquals("kanoo/trips/", path.getRest());
}
}
}
|