Exemplo n.º 1
0
  @Test
  public void test_transformThreeRowsOfComplexXML() throws Exception {
    String xml = TRIPLE_ROW_MULTIPLE_ORG;

    makeTsv(xml);
    psr.setKeepElderInfo(false);
    psr.setRowElementName("Site");

    ByteStreams.copy(inn, tsv);
    tsv.close();

    String result = new String(out.toByteArray());
    System.err.println(result);

    StringReader reader = new StringReader(result);
    LineReader lines = new LineReader(reader);
    String line;

    line = lines.readLine();
    assertTrue(line.startsWith("\"code\"\t\"agency\"\t\"Id\"\t\"level\"\t\"Type\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"01\"\t\"\"\t\"2172257\"\t\"admin\"\t\"water\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"02\"\t\"USGS2\"\t\"\"\t\"\"\t\"clay\""));

    line = lines.readLine();
    assertTrue(line.startsWith("\"03\"\t\"\"\t\"2172258\"\t\"user\"\t\"stream\""));
  }
Exemplo n.º 2
0
  void makeTsv(String xml) throws Exception {
    PostParser pp = new DefaultPostParser();

    out = new ByteArrayOutputStream(1000);
    tsv = new TsvOutputStream(out);
    psr = new DataRowParser(pp);
    tsv.setParser(psr);
    inn = new ByteArrayInputStream(xml.getBytes());
  }
Exemplo n.º 3
0
  @Test
  public void test_transformTwoRowsOfSimplerXML() throws Exception {
    String xml = "<get><Site>2172257</Site><Site>2172258</Site></get>";
    makeTsv(xml);

    ByteStreams.copy(inn, tsv);
    tsv.close();

    String result = new String(out.toByteArray());
    System.err.println(result);

    StringReader reader = new StringReader(result);
    LineReader lines = new LineReader(reader);
    String line;

    line = lines.readLine();
    assertEquals("\"Site\"", line);

    line = lines.readLine();
    assertEquals("\"2172257\"", line);

    line = lines.readLine();
    assertEquals("\"2172258\"", line);
  }