Browse Source

DATAMONGO-907 - Assert compatibility with mongodb 2.6.

Fix test to only check on parts of the expected error message common in both 2.4 and 2.6.

Original Pull Request: #166.
1.4.x
Christoph Strobl 12 years ago committed by Oliver Gierke
parent
commit
cf3818e04c
  1. 12
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java

12
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java

@ -34,7 +34,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import org.hamcrest.CoreMatchers;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -299,6 +298,9 @@ public class MongoTemplateTests {
@Test @Test
public void rejectsDuplicateIdInInsertAll() { public void rejectsDuplicateIdInInsertAll() {
thrown.expect(DataIntegrityViolationException.class);
thrown.expectMessage("E11000 duplicate key error index: database.person.$_id_");
MongoTemplate template = new MongoTemplate(factory); MongoTemplate template = new MongoTemplate(factory);
template.setWriteResultChecking(WriteResultChecking.EXCEPTION); template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
@ -310,15 +312,7 @@ public class MongoTemplateTests {
records.add(person); records.add(person);
records.add(person); records.add(person);
try {
template.insertAll(records); template.insertAll(records);
fail("Expected DataIntegrityViolationException!");
} catch (DataIntegrityViolationException e) {
assertThat(
e.getMessage(),
CoreMatchers
.startsWith("Insert list failed: E11000 duplicate key error index: database.person.$_id_ dup key: { : ObjectId"));
}
} }
@Test @Test

Loading…
Cancel
Save