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
71
72
73
74
75
76
77
78
79
80
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.search.searchchain;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.config.model.test.MockRoot;
import com.yahoo.vespa.model.builder.xml.dom.chains.search.DomSearchChainsBuilder;
import com.yahoo.vespa.model.container.xml.ContainerModelBuilderTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author gjoranv
*/
public class SchemaChainsTest2 {
private MockRoot root;
@BeforeEach
public void prepareTest() {
root = new MockRoot("root");
}
@Test
void fail_upon_unresolved_inheritance() {
final Element searchElem = DomBuilderTest.parse(
"<search>",
" <chain id='default' inherits='nonexistent' />",
"</search>");
try {
MockRoot root = new MockRoot();
SearchChains chains = new DomSearchChainsBuilder().build(root.getDeployState(), root, searchElem);
chains.validate();
fail("Expected exception when inheriting a nonexistent search chain.");
} catch (Exception e) {
assertEquals("Missing chain 'nonexistent'.",
e.getMessage());
}
}
@Test
void fail_upon_two_user_declared_chains_with_same_name() {
final Element clusterElem = DomBuilderTest.parse(
"<container id='cluster1' version='1.0'>",
ContainerModelBuilderTest.nodesXml,
" <search>",
" <chain id='same' />",
" <chain id='same' />",
" </search>",
"</container>");
try {
ContainerModelBuilderTest.createModel(root, clusterElem);
fail("Expected exception when declaring chains with duplicate id.");
} catch (Exception e) {
assertEquals("Both search chain 'same' and search chain 'same' are configured with the id 'same'. All components must have a unique id.",
e.getMessage());
}
}
@Test
void fail_upon_user_declared_chain_with_same_id_as_builtin_chain() {
final Element clusterElem = DomBuilderTest.parse(
"<container id='cluster1' version='1.0'>",
ContainerModelBuilderTest.nodesXml,
" <search>",
" <chain id='vespa' />",
" </search>",
"</container>");
try {
ContainerModelBuilderTest.createModel(root, clusterElem);
fail("Expected exception when taking the id from a builtin chain.");
} catch (Exception e) {
assertEquals("Both search chain 'vespa' and search chain 'vespa' are configured with the id 'vespa'. All components must have a unique id.",
e.getMessage());
}
}
}
|