Skip to content

Commit

Permalink
AtomJMSIT.testDatastreamTerm() assumed messages were arriving in a pa…
Browse files Browse the repository at this point in the history
…rticular order,

(i.e. object node creation first, followed by datastream node creation).

Now explicitly calling session.save() after each node operation and then testing the message.

Alternatively, we could refactor this test to wait to collect both messages and then check the messages
for the expected content.
  • Loading branch information
Edwin Shin committed Jun 13, 2013
1 parent c5464e8 commit 90f0eda
Showing 1 changed file with 47 additions and 31 deletions.
Expand Up @@ -69,6 +69,24 @@ public class AtomJMSIT implements MessageListener {

final private Logger logger = LoggerFactory.getLogger(AtomJMSIT.class);

@Before
public void acquireConnection() throws JMSException {
logger.debug(this.getClass().getName() + " acquiring JMS connection.");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(session.createTopic("fedora"));
consumer.setMessageListener(this);
}

@After
public void releaseConnection() throws JMSException {
logger.debug(this.getClass().getName() + " releasing JMS connection.");
consumer.close();
session.close();
connection.close();
}

@Test
public void testAtomStream() throws LoginException, RepositoryException, InterruptedException {
Session session = repository.login();
Expand Down Expand Up @@ -98,44 +116,60 @@ public void testAtomStream() throws LoginException, RepositoryException, Interru
public void testDatastreamTerm() throws NoSuchNodeTypeException,
VersionException, ConstraintViolationException, LockException,
ItemExistsException, PathNotFoundException, RepositoryException, InterruptedException {
logger.trace("BEGIN: testDatastreamTerm()");
Session session = repository.login();
final Node object = session.getRootNode().addNode("test2");
final Node object = session.getRootNode().addNode("testDatastreamTerm");
object.addMixin(FEDORA_OBJECT);
final Node ds = object.addNode("DATASTREAM");
ds.addMixin(FEDORA_DATASTREAM);
ds.addNode(JCR_CONTENT).setProperty(JCR_DATA, "fake data");
session.save();
logger.trace("testDatastreamTerm called session.save()");

waitForEntry();

session.logout();
if (entry == null) fail("Waited a second, got no messages");

List<Category> categories = copyOf(entry.getCategories("xsd:string"));
//entry = null;
entry = null;

String path = null;
logger.debug("Matched {} categories with scheme xsd:string", categories

logger.trace("Matched {} categories with scheme xsd:string", categories
.size());
for (Category cat : categories) {
if (cat.getLabel().equals("fedora-types:dsID")) {
if (cat.getLabel().equals("fedora-types:pid")) {
logger.debug("Found Category with term: " + cat.getTerm());
path = cat.getTerm();
}
}
assertEquals("Got wrong object PID!", "testDatastreamTerm", path);

final Node ds = object.addNode("DATASTREAM");
ds.addMixin(FEDORA_DATASTREAM);
ds.addNode(JCR_CONTENT).setProperty(JCR_DATA, "fake data");
session.save();
logger.trace("testDatastreamTerm called session.save()");
session.logout();
logger.trace("testDatastreamTerm called session.logout()");

waitForEntry();
if (entry == null) fail("Waited a second, got no messages");
categories = copyOf(entry.getCategories("xsd:string"));
entry = null;
assertEquals("Got wrong datastream ID!", "DATASTREAM", path);

logger.trace("Matched {} categories with scheme xsd:string", categories
.size());
for (Category cat : categories) {
if (cat.getLabel().equals("fedora-types:pid")) {
if (cat.getLabel().equals("fedora-types:dsID")) {
logger.debug("Found Category with term: " + cat.getTerm());
path = cat.getTerm();
}
}
assertEquals("Got wrong object PID!", "test2", path);

assertEquals("Got wrong datastream ID!", "DATASTREAM", path);
logger.trace("END: testDatastreamTerm()");
}

@Override
public void onMessage(Message message) {
logger.debug("Received JMS message: " + message.toString());

TextMessage tMessage = (TextMessage) message;
try {
if (LegacyMethod.canParse(message)){
Expand All @@ -154,24 +188,6 @@ public void onMessage(Message message) {
}
}

@Before
public void acquireConnection() throws JMSException {
logger.debug(this.getClass().getName() + " acquiring JMS connection.");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(session.createTopic("fedora"));
consumer.setMessageListener(this);
}

@After
public void releaseConnection() throws JMSException {
logger.debug(this.getClass().getName() + " releasing JMS connection.");
consumer.close();
session.close();
connection.close();
}

private void waitForEntry() throws InterruptedException {
for(int i = 0; i < 5; i++) {
if (entry == null) { // must not have rec'vd event yet
Expand Down

0 comments on commit 90f0eda

Please sign in to comment.