Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
finish unit testing LowLevelStorageService and accompanying Function …
…classes
- Loading branch information
Showing
6 changed files
with
223 additions
and
31 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
36 changes: 36 additions & 0 deletions
36
fcrepo-kernel/src/main/java/org/fcrepo/services/functions/GetGoodFixityResults.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,36 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import static com.google.common.collect.Collections2.filter; | ||
import static com.google.common.collect.ImmutableSet.copyOf; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
import org.fcrepo.utils.FixityResult; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Predicate; | ||
|
||
public class GetGoodFixityResults implements Function<Collection<FixityResult>, Set<FixityResult>> { | ||
IsGoodFixity predicate = new IsGoodFixity(); | ||
|
||
public boolean isGood(FixityResult input) { | ||
return predicate.apply(input); | ||
} | ||
|
||
@Override | ||
public Set<FixityResult> apply(Collection<FixityResult> input) { | ||
return copyOf(filter(input, predicate)); | ||
} | ||
|
||
static class IsGoodFixity implements Predicate<FixityResult> { | ||
|
||
@Override | ||
public boolean apply(FixityResult input) { | ||
return input.computedChecksum.equals(input.dsChecksum) && | ||
input.computedSize == input.dsSize; | ||
} | ||
|
||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
fcrepo-kernel/src/test/java/org/fcrepo/services/functions/CheckCacheEntryFixityTest.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,27 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.net.URI; | ||
import java.security.MessageDigest; | ||
import java.security.SecureRandom; | ||
|
||
import org.fcrepo.utils.FixityResult; | ||
import org.fcrepo.utils.LowLevelCacheEntry; | ||
import org.junit.Test; | ||
import org.modeshape.jcr.value.binary.BinaryStoreException; | ||
|
||
public class CheckCacheEntryFixityTest { | ||
|
||
@Test | ||
public void testApply() throws BinaryStoreException { | ||
MessageDigest mockDigest = mock(MessageDigest.class); | ||
URI testUri = URI.create("urn:foo:bar"); | ||
long testSize = new SecureRandom().nextLong(); | ||
CheckCacheEntryFixity testObj = new CheckCacheEntryFixity(mockDigest, testUri, testSize); | ||
LowLevelCacheEntry mockEntry = mock(LowLevelCacheEntry.class); | ||
FixityResult actual = testObj.apply(mockEntry); | ||
verify(mockEntry).checkFixity(testUri, testSize, mockDigest); | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
fcrepo-kernel/src/test/java/org/fcrepo/services/functions/GetGoodFixityResultsTest.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,67 @@ | ||
package org.fcrepo.services.functions; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.fcrepo.services.functions.GetGoodFixityResults.IsGoodFixity; | ||
import org.fcrepo.utils.FixityResult; | ||
import org.junit.Test; | ||
|
||
public class GetGoodFixityResultsTest { | ||
|
||
@Test | ||
public void testPredicate() { | ||
IsGoodFixity testPred = new IsGoodFixity(); | ||
FixityResult mockFixity = mock(FixityResult.class); | ||
URI uri = URI.create("urn:foo:bar"); | ||
URI otherUri = URI.create("urn:does:not:match"); | ||
mockFixity.computedChecksum = uri; | ||
mockFixity.dsChecksum = otherUri; | ||
assertFalse(testPred.apply(mockFixity)); | ||
mockFixity.dsChecksum = uri; | ||
mockFixity.computedSize = 1L; | ||
assertFalse(testPred.apply(mockFixity)); | ||
mockFixity.dsSize = 1L; | ||
assertTrue(testPred.apply(mockFixity)); | ||
} | ||
|
||
@Test | ||
public void testIsGood() { | ||
GetGoodFixityResults testObj = new GetGoodFixityResults(); | ||
FixityResult mockFixity = mock(FixityResult.class); | ||
URI uri = URI.create("urn:foo:bar"); | ||
URI otherUri = URI.create("urn:does:not:match"); | ||
mockFixity.computedChecksum = uri; | ||
mockFixity.dsChecksum = otherUri; | ||
assertFalse(testObj.isGood(mockFixity)); | ||
mockFixity.dsChecksum = uri; | ||
mockFixity.computedSize = 1L; | ||
assertFalse(testObj.isGood(mockFixity)); | ||
mockFixity.dsSize = 1L; | ||
assertTrue(testObj.isGood(mockFixity)); | ||
} | ||
|
||
@Test | ||
public void testFunction() { | ||
GetGoodFixityResults testObj = new GetGoodFixityResults(); | ||
FixityResult mockBadFixity = mock(FixityResult.class); | ||
FixityResult mockGoodFixity = mock(FixityResult.class); | ||
List<FixityResult> mockList = Arrays.asList(new FixityResult[]{mockBadFixity, mockGoodFixity}); | ||
URI uri = URI.create("urn:foo:bar"); | ||
URI otherUri = URI.create("urn:does:not:match"); | ||
mockBadFixity.computedChecksum = uri; | ||
mockBadFixity.dsChecksum = otherUri; | ||
mockGoodFixity.computedChecksum = uri; | ||
mockGoodFixity.dsChecksum = uri; | ||
Set<FixityResult> actual = testObj.apply(mockList); | ||
assertEquals(1, actual.size()); | ||
assertTrue(actual.contains(mockGoodFixity)); | ||
} | ||
} |