@@ -95,6 +95,59 @@ void testInsertEntry() throws SQLException {
9595 assertEquals (expectedFieldMap , actualFieldMap );
9696 }
9797
98+ @ Test
99+ void testInsertMultipleEntries () throws SQLException {
100+ BibEntry firstEntry = getBibEntryExample ();
101+ String firstId = firstEntry .getId ();
102+ BibEntry secondEntry = getBibEntryExample2 ();
103+ String secondId = secondEntry .getId ();
104+ BibEntry thirdEntry = getBibEntryExample3 ();
105+ String thirdId = thirdEntry .getId ();
106+
107+ // This must eventually be changed to insertEntries() once that method is implemented
108+ dbmsProcessor .insertEntry (firstEntry );
109+ dbmsProcessor .insertEntry (secondEntry );
110+ dbmsProcessor .insertEntry (thirdEntry );
111+
112+ Map <Integer , Map <String , String >> actualFieldMap = new HashMap <>();
113+
114+ try (ResultSet entryResultSet = selectFrom ("ENTRY" , dbmsConnection , dbmsProcessor )) {
115+ assertTrue (entryResultSet .next ());
116+ assertEquals (1 , entryResultSet .getInt ("SHARED_ID" ));
117+ assertEquals ("inproceedings" , entryResultSet .getString ("TYPE" ));
118+ assertEquals (1 , entryResultSet .getInt ("VERSION" ));
119+ assertTrue (entryResultSet .next ());
120+ assertEquals (2 , entryResultSet .getInt ("SHARED_ID" ));
121+ assertEquals ("inproceedings" , entryResultSet .getString ("TYPE" ));
122+ assertEquals (1 , entryResultSet .getInt ("VERSION" ));
123+ assertTrue (entryResultSet .next ());
124+ assertEquals (3 , entryResultSet .getInt ("SHARED_ID" ));
125+ assertFalse (entryResultSet .next ());
126+
127+ try (ResultSet fieldResultSet = selectFrom ("FIELD" , dbmsConnection , dbmsProcessor )) {
128+ while (fieldResultSet .next ()) {
129+ if (actualFieldMap .keySet ().contains (fieldResultSet .getInt ("ENTRY_SHARED_ID" ))) {
130+ actualFieldMap .get (fieldResultSet .getInt ("ENTRY_SHARED_ID" )).put (
131+ fieldResultSet .getString ("NAME" ), fieldResultSet .getString ("VALUE" ));
132+ } else {
133+ int sharedId = fieldResultSet .getInt ("ENTRY_SHARED_ID" );
134+ actualFieldMap .put (sharedId ,
135+ new HashMap <>());
136+ actualFieldMap .get (sharedId ).put (fieldResultSet .getString ("NAME" ),
137+ fieldResultSet .getString ("VALUE" ));
138+ }
139+ }
140+ }
141+ }
142+ List <BibEntry > entries = Arrays .asList (firstEntry , secondEntry , thirdEntry );
143+ Map <Integer , Map <String , String >> expectedFieldMap = entries .stream ()
144+ .collect (Collectors .toMap (bibEntry -> bibEntry .getSharedBibEntryData ().getSharedID (),
145+ (bibEntry ) -> bibEntry .getFieldMap ().entrySet ().stream ()
146+ .collect (Collectors .toMap ((entry ) -> entry .getKey ().getName (), Map .Entry ::getValue ))));
147+
148+ assertEquals (expectedFieldMap , actualFieldMap );
149+ }
150+
98151 @ Test
99152 void testUpdateEntry () throws Exception {
100153 BibEntry expectedEntry = getBibEntryExample ();
@@ -156,7 +209,7 @@ void testUpdateEqualEntry() throws OfflineLockException, SQLException {
156209 @ Test
157210 void testRemoveAllEntries () throws SQLException {
158211 BibEntry firstEntry = getBibEntryExample ();
159- BibEntry secondEntry = getBibEntryExample ();
212+ BibEntry secondEntry = getBibEntryExample2 ();
160213 List <BibEntry > entriesToRemove = Arrays .asList (firstEntry , secondEntry );
161214 dbmsProcessor .insertEntry (firstEntry );
162215 dbmsProcessor .insertEntry (secondEntry );
@@ -170,8 +223,8 @@ void testRemoveAllEntries() throws SQLException {
170223 @ Test
171224 void testRemoveSomeEntries () throws SQLException {
172225 BibEntry firstEntry = getBibEntryExample ();
173- BibEntry secondEntry = getBibEntryExample ();
174- BibEntry thirdEntry = getBibEntryExample ();
226+ BibEntry secondEntry = getBibEntryExample2 ();
227+ BibEntry thirdEntry = getBibEntryExample3 ();
175228
176229 // Remove the first and third entries - the second should remain (SHARED_ID will be 2)
177230
@@ -311,6 +364,24 @@ private static BibEntry getBibEntryExample() {
311364 .withCiteKey ("nanoproc1994" );
312365 }
313366
367+ private static BibEntry getBibEntryExample2 () {
368+ return new BibEntry (StandardEntryType .InProceedings )
369+ .withField (StandardField .AUTHOR , "Shelah, Saharon and Ziegler, Martin" )
370+ .withField (StandardField .TITLE , "Algebraically closed groups of large cardinality" )
371+ .withField (StandardField .JOURNAL , "The Journal of Symbolic Logic" )
372+ .withField (StandardField .YEAR , "1979" )
373+ .withCiteKey ("algegrou1979" );
374+ }
375+
376+ private static BibEntry getBibEntryExample3 () {
377+ return new BibEntry (StandardEntryType .InProceedings )
378+ .withField (StandardField .AUTHOR , "Hodges, Wilfrid and Shelah, Saharon" )
379+ .withField (StandardField .TITLE , "Infinite games and reduced products" )
380+ .withField (StandardField .JOURNAL , "Annals of Mathematical Logic" )
381+ .withField (StandardField .YEAR , "1981" )
382+ .withCiteKey ("infigame1981" );
383+ }
384+
314385 private ResultSet selectFrom (String table , DBMSConnection dbmsConnection , DBMSProcessor dbmsProcessor ) {
315386 try {
316387 return dbmsConnection .getConnection ().createStatement ().executeQuery ("SELECT * FROM " + escape (table , dbmsProcessor ));
0 commit comments