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
64
65
66
67
68
69
70
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;
import com.yahoo.document.idstring.IdIdString;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Created with IntelliJ IDEA.
* User: magnarn
* Date: 10/16/12
* Time: 9:10 AM
*/
public class IdIdStringTest {
@Test
public void requireThatIdIdStringGeneratesProperString() throws Exception {
DocumentId docId = new DocumentId(new IdIdString("namespace", "type", "g=group", "foobar"));
assertEquals("id:namespace:type:g=group:foobar", docId.toString());
}
@Test
public void requireThatEmptyKeyValuesAreOk() throws Exception {
DocumentId docId = new DocumentId(new IdIdString("namespace", "type", "", "foobar"));
assertEquals("id:namespace:type::foobar", docId.toString());
}
@Test
public void requireThatIdIdStringCanBehaveLikeGroupDoc() throws Exception {
DocumentId docId1 = new DocumentId(new IdIdString("namespace", "type", "g=foo", "foo"));
DocumentId docId2 = new DocumentId(new IdIdString("namespace", "type", "g=foo", "bar"));
DocumentId docId3 = new DocumentId(new IdIdString("namespace", "type", "g=bar", "baz"));
assertEquals(docId1.getScheme().getLocation(), docId2.getScheme().getLocation());
assert(docId1.getScheme().getLocation() != docId3.getScheme().getLocation());
}
@Test
public void requireThatIdIdStringCanBehaveLikeUserDoc() throws Exception {
DocumentId docId1 = new DocumentId(new IdIdString("namespace", "type", "n=10", "foo"));
DocumentId docId2 = new DocumentId(new IdIdString("namespace", "type", "n=10", "bar"));
DocumentId docId3 = new DocumentId(new IdIdString("namespace", "type", "n=20", "baz"));
assertEquals(docId1.getScheme().getLocation(), docId2.getScheme().getLocation());
assert(docId1.getScheme().getLocation() != docId3.getScheme().getLocation());
}
@Test
public void requireThatIllegalKeyValuesThrow() throws Exception {
try {
new IdIdString("namespace", "type", "illegal=key", "foo");
fail();
} catch (IllegalArgumentException e) {
}
}
@Test
public void requireThatKeysWithoutValuesThrow() throws Exception {
try {
new IdIdString("namespace", "type", "illegal-pair", "foo");
fail();
} catch (IllegalArgumentException e) {
}
}
@Test
public void requireThatIdIdStringCanReplaceType() throws Exception {
String type = IdIdString.replaceType("id:namespace:type::foo", "newType");
assertEquals("id:namespace:newType::foo", type);
}
}
|