DATAMONGO-540 - Added test case to show findOne(…) works after upsert.
This commit is contained in:
committed by
Oliver Gierke
parent
b0bf8cb718
commit
0afbf6fe19
@@ -88,6 +88,7 @@ import com.mongodb.WriteResult;
|
||||
* @author Thomas Risberg
|
||||
* @author Amol Nayak
|
||||
* @author Patryk Wasik
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:infrastructure.xml")
|
||||
@@ -1661,6 +1662,27 @@ public class MongoTemplateTests {
|
||||
assertThat(result.get(0).date, is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-540
|
||||
*/
|
||||
@Test
|
||||
public void findOneAfterUpsertForNonExistingObjectReturnsTheInsertedObject() {
|
||||
|
||||
String idValue = "4711";
|
||||
Query query = new Query(Criteria.where("id").is(idValue));
|
||||
|
||||
String fieldValue = "bubu";
|
||||
Update update = Update.update("field", fieldValue);
|
||||
|
||||
String collectionName = "datamongo540";
|
||||
template.upsert(query, update, collectionName);
|
||||
Sample result = template.findOne(query, Sample.class, collectionName);
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.field, is(fieldValue));
|
||||
assertThat(result.id, is(idValue));
|
||||
}
|
||||
|
||||
static class MyId {
|
||||
|
||||
String first;
|
||||
|
||||
Reference in New Issue
Block a user