further persistence work
This commit is contained in:
+23
-3
@@ -1,8 +1,14 @@
|
||||
package org.baeldung.ex.dataIntegrityviolationexception;
|
||||
|
||||
import org.baeldung.ex.dataIntegrityviolationexception.spring.Cause1DataContextWithJavaConfig;
|
||||
import org.baeldung.persistence.model.Child;
|
||||
import org.baeldung.persistence.model.Parent;
|
||||
import org.baeldung.persistence.service.IChildService;
|
||||
import org.baeldung.persistence.service.IParentService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
@@ -11,9 +17,23 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
@ContextConfiguration(classes = { Cause1DataContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class Cause1DataIntegrityViolationExceptionIntegrationTest {
|
||||
|
||||
@Test
|
||||
public final void givenContextIsInitialized_thenNoException() {
|
||||
//
|
||||
@Autowired
|
||||
private IParentService service;
|
||||
|
||||
@Autowired
|
||||
private IChildService childService;
|
||||
|
||||
// tests
|
||||
|
||||
@Test(expected = DataIntegrityViolationException.class)
|
||||
public void whenChildIsDeletedWhileParentStillHasForeignKeyToIt_thenDataException() {
|
||||
final Child childEntity = new Child();
|
||||
childService.create(childEntity);
|
||||
|
||||
final Parent parentEntity = new Parent(childEntity);
|
||||
service.create(parentEntity);
|
||||
|
||||
childService.delete(childEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-17
@@ -17,23 +17,9 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
@ContextConfiguration(classes = { Cause1ContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class Cause1NoSuchBeanDefinitionExceptionIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private IParentService service;
|
||||
|
||||
@Autowired
|
||||
private IChildService childService;
|
||||
|
||||
// tests
|
||||
|
||||
@Test(expected = DataIntegrityViolationException.class)
|
||||
public void whenChildIsDeletedWhileParentStillHasForeignKeyToIt_thenDataException() {
|
||||
final Child childEntity = new Child();
|
||||
childService.create(childEntity);
|
||||
|
||||
final Parent parentEntity = new Parent(childEntity);
|
||||
service.create(parentEntity);
|
||||
|
||||
childService.delete(childEntity);
|
||||
@Test
|
||||
public final void givenContextIsInitialized_thenNoException() {
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user