1616package org .springframework .batch .item .database ;
1717
1818import static org .junit .Assert .assertEquals ;
19+ import static org .junit .Assert .assertNotNull ;
1920
2021import java .util .List ;
2122
2728import org .springframework .batch .item .data .RepositoryItemReader ;
2829import org .springframework .batch .item .sample .books .Author ;
2930import org .springframework .batch .item .sample .books .Book ;
30- import org .springframework .batch .item .sample .books .data .SimpleService ;
3131import org .springframework .beans .factory .annotation .Autowired ;
3232import org .springframework .test .context .ContextConfiguration ;
3333import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
34+ import org .springframework .transaction .annotation .Transactional ;
3435
3536
3637@ RunWith (SpringJUnit4ClassRunner .class )
3738@ ContextConfiguration (locations = "RepositoryItemReaderCommonTests-context.xml" )
39+ @ Transactional
3840public class RepositoryItemReaderIntegrationTests {
3941
4042 private static final String CONTEXT_KEY = "RepositoryItemReader.read.count" ;
4143
42- @ Autowired
43- private SimpleService service ;
44-
4544 @ Autowired
4645 private RepositoryItemReader <Author > reader ;
4746
@@ -52,65 +51,75 @@ public void reinitializeReader() {
5251
5352 @ Test
5453 public void testReadFromFirstPos () throws Exception {
55- service . openReader (new ExecutionContext ());
54+ reader . open (new ExecutionContext ());
5655
57- final List < Book > books = service . nextAuthorBooks ();
56+ Author author = reader . read ();
5857
59- assertEquals ("Books list size" , 2 , books .size ());
60- assertEquals ("First book" , "author 1 - book 1" , books .get (0 ).getName ());
61- assertEquals ("Second book" , "author 1 - book 2" , books .get (1 ).getName ());
58+ assertNotNull (author );
59+ final List <Book > books = author .getBooks ();
60+ assertEquals ("Books list size must be = 2" , 2 , books .size ());
61+ assertEquals ("First book must be author 1 - book 1" , "author 1 - book 1" , books .get (0 ).getName ());
62+ assertEquals ("Second book must be author 1 - book 2" , "author 1 - book 2" , books .get (1 ).getName ());
6263 }
6364
6465 @ Test
6566 public void testReadFromWithinPage () throws Exception {
6667 reader .setCurrentItemCount (1 );
67- service . openReader (new ExecutionContext ());
68+ reader . open (new ExecutionContext ());
6869
69- final List < Book > books = service . nextAuthorBooks ();
70+ Author author = reader . read ();
7071
71- assertEquals ("Books list size" , 2 , books .size ());
72- assertEquals ("First book" , "author 2 - book 1" , books .get (0 ).getName ());
73- assertEquals ("Second book" , "author 2 - book 2" , books .get (1 ).getName ());
72+ assertNotNull (author );
73+ final List <Book > books = author .getBooks ();
74+ assertEquals ("Books list size must be = 2" , 2 , books .size ());
75+ assertEquals ("First book must be author 2 - book 1" , "author 2 - book 1" , books .get (0 ).getName ());
76+ assertEquals ("Second book must be author 2 - book 2" , "author 2 - book 2" , books .get (1 ).getName ());
7477 }
7578
7679 @ Test
7780 public void testReadFromNewPage () throws Exception {
7881 reader .setPageSize (2 );
7982 reader .setCurrentItemCount (2 ); // 3rd item = 1rst of page 2
80- service . openReader (new ExecutionContext ());
83+ reader . open (new ExecutionContext ());
8184
82- final List < Book > books = service . nextAuthorBooks ();
85+ Author author = reader . read ();
8386
84- assertEquals ("Books list size" , 2 , books .size ());
85- assertEquals ("First book" , "author 3 - book 1" , books .get (0 ).getName ());
86- assertEquals ("Second book" , "author 3 - book 2" , books .get (1 ).getName ());
87+ assertNotNull (author );
88+ final List <Book > books = author .getBooks ();
89+ assertEquals ("Books list size must be = 2" , 2 , books .size ());
90+ assertEquals ("First book must be author 3 - book 1" , "author 3 - book 1" , books .get (0 ).getName ());
91+ assertEquals ("Second book must be author 3 - book 2" , "author 3 - book 2" , books .get (1 ).getName ());
8792 }
8893
8994 @ Test
9095 public void testReadFromWithinPage_Restart () throws Exception {
9196 final ExecutionContext executionContext = new ExecutionContext ();
9297 executionContext .putInt (CONTEXT_KEY , 1 );
93- service . openReader (executionContext );
98+ reader . open (executionContext );
9499
95- final List < Book > books = service . nextAuthorBooks ();
100+ Author author = reader . read ();
96101
97- assertEquals ("Books list size" , 2 , books .size ());
98- assertEquals ("First book" , "author 2 - book 1" , books .get (0 ).getName ());
99- assertEquals ("Second book" , "author 2 - book 2" , books .get (1 ).getName ());
102+ assertNotNull (author );
103+ final List <Book > books = author .getBooks ();
104+ assertEquals ("Books list size must be = 2" , 2 , books .size ());
105+ assertEquals ("First book must be author 2 - book 1" , "author 2 - book 1" , books .get (0 ).getName ());
106+ assertEquals ("Second book must be author 2 - book 2" , "author 2 - book 2" , books .get (1 ).getName ());
100107 }
101108
102109 @ Test
103110 public void testReadFromNewPage_Restart () throws Exception {
104111 reader .setPageSize (2 );
105112 final ExecutionContext executionContext = new ExecutionContext ();
106113 executionContext .putInt (CONTEXT_KEY , 2 );
107- service . openReader (executionContext );
114+ reader . open (executionContext );
108115
109- final List < Book > books = service . nextAuthorBooks ();
116+ Author author = reader . read ();
110117
111- assertEquals ("Books list size" , 2 , books .size ());
112- assertEquals ("First book" , "author 3 - book 1" , books .get (0 ).getName ());
113- assertEquals ("Second book" , "author 3 - book 2" , books .get (1 ).getName ());
118+ assertNotNull (author );
119+ final List <Book > books = author .getBooks ();
120+ assertEquals ("Books list size must be = 2" , 2 , books .size ());
121+ assertEquals ("First book must be author 3 - book 1" , "author 3 - book 1" , books .get (0 ).getName ());
122+ assertEquals ("Second book must be author 3 - book 2" , "author 3 - book 2" , books .get (1 ).getName ());
114123 }
115124
116125}
0 commit comments