@Test public void testAddMetaAlertToAlertEmpty() { Map<String, Object> alertFields = new HashMap<>(); alertFields.put(METAALERT_FIELD, new ArrayList<>()); Document alert = new Document(alertFields, "alert", "test", 0L); Document expected = new Document(new HashMap<>(), "alert", "test", 0L); List<String> expectedMetaAlertGuids = new ArrayList<>(); expectedMetaAlertGuids.add("metaalert1"); expected.getDocument().put(METAALERT_FIELD, expectedMetaAlertGuids); boolean actual = dao.addMetaAlertToAlert("metaalert1", alert); assertTrue(actual); assertEquals(expected, alert); }
@Test public void testAddMetaAlertToAlertNonEmpty() { List<String> metaAlertGuids = new ArrayList<>(); metaAlertGuids.add("metaalert1"); Map<String, Object> alertFields = new HashMap<>(); alertFields.put(METAALERT_FIELD, metaAlertGuids); Document alert = new Document(alertFields, "alert", "test", 0L); Document expected = new Document(new HashMap<>(), "alert", "test", 0L); List<String> expectedMetaAlertGuids = new ArrayList<>(); expectedMetaAlertGuids.add("metaalert1"); expectedMetaAlertGuids.add("metaalert2"); expected.getDocument().put(METAALERT_FIELD, expectedMetaAlertGuids); boolean actual = dao.addMetaAlertToAlert("metaalert2", alert); assertTrue(actual); assertEquals(expected, alert); }
@Test public void testAddMetaAlertToAlertDuplicate() { List<String> metaAlertGuids = new ArrayList<>(); metaAlertGuids.add("metaalert1"); Map<String, Object> alertFields = new HashMap<>(); alertFields.put(METAALERT_FIELD, metaAlertGuids); Document alert = new Document(alertFields, "alert", "test", 0L); boolean actual = dao.addMetaAlertToAlert("metaalert1", alert); assertFalse(actual); }