use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContextualQuerySpecialMatch.
@Test
public void testContextualQuerySpecialMatch() throws IOException {
for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Predicate predicate = getPredicate("\"" + phrase + "\"");
Event testEvent = getEvent(metadata);
assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
}
}
}
use of org.osgi.service.event.Event in project ddf by codice.
the class PredicateTest method testContextualQuerySurroundedByWildcards.
@Test
public void testContextualQuerySurroundedByWildcards() throws Exception {
Predicate predicate = getPredicate("*test*");
for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
String phrase = String.format(term, specialChar);
String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
Event testEvent = getEvent(metadata);
assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
}
}
}
use of org.osgi.service.event.Event in project ddf by codice.
the class ActivityControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId.
/**
* Test method for {@link ActivityController#handleEvent(org.osgi.service.event.Event)}
*
* Verifies that {@code IllegalArgumentException} is thrown when
* {@code Event}'s {@link ActivityEvent#USER_ID_KEY} and
* {@link ActivityEvent#SESSION_ID_KEY} properties are empty.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId() {
testEventProperties.put(ActivityEvent.USER_ID_KEY, "");
testEventProperties.put(ActivityEvent.SESSION_ID_KEY, "");
activityController.handleEvent(new Event(ActivityEvent.EVENT_TOPIC, testEventProperties));
}
use of org.osgi.service.event.Event in project ddf by codice.
the class ActivityControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyMessage.
/**
* Test method for {@link ActivityController#handleEvent(org.osgi.service.event.Event)}
*
* Verifies that {@code IllegalArgumentException} is thrown when
* {@code Event}'s {@link ActivityEvent#MESSAGE_KEY} property is
* empty.
*/
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyMessage() {
testEventProperties.put(ActivityEvent.MESSAGE_KEY, "");
activityController.handleEvent(new Event(ActivityEvent.EVENT_TOPIC, testEventProperties));
}
use of org.osgi.service.event.Event in project ddf by codice.
the class NotificationController method getPersistedNotifications.
@Listener('/' + Notification.NOTIFICATION_TOPIC_ROOT)
public void getPersistedNotifications(final ServerSession remote, Message message) {
Subject subject = null;
try {
subject = SecurityUtils.getSubject();
} catch (Exception e) {
LOGGER.debug("Couldn't grab user subject from Shiro.", e);
}
String userId = getUserId(remote, subject);
if (null == userId) {
throw new IllegalArgumentException("User ID is null");
}
Map<String, Object> data = message.getDataAsMap();
if (MapUtils.isEmpty(data)) {
List<Map<String, Object>> notifications = getNotificationsForUser(userId);
if (CollectionUtils.isNotEmpty(notifications)) {
queuePersistedMessages(remote, notifications, "/" + Notification.NOTIFICATION_TOPIC_BROADCAST);
}
} else {
String id = UUID.randomUUID().toString().replaceAll("-", "");
String sessionId = remote.getId();
Notification notification = new Notification(id, sessionId, (String) data.get(Notification.NOTIFICATION_KEY_APPLICATION), (String) data.get(Notification.NOTIFICATION_KEY_TITLE), (String) data.get(Notification.NOTIFICATION_KEY_MESSAGE), (Long) data.get(Notification.NOTIFICATION_KEY_TIMESTAMP), userId);
Event event = new Event(Notification.NOTIFICATION_TOPIC_PUBLISH, notification);
eventAdmin.postEvent(event);
}
}
Aggregations