Skip to content

Commit

Permalink
Merge pull request #6342 from dominikl/loadfacility_tests
Browse files Browse the repository at this point in the history
Add tests for the LoadFacility
  • Loading branch information
jburel authored Mar 17, 2023
2 parents d0c5a03 + e7c445b commit 30d57e7
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private void initData() throws Exception {

this.user2Folder = createFolder(ctx);

this.wellsPlate = createPlateWithWells();
this.wellsPlate = createPlateWithWells(rootCtx, null);

this.wellIds = new ArrayList<Long>();
Plate p = this.wellsPlate.asPlate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import omero.gateway.facility.BrowseFacility;
import omero.gateway.facility.DataManagerFacility;
import omero.gateway.facility.Facility;
import omero.gateway.facility.LoadFacility;
import omero.gateway.facility.MetadataFacility;
import omero.gateway.facility.ROIFacility;
import omero.gateway.facility.RawDataFacility;
Expand Down Expand Up @@ -101,6 +102,7 @@ public class GatewayTest {
MetadataFacility metadataFacility = null;
ROIFacility roiFacility = null;
TablesFacility tablesFacility = null;
LoadFacility loadFacility = null;

@Test
public void testConnected() throws DSOutOfServiceException {
Expand Down Expand Up @@ -146,6 +148,7 @@ protected void setUp() throws Exception {
roiFacility = Facility.getFacility(ROIFacility.class,
gw);
tablesFacility = Facility.getFacility(TablesFacility.class, gw);
loadFacility = Facility.getFacility(LoadFacility.class, gw);
}

@AfterClass(alwaysRun = true)
Expand Down Expand Up @@ -220,10 +223,15 @@ PlateData createPlate(SecurityContext ctx, ScreenData screen)
return (PlateData) datamanagerFacility.saveAndReturnObject(ctx, plate);
}

PlateData createPlateWithWells() throws Exception {
ModelMockFactory mf = new ModelMockFactory(gw.getTypesService(rootCtx));
PlateData createPlateWithWells(SecurityContext ctx, ScreenData screen) throws Exception {
ModelMockFactory mf = new ModelMockFactory(gw.getTypesService(ctx));
PlateData p = new PlateData(mf.createPlate(3, 3, 2, 1, false));
return (PlateData) datamanagerFacility.saveAndReturnObject(rootCtx, p);
if (screen != null) {
Set<ScreenData> screens = new HashSet<ScreenData>(1);
screens.add(screen);
p.setScreens(screens);
}
return (PlateData) datamanagerFacility.saveAndReturnObject(ctx, p);
}

ImageData createImage(SecurityContext ctx, DatasetData ds)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2023 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package integration.gateway;

import omero.gateway.SecurityContext;
import omero.gateway.exception.DSAccessException;
import omero.gateway.exception.DSOutOfServiceException;
import omero.gateway.facility.BrowseFacility;
import omero.gateway.model.DatasetData;
import omero.gateway.model.ExperimenterData;
import omero.gateway.model.GroupData;
import omero.gateway.model.ImageData;
import omero.gateway.model.PlateData;
import omero.gateway.model.ProjectData;
import omero.gateway.model.ScreenData;
import omero.gateway.model.WellData;
import omero.model.Plate;
import omero.model.Well;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
*
* @author Dominik Lindner &nbsp;&nbsp;&nbsp;&nbsp; <a
* href="mailto:[email protected]">[email protected]</a>
*/

public class LoadFacilityTest extends GatewayTest {

private GroupData group;
private ExperimenterData user;
private SecurityContext ctx;

private ProjectData proj;
private DatasetData ds;
private ScreenData screen;
private PlateData plate;
private ImageData img;
private ArrayList<Long> wellIds;

@Override
@BeforeClass(alwaysRun = true)
protected void setUp() throws Exception {
super.setUp();
initData();
}

@Test
public void testGetDataset() throws DSOutOfServiceException, DSAccessException {
DatasetData obj = this.loadFacility.getDataset(this.ctx, this.ds.getId());
Assert.assertEquals(obj.getName(), this.ds.getName());
}

@Test
public void testGetImage() throws DSOutOfServiceException, DSAccessException {
ImageData obj = this.loadFacility.getImage(this.ctx, this.img.getId());
Assert.assertEquals(obj.getName(), this.img.getName());
}

@Test
public void testGetPlate() throws DSOutOfServiceException, DSAccessException {
PlateData obj = this.loadFacility.getPlate(this.ctx, this.plate.getId());
Assert.assertEquals(obj.getName(), this.plate.getName());
}

@Test
public void testGetProject() throws DSOutOfServiceException, DSAccessException {
ProjectData obj = this.loadFacility.getProject(this.ctx, this.proj.getId());
Assert.assertEquals(obj.getName(), this.proj.getName());
}

@Test
public void testGetScreen() throws DSOutOfServiceException, DSAccessException {
ScreenData obj = this.loadFacility.getScreen(this.ctx, this.screen.getId());
Assert.assertEquals(obj.getName(), this.screen.getName());
}

@Test
public void testGetWell() throws DSOutOfServiceException, DSAccessException {
WellData test = this.plate.getWells().iterator().next();
WellData obj = this.loadFacility.getWell(this.ctx, test.getId());
Assert.assertEquals(obj.getColumn(), test.getColumn());
Assert.assertEquals(obj.getRow(), test.getRow());
Assert.assertEquals(obj.getWellSamples().get(0).getImage().getId(),
test.getWellSamples().get(0).getImage().getId());
}

private void initData() throws Exception {
this.group = createGroup();
this.user = createExperimenter(group);
this.ctx = new SecurityContext(group.getId());

this.img = createImage(ctx, null);

this.proj = createProject(ctx);
this.ds = createDataset(ctx, null);
this.screen = createScreen(ctx);
this.plate = createPlateWithWells(ctx, screen);

this.wellIds = new ArrayList<Long>();
Plate p = this.plate.asPlate();
for (Well w : p.copyWells()) {
this.wellIds.add(w.getId().getValue());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testAddTable() throws Exception {
ImageData img = createImage();
ProjectData pr = createProject(rootCtx);
DatasetData dat = createDataset(rootCtx, pr);
PlateData plate = createPlateWithWells();
PlateData plate = createPlateWithWells(rootCtx, null);
ArrayList tmp = new ArrayList<ROIData>();
tmp.add(createRectangleROI(0, 0, 10, 10, img.getId()));
ROIData roi = (ROIData) roiFacility.saveROIs(rootCtx, img.getId(), tmp).iterator().next();
Expand Down

0 comments on commit 30d57e7

Please sign in to comment.