@Test public void testMapWithIvalidXml() throws Exception { // given Configuration conf = new Configuration(); conf.set(NAMED_OUTPUT_META, "meta"); conf.set(NAMED_OUTPUT_FAULT, "fault"); doReturn(conf).when(context).getConfiguration(); mapper.setup(context); String id = "id"; DocumentText.Builder docTextBuilder = DocumentText.newBuilder(); docTextBuilder.setId(id); docTextBuilder.setText(getContent(NON_XML_FILE)); // execute mapper.map(new AvroKey<>(docTextBuilder.build()), null, context); // assert verify(context, never()).write(any(), any()); verify(multipleOutputs, times(2)).write(mosKeyCaptor.capture(), mosValueCaptor.capture()); // doc meta assertEquals(conf.get(NAMED_OUTPUT_META), mosKeyCaptor.getAllValues().get(0)); ExtractedDocumentMetadata docMeta = (ExtractedDocumentMetadata) mosValueCaptor.getAllValues().get(0).datum(); assertNotNull(docMeta); assertEquals(id, docMeta.getId()); assertEquals("", docMeta.getText()); assertEquals(JatsXmlHandler.ENTITY_TYPE_UNKNOWN, docMeta.getEntityType()); // fault assertEquals(conf.get(NAMED_OUTPUT_FAULT), mosKeyCaptor.getAllValues().get(1)); Fault fault = (Fault) mosValueCaptor.getAllValues().get(1).datum(); assertNotNull(fault); assertEquals(id, fault.getInputObjectId()); assertEquals(JDOMParseException.class.getName(), fault.getCode()); assertTrue(fault.getTimestamp() > 0); }
@Override public NATO4676Message readNext( final InputStream is ) { NATO4676Message msg = null; try { if (printNotParse) { final String trackStr = IOUtils.toString( is, "UTF-8"); is.reset(); } else { final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(is); final Element rootEl = doc.getRootElement(); final Namespace xmlns = rootEl.getNamespace(); String name = rootEl.getName(); if ("TrackMessage".equals(name)) { msg = readTrackMessage( rootEl, xmlns); LOGGER.info("TrackMessage read " + trackStatsNumTracks + " Tracks and " + trackStatsNumDots + " TrackPoints."); } else if ("MissionSummary".equals(name)) { msg = readMissionSummaryMessage( rootEl, xmlns); } } } catch (final JDOMParseException jdomPe) { LOGGER.info( "jdomParseException: " + jdomPe.getLocalizedMessage(), jdomPe); return null; } catch (final IOException ioe) { LOGGER.info( "IO exception: " + ioe.getLocalizedMessage(), ioe); return null; } catch (final JDOMException jdome) { LOGGER.info( "jdomException: " + jdome.getLocalizedMessage(), jdome); return null; } return msg; }
/** * Returns the line number of the end of the text where the * parse error occurred. * <p> * The first line in the document is line 1.</p> * * @return an integer representing the line number, or -1 * if the information is not available. */ public int getLineNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getLineNumber(): -1; }
/** * Returns the column number of the end of the text where the * parse error occurred. * <p> * The first column in a line is position 1.</p> * * @return an integer representing the column number, or -1 * if the information is not available. */ public int getColumnNumber() { return (getCause() instanceof JDOMParseException)? ((JDOMParseException)getCause()).getColumnNumber(): -1; }