DATAKV-89 - KeyValueTemplate now throws DuplicateKeyException.

We now throw DuplicateKeyException instead of InvalidDataAccessApiUsageException in case an object with given id already exists.

Original pull request: spring-projects/spring-data-commons#106.
This commit is contained in:
Christoph Strobl
2014-11-27 14:29:50 +01:00
committed by Oliver Gierke
parent 42a13a7403
commit 5f62882a3e
3 changed files with 14 additions and 4 deletions

View File

@@ -33,7 +33,7 @@ import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.keyvalue.annotation.KeySpace;
@@ -94,7 +94,7 @@ public class KeyValueTemplateTests {
/**
* @see DATACMNS-525
*/
@Test(expected = InvalidDataAccessApiUsageException.class)
@Test(expected = DuplicateKeyException.class)
public void insertShouldThrowExecptionWhenObjectOfSameTypeAlreadyExists() {
operations.insert("1", FOO_ONE);

View File

@@ -30,11 +30,14 @@ import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Persistent;
@@ -49,6 +52,8 @@ import org.springframework.util.ObjectUtils;
@RunWith(MockitoJUnitRunner.class)
public class KeyValueTemplateUnitTests {
public @Rule ExpectedException exception = ExpectedException.none();
private static final Foo FOO_ONE = new Foo("one");
private static final Foo FOO_TWO = new Foo("two");
private static final ClassWithTypeAlias ALIASED = new ClassWithTypeAlias("super");
@@ -105,9 +110,12 @@ public class KeyValueTemplateUnitTests {
/**
* @see DATACMNS-525
*/
@Test(expected = InvalidDataAccessApiUsageException.class)
@Test
public void insertShouldThrowExceptionWhenObectWithIdAlreadyExists() {
exception.expect(DuplicateKeyException.class);
exception.expectMessage("id 1");
when(adapterMock.contains(anyString(), anyString())).thenReturn(true);
template.insert("1", FOO_ONE);