JAVA-10516: Revisit spring-boot module inside spring-boot-modules folder (#12038)
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.boot;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.session.exception.Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@TestPropertySource("classpath:exception.properties")
|
||||
public class ApplicationIntegrationTest {
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.boot.repository;
|
||||
|
||||
import com.baeldung.demo.DemoApplicationIntegrationTest;
|
||||
import com.baeldung.demo.model.Foo;
|
||||
import com.baeldung.demo.repository.FooRepository;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@Transactional
|
||||
public class FooRepositoryIntegrationTest extends DemoApplicationIntegrationTest {
|
||||
@Autowired
|
||||
private FooRepository fooRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
fooRepository.save(new Foo("Foo"));
|
||||
fooRepository.save(new Foo("Bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindByName() {
|
||||
Foo foo = fooRepository.findByName("Bar");
|
||||
|
||||
assertThat(foo, notNullValue());
|
||||
assertThat(foo.getId(), notNullValue());
|
||||
assertThat(foo.getName(), is("Bar"));
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.boot.repository;
|
||||
|
||||
import com.baeldung.demo.DemoApplicationIntegrationTest;
|
||||
import com.baeldung.demo.model.Foo;
|
||||
import com.baeldung.demo.repository.FooRepository;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@Transactional
|
||||
public class HibernateSessionIntegrationTest extends DemoApplicationIntegrationTest {
|
||||
@Autowired
|
||||
private FooRepository fooRepository;
|
||||
|
||||
@Test
|
||||
public void whenSavingWithCurrentSession_thenThrowNoException() {
|
||||
fooRepository.save(new Foo("Exception Solved"));
|
||||
|
||||
Foo foo = fooRepository.findByName("Exception Solved");
|
||||
|
||||
assertThat(foo, notNullValue());
|
||||
assertThat(foo.getId(), notNullValue());
|
||||
assertThat(foo.getName(), is("Exception Solved"));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.boot.repository;
|
||||
|
||||
import com.baeldung.boot.ApplicationIntegrationTest;
|
||||
import com.baeldung.demo.model.Foo;
|
||||
import com.baeldung.session.exception.repository.FooRepository;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@TestPropertySource("classpath:exception-hibernate.properties")
|
||||
public class NoHibernateSessionIntegrationTest extends ApplicationIntegrationTest {
|
||||
@Autowired
|
||||
private FooRepository fooRepository;
|
||||
|
||||
@Test(expected = HibernateException.class)
|
||||
public void whenSavingWithoutCurrentSession_thenThrowException() {
|
||||
Foo foo = new Foo("Exception Thrown");
|
||||
fooRepository.save(foo);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.demo;
|
||||
|
||||
import com.baeldung.demo.DemoApplication;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class DemoApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
spring.profiles.active=exception
|
||||
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
|
||||
@@ -0,0 +1,2 @@
|
||||
spring.dao.exceptiontranslation.enabled=false
|
||||
spring.profiles.active=exception
|
||||
Reference in New Issue
Block a user