blob: 465bdef87a3698b5de6297ef155fe066951f2dc3 (
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
59
60
61
62
63
64
65
66
67
68
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container;
import com.yahoo.application.Networking;
import com.yahoo.application.container.searchers.AddHitSearcher;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author gjoranv
* @author ollivir
*/
public class ContainerSchemaTest {
@Test
void processing_and_rendering_works() throws Exception {
final String searcherId = AddHitSearcher.class.getName();
try (JDisc container = containerWithSearch(searcherId)) {
byte[] rendered = container.search().processAndRender(ComponentSpecification.fromString("mychain"),
ComponentSpecification.fromString("XmlRenderer"), new Query(""));
String renderedAsString = new String(rendered, StandardCharsets.UTF_8);
assertTrue(renderedAsString.contains(searcherId));
}
}
@Test
void searching_works() {
final String searcherId = AddHitSearcher.class.getName();
try (JDisc container = containerWithSearch(searcherId)) {
Search searching = container.search();
Result result = searching.process(ComponentSpecification.fromString("mychain"), new Query(""));
String hitTitle = result.hits().get(0).getField("title").toString();
assertEquals(searcherId, hitTitle);
}
}
public JDisc containerWithSearch(String searcherId) {
return JDisc.fromServicesXml("<container version=\"1.0\">" + //
" <search>" + //
" <chain id=\"mychain\">" + //
" <searcher id=\"" + searcherId + "\"/>" + //
" </chain>" + //
" </search>" + //
" <accesslog type=\"disabled\" />" + //
"</container>", Networking.disable);
}
@Test
void retrieving_search_from_container_without_search_is_illegal() {
assertThrows(UnsupportedOperationException.class, () -> {
try (JDisc container = JDisc.fromServicesXml("<container version=\"1.0\" />", Networking.disable)) {
container.search(); // throws
}
});
}
}
|