Package org.molgenis.util.tuple

Examples of org.molgenis.util.tuple.Tuple


  {
    TupleTable tupleTable = mock(TupleTable.class);
    Field field1 = when(mock(Field.class).getSqlName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getSqlName()).thenReturn("col2").getMock();
    when(tupleTable.getColumns()).thenReturn(Arrays.asList(field1, field2));
    Tuple row1 = mock(Tuple.class);
    when(row1.getNrCols()).thenReturn(2);
    when(row1.get("col1")).thenReturn("val1");
    when(row1.get("col2")).thenReturn("val2");
    when(row1.hasColNames()).thenReturn(true);
    when(row1.getColNames()).thenReturn(Arrays.asList("col1", "col2"));

    Tuple row2 = mock(Tuple.class);
    when(row2.getNrCols()).thenReturn(2);
    when(row2.get("col1")).thenReturn("val3");
    when(row2.get("col2")).thenReturn("val4");
    when(row2.hasColNames()).thenReturn(true);
    when(row2.getColNames()).thenReturn(Arrays.asList("col1", "col2"));
    when(tupleTable.iterator()).thenReturn(Arrays.asList(row1, row2).iterator());

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CsvExporter csvExporter = new CsvExporter(tupleTable);
    csvExporter.export(bos);
View Full Code Here


    when(tupleTable.getLimit()).thenReturn(2);

    Field field1 = when(mock(Field.class).getSqlName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getSqlName()).thenReturn("col2").getMock();
    when(tupleTable.getColumns()).thenReturn(Arrays.asList(field1, field2));
    Tuple row1 = mock(Tuple.class);
    when(row1.getNrCols()).thenReturn(2);
    when(row1.get("col1")).thenReturn("val1");
    when(row1.get("col2")).thenReturn("val2");
    when(row1.hasColNames()).thenReturn(true);
    when(row1.getColNames()).thenReturn(Arrays.asList("col1", "col2"));

    Tuple row2 = mock(Tuple.class);
    when(row2.getNrCols()).thenReturn(2);
    when(row2.get("col1")).thenReturn("val3");
    when(row2.get("col2")).thenReturn("val4");
    when(row2.hasColNames()).thenReturn(true);
    when(row2.getColNames()).thenReturn(Arrays.asList("col1", "col2"));
    when(tupleTable.iterator()).thenReturn(Arrays.asList(row1, row2).iterator());

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CsvExporter csvExporter = new CsvExporter(tupleTable);
    csvExporter.export(bos);
View Full Code Here

public class JdbcTableTest
{
  @Test
  public void testJDBCTable() throws SQLException, DatabaseException, TableException
  {
    Tuple tuple0 = mock(Tuple.class);
    when(tuple0.getColNames()).thenReturn(Arrays.asList("Name", "Continent")).getMock();
    when(tuple0.getString("Name")).thenReturn("Netherlands");

    Database db = mock(Database.class);
    String query = "SELECT Name, Continent FROM Country";
    QueryRule queryRule = new QueryRule("Code", Operator.EQUALS, "NLD");
    when(db.sql(query, queryRule)).thenReturn(Arrays.asList(tuple0));
View Full Code Here

        tuples.add(tuple);

      assertEquals(7, tuples.size());

      // test normal case
      Tuple tuple0 = tuples.get(0);
      assertEquals("a", tuple0.get(0));
      assertEquals("b", tuple0.get(1));
      assertEquals("c", tuple0.get(2));

      // test quoted commas
      Tuple tuple1 = tuples.get(1);
      assertEquals("a", tuple1.get(0));
      assertEquals("b,b,b", tuple1.get(1));
      assertEquals("c", tuple1.get(2));

      // test empty elements
      Tuple tuple2 = tuples.get(2);
      assertEquals(3, tuple2.getNrCols());

      // test multiline quoted
      Tuple tuple3 = tuples.get(3);
      assertEquals(3, tuple3.getNrCols());

      // test quoted quote chars
      Tuple tuple4 = tuples.get(4);
      assertEquals("Glen \"The Man\" Smith", tuple4.get(0));

      Tuple tuple5 = tuples.get(5);
      assertEquals("\"\"", tuple5.get(0)); // check the tricky
                          // situation
      assertEquals("test", tuple5.get(1)); // make sure we didn't
                          // ruin the next field..
      Tuple tuple6 = tuples.get(6);
      assertEquals(4, tuple6.getNrCols());
    }
    finally
    {
      csvReader.close();
    }
View Full Code Here

    CsvReader csvReader = new CsvReader(new StringReader(csvString));
    try
    {
      Iterator<Tuple> it = csvReader.iterator();
      assertTrue(it.hasNext());
      Tuple tuple = it.next();
      assertTrue(tuple.isNull("col1"));
    }
    finally
    {
      csvReader.close();
    }
View Full Code Here

  {
    CsvReader tsvReader = new CsvReader(new StringReader("col1\tcol2\nval1\tval2\n"), '\t');
    try
    {
      Iterator<Tuple> it = tsvReader.iterator();
      Tuple t0 = it.next();
      assertEquals(t0.get("col1"), "val1");
      assertEquals(t0.get("col2"), "val2");
      assertFalse(it.hasNext());
    }
    finally
    {
      tsvReader.close();
View Full Code Here

    ExcelReader excelReader = new ExcelReader(new ByteArrayInputStream(bos.toByteArray()), false);
    try
    {
      Iterator<Tuple> it = excelReader.getSheet("sheet").iterator();
      assertTrue(it.hasNext());
      Tuple tuple0 = it.next();
      assertEquals(tuple0.getString(0), "val1");
      assertEquals(tuple0.getString(1), "val2");
      assertEquals(tuple0.getString(2), "val3");
      assertTrue(it.hasNext());
      Tuple tuple1 = it.next();
      assertEquals(tuple1.getString(0), "val4");
      assertEquals(tuple1.getString(1), "val5");
      assertFalse(it.hasNext());
    }
    finally
    {
      excelReader.close();
View Full Code Here

      assertEquals(colNamesIt.next(), "col1");
      assertTrue(colNamesIt.hasNext());
      assertEquals(colNamesIt.next(), "col2");

      Iterator<Tuple> it = csvReader.iterator();
      Tuple t0 = it.next();
      assertEquals(t0.get("col1"), "val1");
      assertEquals(t0.get("col2"), "val2");
      assertFalse(it.hasNext());
    }
    finally
    {
      csvReader.close();
View Full Code Here

    ExcelReader excelReader = new ExcelReader(new ByteArrayInputStream(bos.toByteArray()), true);
    try
    {
      Iterator<Tuple> it = excelReader.getSheet("sheet").iterator();
      assertTrue(it.hasNext());
      Tuple tuple0 = it.next();
      assertEquals(tuple0.getString("col1"), "val1");
      assertEquals(tuple0.getString("col2"), "val2");
      assertTrue(it.hasNext());
      Tuple tuple1 = it.next();
      assertEquals(tuple1.getString("col1"), "val3");
      assertEquals(tuple1.getString("col2"), "val4");
      assertFalse(it.hasNext());
    }
    finally
    {
      excelReader.close();
View Full Code Here

      ExcelSheetReader sheetReader = excelReader.getSheet("Sheet1");
      try
      {
        Iterator<Tuple> it = sheetReader.iterator();
        assertTrue(it.hasNext());
        Tuple tuple1 = it.next();
        assertEquals(tuple1.getString("col1"), row1.getString("col1"));
        assertEquals(tuple1.getString("col2"), row1.getString("col2"));
        assertEquals(tuple1.getString("col3"), row1.getString("col3"));
        assertTrue(it.hasNext());
        Tuple tuple2 = it.next();
        assertEquals(tuple2.getString("col1"), row2.getString("col1"));
        assertEquals(tuple2.getString("col2"), row2.getString("col2"));
        assertEquals(tuple2.getString("col3"), row2.getString("col3"));
        assertFalse(it.hasNext());
      }
      finally
      {
        IOUtils.closeQuietly(sheetReader);
View Full Code Here

TOP

Related Classes of org.molgenis.util.tuple.Tuple

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.