further persistence work

This commit is contained in:
eugenp
2013-08-11 17:35:21 +03:00
parent f6e6b97717
commit cc7775d6d8
7 changed files with 177 additions and 20 deletions
@@ -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);
}
}
@@ -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() {
//
}
}