Search in sources :

Example 1 with SystemNotice

use of org.codice.ddf.system.alerts.SystemNotice in project ddf by codice.

the class SolrAppenderTest method testHandleEventSizeBatching.

@Test
public void testHandleEventSizeBatching() throws Exception {
    SystemNotice notice = new SystemNotice();
    Event event = new Event("decanter/collect", notice.getProperties());
    solrAppender.setBatchSize(1);
    solrAppender.handleEvent(event);
    verify(persistentStore, never()).add(eq("decanter"), any(Collection.class));
    solrAppender.handleEvent(event);
    verify(persistentStore).add(eq("decanter"), any(Collection.class));
}
Also used : Event(org.osgi.service.event.Event) Collection(java.util.Collection) SystemNotice(org.codice.ddf.system.alerts.SystemNotice) Test(org.junit.Test)

Example 2 with SystemNotice

use of org.codice.ddf.system.alerts.SystemNotice in project ddf by codice.

the class CrlGenerator method postErrorEvent.

/**
 * Posts and error message to the Admin Console.
 *
 * @param errorMessage - The reason for the error.
 */
private void postErrorEvent(String errorMessage) {
    String title = "Unable to download the Certificate Revocation List (CRL) from " + crlLocationUrl;
    Set<String> details = new HashSet<>();
    details.add("The provided CRL could not be downloaded. Please check the provided URL and/or the contents of the given CRL.");
    details.add(errorMessage);
    details.add("To recover, resolve the issue and save the configuration.");
    eventAdmin.postEvent(new Event(SystemNotice.SYSTEM_NOTICE_BASE_TOPIC + "crl", new SystemNotice(this.getClass().getName(), NoticePriority.CRITICAL, title, details).getProperties()));
    securityLogger.audit(title);
    securityLogger.audit(errorMessage);
}
Also used : Event(org.osgi.service.event.Event) SystemNotice(org.codice.ddf.system.alerts.SystemNotice) HashSet(java.util.HashSet)

Example 3 with SystemNotice

use of org.codice.ddf.system.alerts.SystemNotice in project ddf by codice.

the class AlertListenerTest method testHandleEventExistingAlert.

@Test
public void testHandleEventExistingAlert() throws Exception {
    SystemNotice notice = new SystemNotice("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
    Map<String, Object> props = notice.getProperties();
    props.put("event.topics", "decanter/alert/test");
    Alert alert = new Alert(props);
    ArgumentCaptor<PersistentItem> captor = ArgumentCaptor.forClass(PersistentItem.class);
    Event event = new Event("decanter/alert/test", alert.getProperties());
    when(persistentStore.get(any(), any())).thenReturn(Collections.singletonList(toSolr(alert)));
    alertListener.handleEvent(event);
    verify(persistentStore).add(eq("alerts"), captor.capture());
    PersistentItem item = captor.getValue();
    assertThat(item.getLongProperty(Alert.ALERT_COUNT), equalTo(2L));
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem) Event(org.osgi.service.event.Event) Alert(org.codice.ddf.system.alerts.Alert) SystemNotice(org.codice.ddf.system.alerts.SystemNotice) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with SystemNotice

use of org.codice.ddf.system.alerts.SystemNotice in project ddf by codice.

the class AlertListenerTest method testHandleEventDismissNoDismissedBy.

@Test
public void testHandleEventDismissNoDismissedBy() throws Exception {
    SystemNotice alert = new SystemNotice("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
    ArgumentCaptor<PersistentItem> captor = ArgumentCaptor.forClass(PersistentItem.class);
    Map<String, String> dismissEvent = new HashMap<>();
    dismissEvent.put(Alert.SYSTEM_NOTICE_ID_KEY, alert.getId());
    Event event = new Event(Alert.ALERT_DISMISS_TOPIC, dismissEvent);
    when(persistentStore.get(any(), any())).thenReturn(Collections.singletonList(toSolr(alert)));
    alertListener.handleEvent(event);
    verify(persistentStore, never()).add(any(), any(PersistentItem.class));
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem) HashMap(java.util.HashMap) Event(org.osgi.service.event.Event) SystemNotice(org.codice.ddf.system.alerts.SystemNotice) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with SystemNotice

use of org.codice.ddf.system.alerts.SystemNotice in project ddf by codice.

the class AlertListenerTest method testHandleEventFirstAlert.

@Test
public void testHandleEventFirstAlert() throws Exception {
    SystemNotice notice = new SystemNotice("test-source", NoticePriority.IMPORTANT, "title", new HashSet());
    Map<String, Object> props = notice.getProperties();
    props.put("event.topics", "decanter/alert/test");
    Alert alert = new Alert(props);
    ArgumentCaptor<Event> captor = ArgumentCaptor.forClass(Event.class);
    Event event = new Event("decanter/alert/test", notice.getProperties());
    when(persistentStore.get(any(), any())).thenReturn(new ArrayList<>());
    alertListener.handleEvent(event);
    verify(persistentStore).add(eq("alerts"), any(PersistentItem.class));
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem) Event(org.osgi.service.event.Event) Alert(org.codice.ddf.system.alerts.Alert) SystemNotice(org.codice.ddf.system.alerts.SystemNotice) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SystemNotice (org.codice.ddf.system.alerts.SystemNotice)10 Event (org.osgi.service.event.Event)9 HashSet (java.util.HashSet)6 Test (org.junit.Test)5 PersistentItem (org.codice.ddf.persistence.PersistentItem)3 Collection (java.util.Collection)2 Alert (org.codice.ddf.system.alerts.Alert)2 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1 PaxLoggingEvent (org.ops4j.pax.logging.spi.PaxLoggingEvent)1