Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish unit testing FedoraTransactions and debug expiration, refactor…
… Transaction state to not rely on client code, Transaction#rollback and Transaction#commit now end internal sessions as appropriate, unit test Transaction
- Loading branch information
Showing
5 changed files
with
191 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
fcrepo-kernel/src/test/java/org/fcrepo/TransactionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.fcrepo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class TransactionTest { | ||
|
||
private Transaction testObj; | ||
|
||
private Session mockSession; | ||
|
||
@Before | ||
public void setUp(){ | ||
mockSession = mock(Session.class); | ||
testObj = new Transaction(mockSession); | ||
} | ||
|
||
@Test | ||
public void testRollback() throws RepositoryException { | ||
testObj.rollback(); | ||
verify(mockSession).refresh(false); | ||
verify(mockSession).logout(); | ||
assertEquals(Transaction.State.ROLLED_BACK, testObj.getState()); | ||
long update = testObj.getExpires().getTime(); | ||
assertTrue(update <= System.currentTimeMillis()); | ||
} | ||
|
||
@Test | ||
public void testCommit() throws RepositoryException { | ||
testObj.commit(); | ||
verify(mockSession).save(); | ||
verify(mockSession).logout(); | ||
assertEquals(Transaction.State.COMMITED, testObj.getState()); | ||
long update = testObj.getExpires().getTime(); | ||
assertTrue(update <= System.currentTimeMillis()); | ||
} | ||
|
||
@Test | ||
public void testExpire() throws RepositoryException { | ||
long orig = testObj.getExpires().getTime(); | ||
testObj.expire(); | ||
verify(mockSession, never()).save(); | ||
verify(mockSession).logout(); | ||
long update = testObj.getExpires().getTime(); | ||
assertTrue(update < orig); | ||
assertTrue(update <= System.currentTimeMillis()); | ||
assertTrue(update < orig); | ||
} | ||
|
||
@Test | ||
public void testExpiryUpdate() throws RepositoryException { | ||
long orig = testObj.getExpires().getTime(); | ||
testObj.updateExpiryDate(); | ||
long update = testObj.getExpires().getTime(); | ||
assertTrue("Unexpected negative expiry delta: " + (update - orig), | ||
update - orig >= 0); | ||
} | ||
|
||
@Test | ||
public void testState() throws RepositoryException { | ||
assertEquals(Transaction.State.NEW, testObj.getState()); | ||
when(mockSession.hasPendingChanges()).thenReturn(true, false); | ||
assertEquals(Transaction.State.DIRTY, testObj.getState()); | ||
testObj.commit(); | ||
} | ||
} |