|
2 | 2 |
|
3 | 3 | import com.arangodb.springframework.AbstractArangoTest; |
4 | 4 | import com.arangodb.springframework.ArangoTransactionalTestConfiguration; |
5 | | -import com.arangodb.springframework.repository.HumanBeingRepository; |
6 | | -import com.arangodb.springframework.testdata.HumanBeing; |
7 | | -import org.junit.Before; |
| 5 | +import com.arangodb.springframework.repository.ActorRepository; |
| 6 | +import com.arangodb.springframework.repository.MovieRepository; |
| 7 | +import com.arangodb.springframework.testdata.Actor; |
| 8 | +import com.arangodb.springframework.testdata.Movie; |
8 | 9 | import org.junit.Test; |
9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
10 | 11 | import org.springframework.test.context.ContextConfiguration; |
|
16 | 17 | @ContextConfiguration(classes = { ArangoTransactionalTestConfiguration.class }) |
17 | 18 | public class ArangoTransactionManagerRepositoryTest extends AbstractArangoTest { |
18 | 19 |
|
19 | | - private final HumanBeing anakin = new HumanBeing("Anakin", "Skywalker", false); |
| 20 | + public ArangoTransactionManagerRepositoryTest() { |
| 21 | + super(Movie.class, Actor.class); |
| 22 | + } |
20 | 23 |
|
21 | 24 | @Autowired |
22 | | - private HumanBeingRepository humanBeingRepository; |
| 25 | + private MovieRepository movieRepository; |
| 26 | + @Autowired |
| 27 | + private ActorRepository actorRepository; |
23 | 28 |
|
24 | | - @Before |
25 | | - public void cleanupDatabase() { |
26 | | - template.collection(HumanBeing.class).truncate(); |
| 29 | + Movie starWars = new Movie(); |
| 30 | + |
| 31 | + { |
| 32 | + starWars.setName("Star Wars"); |
27 | 33 | } |
28 | 34 |
|
29 | 35 | @Test |
30 | 36 | public void shouldWorkWithoutTransaction() { |
31 | | - humanBeingRepository.save(anakin); |
| 37 | + movieRepository.save(starWars); |
32 | 38 |
|
33 | | - assertThat(humanBeingRepository.findByNameAndSurname(anakin.getName(), anakin.getSurname())).isPresent(); |
| 39 | + assertThat(movieRepository.findById(starWars.getId())).isPresent(); |
34 | 40 | } |
35 | 41 |
|
36 | 42 | @Test |
37 | 43 | @Transactional |
38 | 44 | public void shouldWorkWithinTransaction() { |
39 | | - humanBeingRepository.save(anakin); |
| 45 | + movieRepository.save(starWars); |
40 | 46 |
|
41 | | - assertThat(humanBeingRepository.findByNameAndSurname(anakin.getName(), anakin.getSurname())).isPresent(); |
| 47 | + assertThat(movieRepository.findById(starWars.getId())).isPresent(); |
42 | 48 | } |
43 | 49 |
|
44 | 50 | @Test |
45 | 51 | @Transactional |
46 | 52 | public void shouldWorkAfterTransaction() { |
47 | 53 | TestTransaction.flagForCommit(); |
48 | 54 |
|
49 | | - humanBeingRepository.save(anakin); |
50 | | - |
51 | | - assertThat(TestTransaction.isFlaggedForRollback()).isFalse(); |
| 55 | + movieRepository.save(starWars); |
52 | 56 | TestTransaction.end(); |
53 | 57 |
|
54 | | - assertThat(humanBeingRepository.findByNameAndSurname(anakin.getName(), anakin.getSurname())).isPresent(); |
| 58 | + assertThat(movieRepository.findById(starWars.getId())).isPresent(); |
55 | 59 | } |
56 | 60 |
|
57 | 61 | @Test |
58 | 62 | @Transactional |
59 | 63 | public void shouldRollbackWithinTransaction() { |
60 | | - humanBeingRepository.save(anakin); |
61 | | - TestTransaction.flagForRollback(); |
| 64 | + movieRepository.save(starWars); |
62 | 65 | TestTransaction.end(); |
63 | 66 |
|
64 | | - assertThat(humanBeingRepository.findByNameAndSurname(anakin.getName(), anakin.getSurname())).isNotPresent(); |
| 67 | + assertThat(movieRepository.findById(starWars.getId())).isNotPresent(); |
65 | 68 | } |
66 | 69 | } |
0 commit comments