Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pure Junit test for FixityService
- Loading branch information
Showing
3 changed files
with
44 additions
and
9 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
48 changes: 41 additions & 7 deletions
48
fcrepo-fixity-core/src/test/java/org/fcrepo/services/FixityServiceTest.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 |
---|---|---|
@@ -1,28 +1,62 @@ | ||
/** | ||
* | ||
*/ | ||
|
||
package org.fcrepo.services; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
|
||
import org.fcrepo.fixity.client.FedoraFixityClient; | ||
import org.fcrepo.fixity.service.FixityService; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import org.mockito.Mockito; | ||
import org.springframework.jms.core.JmsTemplate; | ||
import org.springframework.jms.core.MessageCreator; | ||
|
||
/** | ||
* @author frank asseg | ||
* | ||
*/ | ||
public class FixityServiceTest { | ||
|
||
@Autowired | ||
private FixityService fixityService; | ||
private final FixityService fixityService = new FixityService(); | ||
|
||
@Test | ||
@Ignore | ||
public void testQueueFixityCheck() throws Exception { | ||
fixityService.queueFixityCheck(Arrays.asList("/objects/testob1","/objects/testob2")); | ||
/* check that a JMS message is actually queued via the service's JmsTemplate */ | ||
JmsTemplate mockJms = mock(JmsTemplate.class); | ||
setField(fixityService, "fixityJmsTemplate", mockJms); | ||
|
||
fixityService.queueFixityCheck(Arrays.asList("/objects/testob1", | ||
"/objects/testob2")); | ||
verify(mockJms, times(2)).send(any(MessageCreator.class)); | ||
} | ||
|
||
@Test | ||
public void testConsumeFixityMessage() throws Exception { | ||
FedoraFixityClient mockClient = mock(FedoraFixityClient.class, Mockito.withSettings().verboseLogging()); | ||
|
||
setField(fixityService, "fixityClient", mockClient); | ||
|
||
fixityService.consumeFixityMessage("http://localhost:8080/objects/testobj1"); | ||
|
||
} | ||
|
||
private static void | ||
setField(FixityService service, String name, Object obj) | ||
throws Exception { | ||
Field f = FixityService.class.getDeclaredField(name); | ||
f.setAccessible(true); | ||
try { | ||
f.set(service, obj); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
File renamed without changes.