Skip to content

Commit

Permalink
added pure Junit test for FixityService
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed Jun 1, 2013
1 parent 1d2e977 commit 6799e02
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Expand Up @@ -72,10 +72,11 @@ public Message createMessage(Session session) throws JMSException {
});
}

/*
/**
* Consume a fixity message published to the JMS queue and act on fixity check requests
* @param uri the text of the {@link Message} which is supposed to be a object uri
*/
private void consumeFixityMessage(String uri) throws JMSException {
public void consumeFixityMessage(String uri) throws JMSException {
logger.debug("received fixity request for object {}", uri);
}

Expand Down
@@ -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();
}
}
}

0 comments on commit 6799e02

Please sign in to comment.