6666
6767public class PercolateDocumentParserTests extends ESTestCase {
6868
69- private Index index ;
7069 private MapperService mapperService ;
7170 private PercolateDocumentParser parser ;
7271 private QueryShardContext queryShardContext ;
72+ private PercolateShardRequest request ;
7373
7474 @ Before
7575 public void init () {
76- index = new Index ("_index" );
7776 IndexSettings indexSettings = new IndexSettings (new IndexMetaData .Builder ("_index" ).settings (
7877 Settings .builder ().put (IndexMetaData .SETTING_NUMBER_OF_SHARDS , 1 )
7978 .put (IndexMetaData .SETTING_NUMBER_OF_REPLICAS , 1 )
@@ -97,6 +96,10 @@ public void init() {
9796 parser = new PercolateDocumentParser (
9897 highlightPhase , new SortParseElement (), aggregationPhase , mappingUpdatedAction
9998 );
99+
100+ request = Mockito .mock (PercolateShardRequest .class );
101+ Mockito .when (request .shardId ()).thenReturn (new ShardId (new Index ("_index" ), 0 ));
102+ Mockito .when (request .documentType ()).thenReturn ("type" );
100103 }
101104
102105 public void testParseDoc () throws Exception {
@@ -105,9 +108,7 @@ public void testParseDoc() throws Exception {
105108 .field ("field1" , "value1" )
106109 .endObject ()
107110 .endObject ();
108- PercolateShardRequest request = new PercolateShardRequest (new ShardId (index , 0 ), null );
109- request .documentType ("type" );
110- request .source (source .bytes ());
111+ Mockito .when (request .source ()).thenReturn (source .bytes ());
111112
112113 PercolateContext context = new PercolateContext (request , new SearchShardTarget ("_node" , "_index" , 0 ), mapperService );
113114 ParsedDocument parsedDocument = parser .parse (request , context , mapperService , queryShardContext );
@@ -126,9 +127,7 @@ public void testParseDocAndOtherOptions() throws Exception {
126127 .field ("size" , 123 )
127128 .startObject ("sort" ).startObject ("_score" ).endObject ().endObject ()
128129 .endObject ();
129- PercolateShardRequest request = new PercolateShardRequest (new ShardId (index , 0 ), null );
130- request .documentType ("type" );
131- request .source (source .bytes ());
130+ Mockito .when (request .source ()).thenReturn (source .bytes ());
132131
133132 PercolateContext context = new PercolateContext (request , new SearchShardTarget ("_node" , "_index" , 0 ), mapperService );
134133 ParsedDocument parsedDocument = parser .parse (request , context , mapperService , queryShardContext );
@@ -151,10 +150,8 @@ public void testParseDocSource() throws Exception {
151150 XContentBuilder docSource = jsonBuilder ().startObject ()
152151 .field ("field1" , "value1" )
153152 .endObject ();
154- PercolateShardRequest request = new PercolateShardRequest (new ShardId (index , 0 ), null );
155- request .documentType ("type" );
156- request .source (source .bytes ());
157- request .docSource (docSource .bytes ());
153+ Mockito .when (request .source ()).thenReturn (source .bytes ());
154+ Mockito .when (request .docSource ()).thenReturn (docSource .bytes ());
158155
159156 PercolateContext context = new PercolateContext (request , new SearchShardTarget ("_node" , "_index" , 0 ), mapperService );
160157 ParsedDocument parsedDocument = parser .parse (request , context , mapperService , queryShardContext );
@@ -180,10 +177,8 @@ public void testParseDocSourceAndSource() throws Exception {
180177 XContentBuilder docSource = jsonBuilder ().startObject ()
181178 .field ("field1" , "value1" )
182179 .endObject ();
183- PercolateShardRequest request = new PercolateShardRequest (new ShardId (index , 0 ), null );
184- request .documentType ("type" );
185- request .source (source .bytes ());
186- request .docSource (docSource .bytes ());
180+ Mockito .when (request .source ()).thenReturn (source .bytes ());
181+ Mockito .when (request .docSource ()).thenReturn (docSource .bytes ());
187182
188183 PercolateContext context = new PercolateContext (request , new SearchShardTarget ("_node" , "_index" , 0 ), mapperService );
189184 try {
0 commit comments