Package org.molgenis.framework.tupletable

Examples of org.molgenis.framework.tupletable.TupleTable


    String query = "SELECT Name, Continent FROM Country";
    QueryRule queryRule = new QueryRule("Code", Operator.EQUALS, "NLD");
    when(db.sql(query, queryRule)).thenReturn(Arrays.asList(tuple0));
    when(db.sql("SELECT COUNT(*) FROM Country", queryRule)).thenReturn(Arrays.asList(tuple0));

    TupleTable jdbcTable = new JdbcTable(db, query, Arrays.asList(queryRule));
    try
    {
      // check columns
      Assert.assertEquals(jdbcTable.getColumns().get(0).getName(), "Name");
      Assert.assertEquals(jdbcTable.getColumns().get(1).getName(), "Continent");

      // check rows
      int i = 1;
      for (Tuple row : jdbcTable)
      {
        Assert.assertEquals(row.getString("Name"), "Netherlands");

        i = i + 1;
      }
    }
    finally
    {
      jdbcTable.close();
    }
  }
View Full Code Here


{

  @Test
  public void test1() throws TableException
  {
    TupleTable table = MemoryTableFactory.create(5, 5);

    // check columns
    Assert.assertEquals("col1", table.getColumns().get(0).getName());
    Assert.assertEquals("col2", table.getColumns().get(1).getName());

    // check rows
    Assert.assertEquals(5, table.getRows().size());

    // check iterator
    int i = 1;
    for (Tuple row : table)
    {
View Full Code Here

  }

  @Test
  public void testLimitOffset() throws TableException
  {
    TupleTable table = MemoryTableFactory.create(5, 5);

    table.setLimitOffset(2, 3);

    // limit == 2
    Assert.assertEquals(table.getRows().size(), 2);

    // offset = 3, so we skip first1-first3 and expect first4
    Assert.assertEquals(table.getRows().get(0).getString("col1"), "val1,4");

    // remove filters again
    table.setLimitOffset(0, 0);
  }
View Full Code Here

  }

  @Test
  public void testColLimitOffset() throws TableException
  {
    TupleTable table = MemoryTableFactory.create(5, 5);

    table.setColLimit(2);
    table.setColOffset(1);

    // limit == 1
    int i = 1;
    for (Tuple row : table.getRows())
    {
      Assert.assertEquals(row.getNrCols(), 2);
      Assert.assertEquals(row.get("col2"), "val2," + i);
      Assert.assertEquals(row.get("col3"), "val3," + i);
      ++i;
    }

    // remove filters again
    table.setColLimit(0);
    table.setColOffset(0);
  }
View Full Code Here

  }

  @Test
  public void export() throws TableException, IOException
  {
    TupleTable tableModel = mock(TupleTable.class);
    Field field1 = when(mock(Field.class).getName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getName()).thenReturn("col2").getMock();
    Field field3 = when(mock(Field.class).getName()).thenReturn("col3").getMock();
    when(tableModel.getColumns()).thenReturn(Arrays.asList(field1, field2, field3));
    WritableTuple row1 = new KeyValueTuple();
    row1.set("col1", "val1.1");
    row1.set("col2", "val1.2");
    row1.set("col3", "val1.3");
    WritableTuple row2 = new KeyValueTuple();
    row2.set("col1", "val2.1");
    row2.set("col2", "val2.2");
    row2.set("col3", "val2.3");
    when(tableModel.iterator()).thenReturn(Arrays.<Tuple> asList(row1, row2).iterator());

    ExcelExporter excelExporter = new ExcelExporter(tableModel);
    File xlsFile = File.createTempFile("table", ".xls");
    try
    {
View Full Code Here

  }

  @Test
  public void export_offsetsLimits() throws TableException, IOException
  {
    TupleTable tableModel = mock(TupleTable.class);
    when(tableModel.getColOffset()).thenReturn(2);
    when(tableModel.getColLimit()).thenReturn(3);
    when(tableModel.getOffset()).thenReturn(1);
    when(tableModel.getLimit()).thenReturn(2);

    // verify that offsets and limits are ignored during export
    Field field1 = when(mock(Field.class).getName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getName()).thenReturn("col2").getMock();
    Field field3 = when(mock(Field.class).getName()).thenReturn("col3").getMock();
    when(tableModel.getColumns()).thenReturn(Arrays.asList(field1, field2, field3));
    WritableTuple row1 = new KeyValueTuple();
    row1.set("col1", "val1.1");
    row1.set("col2", "val1.2");
    row1.set("col3", "val1.3");
    WritableTuple row2 = new KeyValueTuple();
    row2.set("col1", "val2.1");
    row2.set("col2", "val2.2");
    row2.set("col3", "val2.3");
    when(tableModel.iterator()).thenReturn(Arrays.<Tuple> asList(row1, row2).iterator());

    ExcelExporter excelExporter = new ExcelExporter(tableModel);
    File xlsFile = File.createTempFile("table", ".xls");
    try
    {
View Full Code Here

  }

  @Test
  public void testCsvTableString() throws Exception
  {
    TupleTable table = new CsvTable(csvString);
    testTable(table);
  }
View Full Code Here

    String csv = "firstName,lastName";
    csv += "\nlucky,luke";
    csv += "\ncalamity,jane";
    csv += "\njolly,jumper";

    TupleTable table = new CsvTable(csv);

    table.setLimitOffset(1, 1);

    assertEquals(table.getCount(), 3);

    assertEquals(table.getRows().size(), 1);

    assertEquals(table.getRows().get(0).getString("firstName"), "calamity");
  }
View Full Code Here

      FileUtils.write(file, csvString, Charset.forName("UTF-8"));
      CsvTable csvTable = new CsvTable(file);
      testTable(csvTable);

      TupleTable table = new CsvTable(file);

      table.setLimitOffset(1, 1);

      assertEquals(table.getCount(), 3);

      assertEquals(table.getRows().size(), 1);

      assertEquals(table.getRows().get(0).getString("firstName"), "calamity");

    }
    finally
    {
      file.delete();
View Full Code Here

  }

  @Test
  public void export() throws IOException, TableException
  {
    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);
    String csvString = new String(bos.toByteArray(), Charset.forName("UTF-8"));
View Full Code Here

TOP

Related Classes of org.molgenis.framework.tupletable.TupleTable

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.