Skip to content

Commit

Permalink
Non-rdf resources emit events without fcr:content references
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles authored and Andrew Woods committed Oct 23, 2014
1 parent 5dd9a1a commit f388cd7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.fcrepo.jms.headers;

import static org.fcrepo.kernel.RdfLexicon.REPOSITORY_NAMESPACE;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Set;
Expand Down Expand Up @@ -94,7 +95,11 @@ public Message getMessage(final FedoraEvent jcrEvent,

final Message message = jmsSession.createMessage();
message.setLongProperty(TIMESTAMP_HEADER_NAME, jcrEvent.getDate());
message.setStringProperty(IDENTIFIER_HEADER_NAME, jcrEvent.getPath());
String path = jcrEvent.getPath();
if ( path.endsWith("/" + JCR_CONTENT) ) {
path = path.replaceAll("/" + JCR_CONTENT,"");
}
message.setStringProperty(IDENTIFIER_HEADER_NAME, path);
message.setStringProperty(EVENT_TYPE_HEADER_NAME, getEventURIs( jcrEvent
.getTypes()));
message.setStringProperty(BASE_URL_HEADER_NAME, baseURL);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;

import java.util.Set;

Expand Down Expand Up @@ -67,15 +68,25 @@ public void setUp() throws JMSException {

@Test
public void testBuildMessage() throws RepositoryException, JMSException {
doTestBuildMessage("base-url");
final String testPath = "/path/to/resource";
final Message msg = doTestBuildMessage("base-url", testPath);
assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME));
}

@Test
public void testBuildMessageNullUrl() throws RepositoryException, JMSException {
doTestBuildMessage(null);
final String testPath = "/path/to/resource";
final Message msg = doTestBuildMessage(null, testPath);
assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME));
}
@Test
public void testBuildMessageContent() throws RepositoryException, JMSException {
final String testPath = "/path/to/resource";
final Message msg = doTestBuildMessage("base-url", testPath + "/" + JCR_CONTENT);
assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME));
}

private void doTestBuildMessage(final String baseUrl) throws RepositoryException, JMSException {
private Message doTestBuildMessage(final String baseUrl, final String id) throws RepositoryException, JMSException {
final Long testDate = 46647758568747L;
when(mockEvent.getDate()).thenReturn(testDate);

Expand All @@ -84,8 +95,7 @@ private void doTestBuildMessage(final String baseUrl) throws RepositoryException
url = "{\"baseURL\":\"" + baseUrl + "\"}";
}
when(mockEvent.getUserData()).thenReturn(url);
final String testPath = "super/calli/fragi/listic";
when(mockEvent.getPath()).thenReturn(testPath);
when(mockEvent.getPath()).thenReturn(id);
final Set<Integer> testTypes = singleton(NODE_ADDED);
final String testReturnType = REPOSITORY_NAMESPACE + EventType.valueOf(NODE_ADDED).toString();
when(mockEvent.getTypes()).thenReturn(testTypes);
Expand All @@ -94,10 +104,10 @@ private void doTestBuildMessage(final String baseUrl) throws RepositoryException

final Message msg = testDefaultMessageFactory.getMessage(mockEvent, mockSession);
assertEquals("Got wrong date in message!", testDate, (Long) msg.getLongProperty(TIMESTAMP_HEADER_NAME));
assertEquals("Got wrong identifier in message!", testPath, msg.getStringProperty(IDENTIFIER_HEADER_NAME));
assertEquals("Got wrong type in message!", testReturnType, msg.getStringProperty(EVENT_TYPE_HEADER_NAME));
assertEquals("Got wrong base-url in message", baseUrl, msg.getStringProperty(BASE_URL_HEADER_NAME));
assertEquals("Got wrong property in message", prop, msg.getStringProperty(PROPERTIES_HEADER_NAME));
return msg;
}

}

0 comments on commit f388cd7

Please sign in to comment.