blob: 9d7e8ea26ab4c776d7833da9dc9257d40b61e07c (
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
69
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.application.container
import org.junit.Test
import searchers.AddHitSearcher
import com.yahoo.component.ComponentSpecification
import com.yahoo.search.Query
import org.junit.Assert._
import org.hamcrest.CoreMatchers._
import org.hamcrest.Matchers.containsString;
import JDiscTest.{fromServicesXml, using}
/**
*
* @author gjoranv
* @since 5.1.15
*/
class JDiscContainerSearchTest {
@Test
def processing_and_rendering_works() {
val searcherId = classOf[AddHitSearcher].getName
using(containerWithSearch(searcherId))
{ container =>
val rendered = container.search.processAndRender(ComponentSpecification.fromString("mychain"),
ComponentSpecification.fromString("DefaultRenderer"), new Query(""))
val renderedAsString = new String(rendered, "utf-8")
assertThat(renderedAsString, containsString(searcherId))
}
}
@Test
def searching_works() {
val searcherId = classOf[AddHitSearcher].getName
using(containerWithSearch(searcherId))
{ container =>
val searching = container.search
val result = searching.process(ComponentSpecification.fromString("mychain"), new Query(""))
val hitTitle = result.hits().get(0).getField("title").asInstanceOf[String]
assertThat(hitTitle, is(searcherId))
}
}
def containerWithSearch(searcherId: String) = {
fromServicesXml(
<container version="1.0">
<search>
<chain id="mychain">
<searcher id={searcherId}/>
</chain>
</search>
</container>)
}
@Test(expected = classOf[UnsupportedOperationException])
def retrieving_search_from_container_without_search_is_illegal() {
using(JDiscTest.fromServicesXml(
<container version="1.0" />
))
{ container =>
container.search // throws
}
}
}
|