blob: d73b7f78391171e3f33fa9579b4bab346239eee0 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content.cluster;
import com.yahoo.vespa.model.content.ContentSearch;
import com.yahoo.vespa.model.builder.xml.dom.ModelElement;
import org.junit.jupiter.api.Test;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Simon Thoresen Hult
*/
public class DomContentApplicationBuilderTest {
@Test
void requireThatDefaultsAreNull() throws Exception {
ContentSearch search = newContentSearch(
"<content/>");
assertNull(search.getVisibilityDelay());
assertNull(search.getQueryTimeout());
}
@Test
void requireThatEmptySearchIsSafe() throws Exception {
ContentSearch search = newContentSearch(
"<content>" +
" <search/>" +
"</content>");
assertNull(search.getVisibilityDelay());
assertNull(search.getQueryTimeout());
}
@Test
void requireThatContentSearchCanBeBuilt() throws Exception {
ContentSearch search = newContentSearch(
"<content>" +
" <search>" +
" <query-timeout>1.1</query-timeout>" +
" <visibility-delay>2.3</visibility-delay>" +
" </search>" +
"</content>");
assertEquals(1.1, search.getQueryTimeout(), 1E-6);
assertEquals(2.3, search.getVisibilityDelay(), 1E-6);
}
private static ContentSearch newContentSearch(String xml) throws Exception {
return DomContentSearchBuilder.build(
new ModelElement(DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
.getDocumentElement()));
}
}
|