@Test public void testShouldRaiseExceptionEventWhenIndexIsMalformed() throws FileNotFoundException, CaseParserException { CaseTask task = new CaseTask(); List<IndexSubElement> subElements = new ArrayList<IndexSubElement>(); subElements.add(new IndexSubElement(null, null, null)); IndexTask indexTask = new IndexTask(subElements); task.setIndexTask(indexTask); ArgumentCaptor<MotechEvent> motechEventCaptor = ArgumentCaptor.forClass(MotechEvent.class); String xml = caseConverter.convertToCaseXml(task); verify(eventRelay).sendEventMessage(motechEventCaptor.capture()); MotechEvent motechEvent = motechEventCaptor.getValue(); Assert.assertEquals(motechEvent.getSubject(), EventSubjects.MALFORMED_CASE_EXCEPTION); Assert.assertNull(xml); }
@Test public void testNoIndexElementIncludedWhenNoIndices() throws FileNotFoundException, CaseParserException { CaseTask task = new CaseTask(); List<IndexSubElement> subElements = new ArrayList<IndexSubElement>(); IndexTask indexTask = new IndexTask(subElements); task.setIndexTask(indexTask); String xml = caseConverter.convertToCaseXml(task); Assert.assertFalse(xml.contains("index")); }
@Test public void testCorrectIndicesCaseXml() throws FileNotFoundException, CaseParserException { CaseTask task = new CaseTask(); List<IndexSubElement> subElements = new ArrayList<IndexSubElement>(); subElements.add(new IndexSubElement("caseId1", "type1", "indexNodeName1")); subElements.add(new IndexSubElement("caseId2", "type2", "indexNodeName2")); subElements.add(new IndexSubElement("caseId3", "type3", "indexNodeName3")); IndexTask indexTask = new IndexTask(subElements); task.setIndexTask(indexTask); String xml = caseConverter.convertToCaseXml(task); Assert.assertTrue(xml.contains("<indexNodeName1 case_type=\"type1\">caseId1</indexNodeName1>")); Assert.assertTrue(xml.contains("<indexNodeName2 case_type=\"type2\">caseId2</indexNodeName2>")); Assert.assertTrue(xml.contains("<indexNodeName3 case_type=\"type3\">caseId3</indexNodeName3>")); }