22
33import static org .junit .Assert .assertFalse ;
44import static org .junit .Assert .assertTrue ;
5- import static org .mockito .Mockito .verify ;
6- import static org .mockito .Mockito .when ;
7-
85import java .io .IOException ;
96import java .sql .SQLException ;
10- import java .util .ArrayList ;
117import java .util .List ;
128
139import javax .sql .DataSource ;
1814import org .junit .BeforeClass ;
1915import org .junit .Test ;
2016import org .junit .runner .RunWith ;
21- import org .mockito .Matchers ;
22- import org .mockito .Mock ;
23- import org .mockito .Mockito ;
24- import org .mockito .invocation .InvocationOnMock ;
25- import org .mockito .junit .MockitoJUnitRunner ;
26- import org .mockito .stubbing .Answer ;
27- import org .springframework .jdbc .core .JdbcTemplate ;
17+ import org .springframework .beans .factory .annotation .Autowired ;
18+ import org .springframework .boot .test .context .SpringBootTest ;
19+ import org .springframework .test .context .junit4 .SpringRunner ;
2820import org .xml .sax .SAXException ;
2921
3022import com .ffxivcensus .gatherer .config .ApplicationConfig ;
5244 * @see com.ffxivcensus.gatherer.player.PlayerBuilderIT
5345 * @since v1.0
5446 */
55- @ RunWith (MockitoJUnitRunner .class )
47+ @ RunWith (SpringRunner .class )
48+ @ SpringBootTest
5649public class GathererControllerIT {
5750
51+ @ Autowired
5852 private ApplicationConfig config ;
5953 private static DataSource dataSource ;
60- @ Mock
61- private GathererFactory mockFactory ;
62- @ Mock
63- private JdbcTemplate jdbcTemplate ;
54+ @ Autowired
55+ private GathererController gathererController ;
56+ @ Autowired
57+ private PlayerBeanDAO dao ;
6458
6559 @ BeforeClass
6660 public static void setUpClass () throws ParserConfigurationException , IOException , SAXException , SQLException , LiquibaseException {
@@ -86,17 +80,6 @@ public static void setUpClass() throws ParserConfigurationException, IOException
8680
8781 @ Before
8882 public void setUp () throws ParserConfigurationException , IOException , SAXException {
89- config = ConfigurationBuilder .createBuilder ().loadXMLConfiguration ().getConfiguration ();
90- when (mockFactory .createGatherer ()).thenAnswer (new Answer <Gatherer >() {
91-
92- @ Override
93- public Gatherer answer (InvocationOnMock invocation ) throws Throwable {
94- Gatherer gatherer = new Gatherer ();
95- gatherer .setPlayerBeanDAO (new PlayerBeanDAO (config , jdbcTemplate ));
96- return gatherer ;
97- }
98-
99- });
10083 }
10184
10285 @ AfterClass
@@ -117,26 +100,22 @@ public void testRunBasic() throws Exception {
117100 config .setEndId (11887010 );
118101 config .setThreadLimit (40 );
119102
120- GathererController gathererController = new GathererController (config , mockFactory );
121-
122103 gathererController .run ();
123104
124- verify (jdbcTemplate , Mockito .atLeastOnce ()).update (Mockito .anyString (), Mockito .<Object >any ());
125-
126- // List<Integer> addedIDs = new ArrayList<Integer>();
127- //
128- // // Test for IDs we know exist
129- // assertTrue(addedIDs.contains(11886902));
130- // assertTrue(addedIDs.contains(11886903));
131- // assertTrue(addedIDs.contains(11886990));
132- // assertTrue(addedIDs.contains(11887010));
133- //
134- // // Test that gatherer has not written records that don't exist
135- // assertFalse(addedIDs.contains(11886909));
136- //
137- // // Test that gatherer has not 'overrun'
138- // assertFalse(addedIDs.contains(11887011));
139- // assertFalse(addedIDs.contains(11886901));
105+ List <Integer > addedIDs = dao .getAdded (11886902 , 11887010 );
106+
107+ // Test for IDs we know exist
108+ assertTrue (addedIDs .contains (11886902 ));
109+ assertTrue (addedIDs .contains (11886903 ));
110+ assertTrue (addedIDs .contains (11886990 ));
111+ assertTrue (addedIDs .contains (11887010 ));
112+
113+ // Test that gatherer has not written records that don't exist
114+ assertFalse (addedIDs .contains (11886909 ));
115+
116+ // Test that gatherer has not 'overrun'
117+ assertFalse (addedIDs .contains (11887011 ));
118+ assertFalse (addedIDs .contains (11886901 ));
140119 }
141120
142121 /**
@@ -146,11 +125,7 @@ public void testRunBasic() throws Exception {
146125 public void testRunBasicInvalidParams () throws Exception {
147126 config .setStartId (11887010 );
148127
149- GathererController gathererController = new GathererController (config , mockFactory );
150-
151128 gathererController .run ();
152-
153- verify (jdbcTemplate , Mockito .never ()).update (Mockito .anyString (), Mockito .<Object >any ());
154129 }
155130
156131 /**
@@ -165,25 +140,21 @@ public void testRunAdvancedOptions() throws Exception {
165140 config .setStoreMounts (true );
166141 config .setStoreProgression (true );
167142
168- GathererController gathererController = new GathererController (config , mockFactory );
169-
170143 gathererController .run ();
171144
172- verify (jdbcTemplate , Mockito .atLeastOnce ()).update (Mockito .anyString (), Mockito .<Object >any ());
173-
174- // List<Integer> addedIDs = new ArrayList<Integer>();
175- //
176- // // Test for IDs we know exist
177- // assertTrue(addedIDs.contains(config.getStartId()));
178- // assertTrue(addedIDs.contains(config.getEndId()));
179- // assertTrue(addedIDs.contains(1557362));
180- // assertTrue(addedIDs.contains(1557495));
181- //
182- // // Test that gatherer has not written records that don't exist
183- // assertFalse(addedIDs.contains(1558259));
184- //
185- // // Test that gatherer has not 'overrun'
186- // assertFalse(addedIDs.contains(config.getStartId() - 1));
187- // assertFalse(addedIDs.contains(config.getEndId() + 1));
145+ List <Integer > addedIDs = dao .getAdded (1557260 , 1558260 );
146+
147+ // Test for IDs we know exist
148+ assertTrue (addedIDs .contains (config .getStartId ()));
149+ assertTrue (addedIDs .contains (config .getEndId ()));
150+ assertTrue (addedIDs .contains (1557362 ));
151+ assertTrue (addedIDs .contains (1557495 ));
152+
153+ // Test that gatherer has not written records that don't exist
154+ assertFalse (addedIDs .contains (1558259 ));
155+
156+ // Test that gatherer has not 'overrun'
157+ assertFalse (addedIDs .contains (config .getStartId () - 1 ));
158+ assertFalse (addedIDs .contains (config .getEndId () + 1 ));
188159 }
189160}
0 commit comments