@Test public void addTwoGroupsToBibEntryChangesGroupsField() { group.add(entry); group2.add(entry); assertEquals( Optional.of("myExplicitGroup, myExplicitGroup2"), entry.getField(FieldName.GROUPS)); }
/** * Recursive method to include a tree of groups. * * @param cursor The current GroupTreeNode in the GroupsTree * @param parentID The integer ID associated with the cursors's parent node * @param currentID The integer value to associate with the cursor * @param out The output (PrintStream or Connection) object to which the DML should be written. * @param database_id Id of jabref database to which the group is part of */ private int populateEntryGroupsTable( GroupTreeNode cursor, int parentID, int currentID, Object out, int database_id) throws SQLException { // if this group contains entries... if (cursor.getGroup() instanceof ExplicitGroup) { ExplicitGroup grp = (ExplicitGroup) cursor.getGroup(); for (BibtexEntry be : grp.getEntries()) { SQLUtil.processQuery( out, "INSERT INTO entry_group (entries_id, groups_id) " + "VALUES (" + "(SELECT entries_id FROM entries WHERE jabref_eid=" + '\'' + be.getId() + "' AND database_id = " + database_id + "), " + "(SELECT groups_id FROM groups WHERE database_id=" + '\'' + database_id + "' AND parent_id=" + '\'' + parentID + "' AND label=" + '\'' + grp.getName() + "')" + ");"); } } // recurse on child nodes (depth-first traversal) Object response = SQLUtil.processQueryWithResults( out, "SELECT groups_id FROM groups WHERE label='" + cursor.getGroup().getName() + "' AND database_id='" + database_id + "' AND parent_id='" + parentID + "';"); // setting values to ID and myID to be used in case of textual SQL // export ++currentID; int myID = currentID; if (response instanceof Statement) { ResultSet rs = ((Statement) response).getResultSet(); rs.next(); myID = rs.getInt("groups_id"); } for (Enumeration<GroupTreeNode> e = cursor.children(); e.hasMoreElements(); ) { currentID = populateEntryGroupsTable(e.nextElement(), myID, currentID, out, database_id); } return currentID; }
@Test // For https://github.com/JabRef/jabref/issues/1873 public void containsOnlyMatchesCompletePhraseWithSlash() throws Exception { entry.setField(FieldName.GROUPS, "myExplicitGroup/b"); assertFalse(group.contains(entry)); }
@Test public void addDuplicateGroupDoesNotChangeGroupsField() throws Exception { entry.setField(FieldName.GROUPS, "myExplicitGroup"); group.add(entry); assertEquals(Optional.of("myExplicitGroup"), entry.getField(FieldName.GROUPS)); }
@Test public void addSingleGroupToNonemptyBibEntryAppendsToGroupsField() { entry.setField(FieldName.GROUPS, "some thing"); group.add(entry); assertEquals(Optional.of("some thing, myExplicitGroup"), entry.getField(FieldName.GROUPS)); }
@Test // For https://github.com/JabRef/jabref/issues/2334 public void removeDoesNotChangeFieldIfContainsNameAsWord() throws Exception { entry.setField(FieldName.GROUPS, "myExplicitGroup alternative"); group.remove(entry); assertEquals(Optional.of("myExplicitGroup alternative"), entry.getField(FieldName.GROUPS)); }
@Test public void addSingleGroupToEmptyBibEntryChangesGroupsField() { group.add(entry); assertEquals(Optional.of("myExplicitGroup"), entry.getField(FieldName.GROUPS)); }