@Test public void testHint() throws Exception { MongoItemReader<String> reader = getBasicBuilder() .hint("{ $natural : 1}") .build(); when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); assertNull("reader should not return result", reader.read()); Query query = this.queryContainer.getValue(); assertEquals("{ $natural : 1}", query.getHint()); }
@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()); }
@Test public void testBasic() throws Exception { MongoItemReader<String> reader = getBasicBuilder().build(); when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); assertNull("reader should not return result", reader.read()); Query query = this.queryContainer.getValue(); assertEquals(50, query.getLimit()); assertEquals(0, query.getSkip()); assertEquals("{ }", query.getQueryObject().toJson()); assertEquals("{ \"name\" : -1 }", query.getSortObject().toJson()); }
@Test public void testFields() throws Exception { MongoItemReader<String> reader = getBasicBuilder() .fields("{name : 1, age : 1, _id: 0}") .build(); when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); assertNull("reader should not return result", reader.read()); Query query = this.queryContainer.getValue(); assertEquals(1, query.getFieldsObject().get("name")); assertEquals(1, query.getFieldsObject().get("age")); assertEquals(0, query.getFieldsObject().get("_id")); }