DATAMONGO-853 - Update does not allow null keys anymore.
Added check for blank / null keys when adding key to Update. Original pull request: #129.
This commit is contained in:
committed by
Oliver Gierke
parent
d88e4c0e3e
commit
5be66a3fee
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
@@ -263,12 +264,14 @@ public class Update {
|
||||
|
||||
protected void addFieldOperation(String operator, String key, Object value) {
|
||||
|
||||
Assert.hasText(key, "Key/Path for update must not be null or blank.");
|
||||
modifierOps.put(operator, new BasicDBObject(key, value));
|
||||
this.keysToUpdate.add(key);
|
||||
}
|
||||
|
||||
protected void addMultiFieldOperation(String operator, String key, Object value) {
|
||||
|
||||
Assert.hasText(key, "Key/Path for update must not be null or blank.");
|
||||
Object existingValue = this.modifierOps.get(operator);
|
||||
DBObject keyValueMap;
|
||||
|
||||
|
||||
@@ -260,4 +260,28 @@ public class UpdateTests {
|
||||
|
||||
assertThat(clone.modifies("oof"), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-853
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAddingMultiFieldOperationThrowsExceptionWhenCalledWithNullKey() {
|
||||
new Update().addMultiFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-853
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAddingSingleFieldOperationThrowsExceptionWhenCalledWithNullKey() {
|
||||
new Update().addFieldOperation("$op", null, "exprected to throw IllegalArgumentException.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-853
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCreatingUpdateWithNullKeyThrowsException() {
|
||||
Update.update(null, "value");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user