Search in sources :

Example 26 with PersistenceException

use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.

the class AlertListener method addAlertToStore.

private void addAlertToStore(Alert alert) {
    PersistentItem item = new PersistentItem();
    alert.getProperties().forEach((name, value) -> item.addProperty(name, value));
    try {
        persistentStore.add(CORE_NAME, item);
    } catch (PersistenceException e) {
        LOGGER.error("Failed to persist alert.");
    }
}
Also used : PersistentItem(org.codice.ddf.persistence.PersistentItem) PersistenceException(org.codice.ddf.persistence.PersistenceException)

Example 27 with PersistenceException

use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.

the class StoreCommandTest method testPersistenceException.

/**
 * Check for listing command.
 */
@Test
public void testPersistenceException() throws PersistenceException {
    // given
    when(persistentStore.get(anyString(), any(), eq(0), anyInt())).thenThrow(new PersistenceException());
    StoreListCommand command = new StoreListCommand();
    command.persistentStore = persistentStore;
    command.type = "preferences";
    command.execute();
    // then
    assertThat(consoleOutput.getOutput(), containsString("Encountered an error when"));
}
Also used : PersistenceException(org.codice.ddf.persistence.PersistenceException) Test(org.junit.Test)

Example 28 with PersistenceException

use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.

the class AdminAlertImplTest method testGetAlertsPersistentStoreError.

@Test
public void testGetAlertsPersistentStoreError() throws Exception {
    when(persistentStore.get(eq("alerts"), any())).thenThrow(new PersistenceException("error"));
    List<Map<String, Object>> alertList = adminAlert.getAlerts();
    assertThat(alertList.size(), equalTo(1));
    assertThat(alertList.get(0).get(Alert.SYSTEM_NOTICE_SOURCE_KEY), equalTo("unable_to_retrieve_alerts"));
}
Also used : PersistenceException(org.codice.ddf.persistence.PersistenceException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

PersistenceException (org.codice.ddf.persistence.PersistenceException)28 Map (java.util.Map)16 PersistentItem (org.codice.ddf.persistence.PersistentItem)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 SolrServerException (org.apache.solr.client.solrj.SolrServerException)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 List (java.util.List)4 Listener (org.cometd.annotation.Listener)4 Date (java.util.Date)3 SolrClient (org.apache.solr.client.solrj.SolrClient)3 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)3 PersistentStore (org.codice.ddf.persistence.PersistentStore)3 Subject (ddf.security.Subject)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2