Context { public void abort() { if(!isValid()) log.info("abort() was called on a closed Context object. No changes to abort."); try { if (isValid() && !isReadOnly()) { dbConnection.rollback(); } } catch (SQLException se) { log.error(se.getMessage(), se); } finally { try { if (!dbConnection.isSessionAlive()) { dbConnection.closeDBConnection(); } } catch (Exception ex) { log.error("Exception aborting context", ex); } events = null; } } protected  Context(EventService eventService, DBConnection dbConnection);  Context();  Context(Mode mode); DatabaseConfigVO getDBConfig(); String getDbType(); void setCurrentUser(EPerson user); EPerson getCurrentUser(); Locale getCurrentLocale(); void setCurrentLocale(Locale locale); boolean ignoreAuthorization(); void turnOffAuthorisationSystem(); void restoreAuthSystemState(); void setExtraLogInfo(String info); String getExtraLogInfo(); void complete(); void commit(); void dispatchEvents(); void setDispatcher(String dispatcher); void addEvent(Event event); LinkedList<Event> getEvents(); boolean hasEvents(); Event pollEvent(); void abort(); boolean isValid(); boolean isReadOnly(); void setSpecialGroup(UUID groupID); boolean inSpecialGroup(UUID groupID); List<Group> getSpecialGroups(); void shutDownDatabase(); long getCacheSize(); void setMode(Mode newMode); Mode getCurrentMode(); @Deprecated void enableBatchMode(boolean batchModeEnabled); @Deprecated boolean isBatchModeEnabled(); @SuppressWarnings("unchecked") E reloadEntity(E entity); @SuppressWarnings("unchecked") void uncacheEntity(E entity); Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson); void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result, ResourcePolicy rp); Boolean getCachedGroupMembership(Group group, EPerson eperson); void cacheGroupMembership(Group group, EPerson eperson, Boolean isMember); void cacheAllMemberGroupsSet(EPerson ePerson, Set<Group> groups); Set<Group> getCachedAllMemberGroupsSet(EPerson ePerson);  }
@Test public void testAbort() throws SQLException, AuthorizeException { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.isAdmin((Context) any); result = true; }}; Context instance = new Context(); String createdEmail = "susie@email.com"; EPerson newUser = ePersonService.create(instance); newUser.setFirstName(context, "Susan"); newUser.setLastName(context, "Doe"); newUser.setEmail(createdEmail); newUser.setCanLogIn(true); newUser.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage()); instance.abort(); assertThat("testAbort 0", instance.isValid(), equalTo(false)); Context newInstance = new Context(); EPerson found = ePersonService.findByEmail(newInstance, createdEmail); assertThat("testAbort 1", found, nullValue()); cleanupContext(instance); cleanupContext(newInstance); }
@Test public void testAbort2() throws SQLException { Context instance = new Context(); instance.abort(); instance.abort(); cleanupContext(instance); }