Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for current/saved filehandle/stateid
Acked-by: Paul Millar Target: master
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
core/src/test/java/org/dcache/nfs/v4/CompoundContextTest.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,107 @@ | ||
package org.dcache.nfs.v4; | ||
|
||
import org.dcache.nfs.ChimeraNFSException; | ||
import org.dcache.nfs.status.BadStateidException; | ||
import org.dcache.nfs.status.NoFileHandleException; | ||
import org.dcache.nfs.status.RestoreFhException; | ||
import org.dcache.nfs.v4.xdr.stateid4; | ||
import org.dcache.nfs.vfs.Inode; | ||
import org.junit.Test; | ||
import org.junit.Before; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.dcache.nfs.v4.NfsTestUtils.generateRpcCall; | ||
|
||
public class CompoundContextTest { | ||
|
||
private CompoundContext context; | ||
|
||
@Before | ||
public void setUp() { | ||
context = new CompoundContextBuilder() | ||
.withMinorversion(1) | ||
.withCall(generateRpcCall()) | ||
.build(); | ||
} | ||
|
||
@Test(expected = NoFileHandleException.class) | ||
public void testNoCurrentFileHandle() throws ChimeraNFSException { | ||
context.currentInode(); | ||
} | ||
|
||
@Test | ||
public void testCurrentFileHandle() throws ChimeraNFSException { | ||
Inode inode = mock(Inode.class); | ||
context.currentInode(inode); | ||
|
||
assertSame(inode, context.currentInode()); | ||
} | ||
|
||
@Test(expected = BadStateidException.class) | ||
public void testNoCurrentStateid() throws ChimeraNFSException { | ||
context.currentStateid(); | ||
} | ||
|
||
@Test | ||
public void testCurrentStateid() throws ChimeraNFSException { | ||
stateid4 stateid = mock(stateid4.class); | ||
context.currentStateid(stateid); | ||
|
||
assertSame(stateid, context.currentStateid()); | ||
} | ||
|
||
@Test(expected = NoFileHandleException.class) | ||
public void testNoSavedFileHandle() throws ChimeraNFSException { | ||
context.savedInode(); | ||
} | ||
|
||
@Test(expected = NoFileHandleException.class) | ||
public void testNoCurrentFileHandleOnSave() throws ChimeraNFSException { | ||
context.saveCurrentInode(); | ||
} | ||
|
||
@Test | ||
public void testSavedFileHandle() throws ChimeraNFSException { | ||
Inode inode = mock(Inode.class); | ||
context.currentInode(inode); | ||
context.saveCurrentInode(); | ||
|
||
assertSame(inode, context.savedInode()); | ||
} | ||
|
||
@Test(expected = RestoreFhException.class) | ||
public void testReastireCurrentFileHandleNoSaved() throws ChimeraNFSException { | ||
context.restoreSavedInode(); | ||
} | ||
|
||
@Test | ||
public void testRestoreCurrentFileHandle() throws ChimeraNFSException { | ||
Inode inode = mock(Inode.class); | ||
context.currentInode(inode); | ||
context.saveCurrentInode(); | ||
|
||
context.clearCurrentInode(); | ||
context.restoreSavedInode(); | ||
|
||
assertSame(inode, context.currentInode()); | ||
} | ||
|
||
@Test | ||
public void testRestoreCurrentStateid() throws ChimeraNFSException { | ||
Inode inode = mock(Inode.class); | ||
stateid4 stateid = mock(stateid4.class); | ||
|
||
context.currentInode(inode); | ||
context.currentStateid(stateid); | ||
context.saveCurrentInode(); | ||
|
||
context.clearCurrentInode(); | ||
context.currentStateid(null); | ||
|
||
context.restoreSavedInode(); | ||
|
||
assertSame(inode, context.currentInode()); | ||
} | ||
|
||
} |