/** * Values to be substituted in for each of the parameters in the query. * * @param parameterValues values * @return The current instance of the builder * @see MongoItemReader#setParameterValues(List) */ public MongoItemReaderBuilder<T> parameterValues(Object... parameterValues) { return parameterValues(Arrays.asList(parameterValues)); }
@Test public void testCollection() throws Exception { MongoItemReader<String> reader = getBasicBuilder() .parameterValues(Collections.singletonList("foo")) .jsonQuery("{ name : ?0 }") .collection("collection") .build(); ArgumentCaptor<String> collectionContainer = ArgumentCaptor.forClass(String.class); when(this.template.find(this.queryContainer.capture(), eq(String.class), collectionContainer.capture())) .thenReturn(new ArrayList<>()); assertNull("reader should not return result", reader.read()); Query query = this.queryContainer.getValue(); assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson()); assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson()); assertEquals("collection", collectionContainer.getValue()); }
@Test public void testVarargs() throws Exception { MongoItemReader<String> reader = getBasicBuilder() .parameterValues("foo") .jsonQuery("{ name : ?0 }") .collection("collection") .build(); ArgumentCaptor<String> collectionContainer = ArgumentCaptor.forClass(String.class); when(this.template.find(this.queryContainer.capture(), eq(String.class), collectionContainer.capture())) .thenReturn(new ArrayList<>()); assertNull("reader should not return result", reader.read()); Query query = this.queryContainer.getValue(); assertEquals("{ \"name\" : \"foo\" }", query.getQueryObject().toJson()); assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson()); assertEquals("collection", collectionContainer.getValue()); }