Search in sources :

Example 6 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class UploadTableTest method testReferenceTable.

@Test
public void testReferenceTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final GenericTable table = new DefaultGenericTable();
    final OMERORefColumn rc0 = new OMERORefColumn(OMERORef.WELL);
    final OMERORefColumn rc1 = new OMERORefColumn(OMERORef.WELL);
    final OMERORefColumn rc2 = new OMERORefColumn(OMERORef.WELL);
    rc0.fill(new long[] { 2314, 3141324, 1235 });
    rc1.fill(new long[] { 1234, 18367, 82156 });
    rc2.fill(new long[] { 3198, 968431, 5489 });
    table.add(rc0);
    table.add(rc1);
    table.add(rc2);
    final Object[][] wells = new Object[3][3];
    for (int c = 0; c < table.getColumnCount(); c++) {
        for (int r = 0; r < table.getRowCount(); r++) {
            wells[c][r] = new WellSampleData(new WellSampleI((long) table.get(c, r), false));
        }
        ((OMERORefColumn) table.get(c)).setOriginalData(wells[c]);
    }
    // Create expectations
    setUpMethodCalls();
    final long id = service.uploadTable(credentials, "table", table, 0);
    assertEquals(id, -1);
    // NB: Can only capture in a Verifications block
    new Verifications() {

        {
            TableData td;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
            tableEquals(table, td, WellSampleData.class);
        }
    };
}
Also used : DefaultGenericTable(net.imagej.table.DefaultGenericTable) WellSampleData(omero.gateway.model.WellSampleData) GenericTable(net.imagej.table.GenericTable) DefaultGenericTable(net.imagej.table.DefaultGenericTable) DataObject(omero.gateway.model.DataObject) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) WellSampleI(omero.model.WellSampleI) Test(org.junit.Test)

Example 7 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class DownloadTableTest method downloadLongTable.

@Test
public void downloadLongTable() throws PermissionDeniedException, CannotCreateSessionException, ServerError, DSOutOfServiceException, ExecutionException, DSAccessException {
    // Setup OMERO data structures
    final TableDataColumn[] tdc = new TableDataColumn[] { new TableDataColumn("Header 1", 0, Long.class), new TableDataColumn("Header 2", 1, Long.class), new TableDataColumn("Header 3", 2, Long.class), new TableDataColumn("Header 4", 3, Long.class) };
    final Object[][] data = new Object[4][];
    data[0] = new Long[] { 0l, -9223372036854775808l, 9223372036854775807l };
    data[1] = new Long[] { 134l, 5415145l, 4775807l };
    data[2] = new Long[] { -1898l, -97234l, 75807l };
    data[3] = new Long[] { 19048l, -123l, 4l };
    final TableData table = new TableData(tdc, data);
    table.setNumberOfRows(3);
    // Create expectations
    setUpMethodCalls(table);
    final Table<?, ?> imageJTable = ((DefaultOMEROService) service).downloadTable(credentials, 0);
    // Tests
    assertTrue(LongTable.class.isInstance(imageJTable));
    assertEquals(imageJTable.getColumnCount(), 4);
    assertEquals(imageJTable.getRowCount(), 3);
    assertEquals(imageJTable.getColumnHeader(0), "Header 1");
    assertEquals(imageJTable.getColumnHeader(1), "Header 2");
    assertEquals(imageJTable.getColumnHeader(2), "Header 3");
    assertEquals(imageJTable.getColumnHeader(3), "Header 4");
    for (int r = 0; r < imageJTable.getRowCount(); r++) {
        for (int c = 0; c < imageJTable.getColumnCount(); c++) {
            assertEquals(data[c][r], imageJTable.get(c, r));
        }
    }
}
Also used : LongTable(net.imagej.table.LongTable) TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Example 8 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class DownloadTableTest method downloadMixedTable.

@Test
@SuppressWarnings("unchecked")
public void downloadMixedTable() throws PermissionDeniedException, CannotCreateSessionException, ServerError, DSOutOfServiceException, ExecutionException, DSAccessException {
    // / Setup OMERO data structures
    final TableDataColumn[] tdc = new TableDataColumn[] { new TableDataColumn("Header 1", 0, String.class), new TableDataColumn("Header 2", 1, Boolean.class), new TableDataColumn("Header 3", 2, Double[].class), new TableDataColumn("Header 4", 3, Long.class) };
    final Object[][] data = new Object[4][];
    data[0] = new String[] { "abc", "123", "hi!" };
    data[1] = new Boolean[] { false, true, false };
    data[2] = new Double[][] { { 0.125, 3879123.5, -93.25 }, { 0d, -123353.03125, -5.5 }, { 100.25, 0.125, -9000.5 } };
    data[3] = new Long[] { -9028131908l, 0l, 12l };
    final TableData table = new TableData(tdc, data);
    table.setNumberOfRows(3);
    // Create expectations
    setUpMethodCalls(table);
    final Table<?, ?> imageJTable = ((DefaultOMEROService) service).downloadTable(credentials, 0);
    // Tests
    assertTrue(GenericTable.class.isInstance(imageJTable));
    assertTrue(DefaultColumn.class.isInstance(imageJTable.get(0)));
    assertTrue(imageJTable.get(0).getType() == String.class);
    assertTrue(BoolColumn.class.isInstance(imageJTable.get(1)));
    assertTrue(DefaultColumn.class.isInstance(imageJTable.get(2)));
    assertTrue(imageJTable.get(2).getType() == DoubleArray.class);
    assertTrue(LongColumn.class.isInstance(imageJTable.get(3)));
    assertEquals(imageJTable.getColumnCount(), 4);
    assertEquals(imageJTable.getRowCount(), 3);
    assertEquals(imageJTable.getColumnHeader(0), "Header 1");
    assertEquals(imageJTable.getColumnHeader(1), "Header 2");
    assertEquals(imageJTable.getColumnHeader(2), "Header 3");
    assertEquals(imageJTable.getColumnHeader(3), "Header 4");
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[0][r], ((DefaultColumn<String>) imageJTable.get(0)).get(r));
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[1][r], ((BoolColumn) imageJTable.get(1)).getValue(r));
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertArrayEquals((Double[]) data[2][r], ((DefaultColumn<DoubleArray>) imageJTable.get(2)).get(r).toArray());
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[3][r], ((LongColumn) imageJTable.get(3)).getValue(r));
}
Also used : BoolColumn(net.imagej.table.BoolColumn) DefaultColumn(net.imagej.table.DefaultColumn) GenericTable(net.imagej.table.GenericTable) LongColumn(net.imagej.table.LongColumn) TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData) DoubleArray(org.scijava.util.DoubleArray) Test(org.junit.Test)

Example 9 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class DownloadTableTest method downloadDoubleTable.

@Test
public void downloadDoubleTable() throws PermissionDeniedException, CannotCreateSessionException, ServerError, DSOutOfServiceException, ExecutionException, DSAccessException {
    // Setup OMERO data structures
    final TableDataColumn[] tdc = new TableDataColumn[] { new TableDataColumn("Header 1", 0, Double.class), new TableDataColumn("Header 2", 1, Double.class) };
    final Object[][] data = new Object[2][];
    data[0] = new Double[] { 0.125, -0.5, 923014712408917.25, -241.03125, 0.0 };
    data[1] = new Double[] { 1002.125, 908082.5, 59871249.0625, -7.25, 4.5 };
    final TableData table = new TableData(tdc, data);
    table.setNumberOfRows(5);
    // Create expectations
    setUpMethodCalls(table);
    final Table<?, ?> imageJTable = ((DefaultOMEROService) service).downloadTable(credentials, 0);
    // Tests
    assertTrue(ResultsTable.class.isInstance(imageJTable));
    assertEquals(imageJTable.getColumnCount(), 2);
    assertEquals(imageJTable.getRowCount(), 5);
    assertEquals(imageJTable.getColumnHeader(0), "Header 1");
    assertEquals(imageJTable.getColumnHeader(1), "Header 2");
    for (int r = 0; r < imageJTable.getRowCount(); r++) {
        for (int c = 0; c < imageJTable.getColumnCount(); c++) {
            assertEquals((double) data[c][r], ((ResultsTable) imageJTable).get(c, r), 0);
        }
    }
}
Also used : ResultsTable(net.imagej.table.ResultsTable) TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Example 10 with TableData

use of omero.gateway.model.TableData in project imagej-omero by imagej.

the class OmeroIT method testUploadTable.

@Test
public void testUploadTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final byte[][] d = new byte[][] { { 127, 0, -128 }, { -1, -6, -23 }, { 100, 87, 4 } };
    final ByteTable table = new DefaultByteTable(3, 3);
    for (int c = 0; c < table.getColumnCount(); c++) {
        table.setColumnHeader(c, "Heading " + (c + 1));
        for (int r = 0; r < table.getRowCount(); r++) table.set(c, r, d[c][r]);
    }
    final long tableId = omero.uploadTable(cred, "test-table-upload", table, 1);
    // When upload table was called it created a session, which cleared out
    // the username and password from the credentials. The credentials must
    // have a username and password to create security contexts.
    final OMEROCredentials tc = new OMEROCredentials();
    tc.setServer(OMERO_SERVER);
    tc.setPort(OMERO_PORT);
    tc.setUser(OMERO_USER);
    tc.setPassword(OMERO_PASSWORD);
    try (final OMEROSession session = new DefaultOMEROSession(tc)) {
        final TablesFacility tablesFacility = session.getGateway().getFacility(TablesFacility.class);
        final TableData td = tablesFacility.getTableInfo(session.getSecurityContext(), tableId);
        assertEquals(td.getColumns().length, 3);
        assertEquals(td.getColumns()[0].getName(), "Heading 1");
        assertEquals(td.getColumns()[1].getName(), "Heading 2");
        assertEquals(td.getColumns()[2].getName(), "Heading 3");
        assertEquals(td.getNumberOfRows(), 3);
    }
}
Also used : TablesFacility(omero.gateway.facility.TablesFacility) DefaultByteTable(net.imagej.table.DefaultByteTable) DefaultOMEROSession(net.imagej.omero.DefaultOMEROSession) ByteTable(net.imagej.table.ByteTable) DefaultByteTable(net.imagej.table.DefaultByteTable) OMEROSession(net.imagej.omero.OMEROSession) DefaultOMEROSession(net.imagej.omero.DefaultOMEROSession) TableData(omero.gateway.model.TableData) OMEROCredentials(net.imagej.omero.OMEROCredentials) Test(org.junit.Test)

Aggregations

TableData (omero.gateway.model.TableData)23 Test (org.junit.Test)17 Verifications (mockit.Verifications)9 GenericTable (net.imagej.table.GenericTable)9 TableDataColumn (omero.gateway.model.TableDataColumn)9 DefaultColumn (net.imagej.table.DefaultColumn)6 DefaultGenericTable (net.imagej.table.DefaultGenericTable)4 TablesFacility (omero.gateway.facility.TablesFacility)4 ImageData (omero.gateway.model.ImageData)3 BoolColumn (net.imagej.table.BoolColumn)2 BoolTable (net.imagej.table.BoolTable)2 LongTable (net.imagej.table.LongTable)2 DataObject (omero.gateway.model.DataObject)2 DoubleArray (org.scijava.util.DoubleArray)2 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 DefaultOMEROSession (net.imagej.omero.DefaultOMEROSession)1 OMEROCredentials (net.imagej.omero.OMEROCredentials)1 OMEROSession (net.imagej.omero.OMEROSession)1 ByteTable (net.imagej.table.ByteTable)1