|
|
@@ -1,31 +1,62 @@
|
|
1
|
1
|
package se.citerus.dddsample.infrastructure.persistence.hibernate;
|
|
2
|
2
|
|
|
|
3
|
+import org.junit.Before;
|
|
|
4
|
+import org.junit.Test;
|
|
|
5
|
+import org.junit.runner.RunWith;
|
|
|
6
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
7
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
8
|
+import org.springframework.orm.hibernate3.HibernateTransactionManager;
|
|
|
9
|
+import org.springframework.test.context.ContextConfiguration;
|
|
|
10
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
11
|
+import org.springframework.test.context.transaction.TransactionConfiguration;
|
|
|
12
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
13
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
14
|
+import se.citerus.dddsample.application.util.SampleDataGenerator;
|
|
3
|
15
|
import se.citerus.dddsample.domain.model.location.Location;
|
|
4
|
16
|
import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
5
|
17
|
import se.citerus.dddsample.domain.model.location.UnLocode;
|
|
6
|
18
|
|
|
|
19
|
+import javax.sql.DataSource;
|
|
7
|
20
|
import java.util.List;
|
|
8
|
21
|
|
|
9
|
|
-/*public class LocationRepositoryTest extends AbstractRepositoryTest {
|
|
10
|
|
- private LocationRepository locationRepository;
|
|
11
|
|
-
|
|
12
|
|
- public void testFind() throws Exception {
|
|
13
|
|
- final UnLocode melbourne = new UnLocode("AUMEL");
|
|
14
|
|
- Location location = locationRepository.find(melbourne);
|
|
15
|
|
- assertNotNull(location);
|
|
16
|
|
- assertEquals(melbourne, location.unLocode());
|
|
17
|
|
-
|
|
18
|
|
- assertNull(locationRepository.find(new UnLocode("NOLOC")));
|
|
19
|
|
- }
|
|
20
|
|
-
|
|
21
|
|
- public void testFindAll() throws Exception {
|
|
22
|
|
- List<Location> allLocations = locationRepository.findAll();
|
|
23
|
|
-
|
|
24
|
|
- assertNotNull(allLocations);
|
|
25
|
|
- assertEquals(7, allLocations.size());
|
|
26
|
|
- }
|
|
27
|
|
-
|
|
28
|
|
- public void setLocationRepository(LocationRepository locationRepository) {
|
|
29
|
|
- this.locationRepository = locationRepository;
|
|
30
|
|
- }
|
|
31
|
|
-}*/
|
|
|
22
|
+import static org.junit.Assert.*;
|
|
|
23
|
+
|
|
|
24
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
25
|
+@ContextConfiguration(value = {"/context-infrastructure-persistence.xml", "/context-domain.xml"})
|
|
|
26
|
+@TransactionConfiguration(transactionManager = "transactionManager")
|
|
|
27
|
+@Transactional
|
|
|
28
|
+public class LocationRepositoryTest {
|
|
|
29
|
+ @Autowired
|
|
|
30
|
+ private LocationRepository locationRepository;
|
|
|
31
|
+
|
|
|
32
|
+ @Autowired
|
|
|
33
|
+ private DataSource dataSource;
|
|
|
34
|
+
|
|
|
35
|
+ @Autowired
|
|
|
36
|
+ private HibernateTransactionManager transactionManager;
|
|
|
37
|
+
|
|
|
38
|
+ @Before
|
|
|
39
|
+ public void setup() {
|
|
|
40
|
+ JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
41
|
+ SampleDataGenerator.loadSampleData(jdbcTemplate, new TransactionTemplate(transactionManager));
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ @Test
|
|
|
45
|
+ public void testFind() throws Exception {
|
|
|
46
|
+ final UnLocode melbourne = new UnLocode("AUMEL");
|
|
|
47
|
+ Location location = locationRepository.find(melbourne);
|
|
|
48
|
+ assertNotNull(location);
|
|
|
49
|
+ assertEquals(melbourne, location.unLocode());
|
|
|
50
|
+
|
|
|
51
|
+ assertNull(locationRepository.find(new UnLocode("NOLOC")));
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ @Test
|
|
|
55
|
+ public void testFindAll() throws Exception {
|
|
|
56
|
+ List<Location> allLocations = locationRepository.findAll();
|
|
|
57
|
+
|
|
|
58
|
+ assertNotNull(allLocations);
|
|
|
59
|
+ assertEquals(7, allLocations.size());
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+}
|