further persistence tests
This commit is contained in:
parent
cc7775d6d8
commit
b85141738d
|
@ -87,6 +87,12 @@
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${guava.version}</version>
|
<version>${guava.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.baeldung.ex.dataIntegrityviolationexception.spring;
|
package org.baeldung.ex.dataIntegrityviolationexception.spring;
|
||||||
|
|
||||||
|
import org.baeldung.spring.config.PersistenceConfig;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("org.baeldung.ex.dataIntegrityviolationexception.cause2")
|
@ComponentScan("org.baeldung.ex.dataIntegrityviolationexception.cause2")
|
||||||
|
@Import(PersistenceConfig.class)
|
||||||
public class Cause2DataContextWithJavaConfig {
|
public class Cause2DataContextWithJavaConfig {
|
||||||
|
|
||||||
public Cause2DataContextWithJavaConfig() {
|
public Cause2DataContextWithJavaConfig() {
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.baeldung.ex.dataIntegrityviolationexception.spring;
|
package org.baeldung.ex.dataIntegrityviolationexception.spring;
|
||||||
|
|
||||||
|
import org.baeldung.spring.config.PersistenceConfig;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("org.baeldung.ex.dataIntegrityviolationexception.cause3")
|
@ComponentScan("org.baeldung.ex.dataIntegrityviolationexception.cause3")
|
||||||
|
@Import(PersistenceConfig.class)
|
||||||
public class Cause3DataContextWithJavaConfig {
|
public class Cause3DataContextWithJavaConfig {
|
||||||
|
|
||||||
public Cause3DataContextWithJavaConfig() {
|
public Cause3DataContextWithJavaConfig() {
|
||||||
|
|
|
@ -36,4 +36,16 @@ public class Cause1DataIntegrityViolationExceptionIntegrationTest {
|
||||||
childService.delete(childEntity);
|
childService.delete(childEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenChildIsDeletedAfterTheParent_thenNoExceptions() {
|
||||||
|
final Child childEntity = new Child();
|
||||||
|
childService.create(childEntity);
|
||||||
|
|
||||||
|
final Parent parentEntity = new Parent(childEntity);
|
||||||
|
service.create(parentEntity);
|
||||||
|
|
||||||
|
service.delete(parentEntity);
|
||||||
|
childService.delete(childEntity);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package org.baeldung.ex.dataIntegrityviolationexception;
|
package org.baeldung.ex.dataIntegrityviolationexception;
|
||||||
|
|
||||||
import org.baeldung.ex.dataIntegrityviolationexception.spring.Cause2DataContextWithJavaConfig;
|
import org.baeldung.ex.dataIntegrityviolationexception.spring.Cause2DataContextWithJavaConfig;
|
||||||
|
import org.baeldung.persistence.model.Foo;
|
||||||
|
import org.baeldung.persistence.service.IFooService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
@ -11,9 +15,13 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@ContextConfiguration(classes = { Cause2DataContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = { Cause2DataContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
public class Cause2DataIntegrityViolationExceptionIntegrationTest {
|
public class Cause2DataIntegrityViolationExceptionIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Autowired
|
||||||
public final void givenContextIsInitialized_thenNoException() {
|
private IFooService fooService;
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// tests
|
||||||
|
|
||||||
|
@Test(expected = DataIntegrityViolationException.class)
|
||||||
|
public void whenInvalidEntityIsCreated_thenDataException() {
|
||||||
|
fooService.create(new Foo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package org.baeldung.ex.dataIntegrityviolationexception;
|
package org.baeldung.ex.dataIntegrityviolationexception;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||||
|
|
||||||
import org.baeldung.ex.dataIntegrityviolationexception.spring.Cause3DataContextWithJavaConfig;
|
import org.baeldung.ex.dataIntegrityviolationexception.spring.Cause3DataContextWithJavaConfig;
|
||||||
|
import org.baeldung.persistence.model.Foo;
|
||||||
|
import org.baeldung.persistence.service.IFooService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
|
@ -11,9 +17,14 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
@ContextConfiguration(classes = { Cause3DataContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
@ContextConfiguration(classes = { Cause3DataContextWithJavaConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||||
public class Cause3DataIntegrityViolationExceptionIntegrationTest {
|
public class Cause3DataIntegrityViolationExceptionIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Autowired
|
||||||
public final void givenContextIsInitialized_thenNoException() {
|
private IFooService fooService;
|
||||||
//
|
|
||||||
|
// tests
|
||||||
|
|
||||||
|
@Test(expected = DataIntegrityViolationException.class)
|
||||||
|
public final void whenEntityWithLongNameIsCreated_thenDataException() {
|
||||||
|
fooService.create(new Foo(randomAlphabetic(2048)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue