From 71fc497dd8163a36273d9dfecd2e250f92a33d08 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Mon, 13 Dec 2010 21:44:52 +0000 Subject: [PATCH] [LMS-1921] API tests SVN: 19112 --- .../server/logic/ScreeningApiImpl.java | 5 +- .../shared/api/v1/dto/WellIdentifier.java | 8 +- .../server/logic/ScreeningApiImplTest.java | 81 +++++++++++++++++++ .../api/v1/dto/PlateIdentifierTest.java | 42 ++++++++++ 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java index b2c3dd3e221..087a7d988de 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java @@ -381,7 +381,7 @@ public class ScreeningApiImpl { owner = new SampleOwnerIdentifier(DatabaseInstanceIdentifier.createHome()); } - return SampleIdentifier.createOwnedBy(owner, plate.getPermId()); + return SampleIdentifier.createOwnedBy(owner, plate.getPlateCode()); } private List<WellIdentifier> asWellIdentifiers(List<Sample> samples, @@ -406,8 +406,7 @@ public class ScreeningApiImpl { WellLocation location = ScreeningUtils.tryCreateLocationFromMatrixCoordinate(sample.getCode()); - return new WellIdentifier(plateIdentifier, sample.getPermId(), location.getRow(), - location.getColumn()); + return new WellIdentifier(plateIdentifier, sample.getPermId(), location); } public List<PlateWellMaterialMapping> listPlateMaterialMapping( diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/WellIdentifier.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/WellIdentifier.java index 3f3514a5b9e..13b5d34ed2a 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/WellIdentifier.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/WellIdentifier.java @@ -1,5 +1,7 @@ package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellLocation; + /** * Contains data which uniquely define a plate. * @@ -13,12 +15,12 @@ public class WellIdentifier extends PermanentIdentifier private final int row, col; - public WellIdentifier(PlateIdentifier plateIdentifier, String permId, int row, int col) + public WellIdentifier(PlateIdentifier plateIdentifier, String permId, WellLocation wellLocation) { super(permId); this.plateIdentifier = plateIdentifier; - this.row = row; - this.col = col; + this.row = wellLocation.getRow(); + this.col = wellLocation.getColumn(); } public PlateIdentifier getPlateIdentifier() diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImplTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImplTest.java index de32f76f815..7e773a92321 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImplTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImplTest.java @@ -44,12 +44,16 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; +import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory; import ch.systemsx.cisd.openbis.plugin.screening.server.IScreeningBusinessObjectFactory; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.Geometry; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateIdentifier; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellIdentifier; import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.ScreeningConstants; +import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellLocation; /** * @author Franz-Josef Elmer @@ -72,6 +76,83 @@ public class ScreeningApiImplTest extends AbstractServerTestCase screeningApi = new ScreeningApiImpl(SESSION, screeningBOFactory, daoFactory); } + @Test + public void testListPlateWellsFromAugmentedCode() + { + final String identifier = "/SPACE/PLATE"; + final PlateIdentifier pi = PlateIdentifier.createFromAugmentedCode(identifier); + context.checking(new Expectations() + { + { + one(screeningBOFactory).createSampleBO(SESSION); + will(returnValue(sampleBO)); + one(sampleBO).loadBySampleIdentifier(SampleIdentifierFactory.parse(identifier)); + one(sampleBO).getSample(); + SamplePE sample = new SamplePE(); + sample.setId(1L); + will(returnValue(sample)); + + one(screeningBOFactory).createSampleLister(SESSION); + will(returnValue(sampleLister)); + one(sampleLister).list(with(any(ListOrSearchSampleCriteria.class))); + Sample w1 = createWellSample("w1", "A01"); + Sample w2 = createWellSample("w2", "A02"); + will(returnValue(Arrays.asList(w1, w2))); + } + }); + + List<WellIdentifier> wells = screeningApi.listPlateWells(pi); + assertEquals(2, wells.size()); + assertEquals(wellIdentifier(pi, "w1", 1, 1), wells.get(0)); + assertEquals(wellIdentifier(pi, "w2", 1, 2), wells.get(1)); + context.assertIsSatisfied(); + } + + @Test + public void testListPlateWellsFromPermId() + { + final String permId = "PLATE_PERM_ID"; + final PlateIdentifier pi = PlateIdentifier.createFromPermId(permId); + context.checking(new Expectations() + { + { + one(screeningBOFactory).createSampleLister(SESSION); + will(returnValue(sampleLister)); + one(sampleLister).list(with(any(ListOrSearchSampleCriteria.class))); + Sample plate = new Sample(); + plate.setId(1L); + will(returnValue(Arrays.asList(plate))); + + one(screeningBOFactory).createSampleLister(SESSION); + will(returnValue(sampleLister)); + one(sampleLister).list(with(any(ListOrSearchSampleCriteria.class))); + Sample w1 = createWellSample("w1", "A01"); + Sample w2 = createWellSample("w2", "A02"); + will(returnValue(Arrays.asList(w1, w2))); + } + }); + + List<WellIdentifier> wells = screeningApi.listPlateWells(pi); + assertEquals(2, wells.size()); + assertEquals(wellIdentifier(pi, "w1", 1, 1), wells.get(0)); + assertEquals(wellIdentifier(pi, "w2", 1, 2), wells.get(1)); + context.assertIsSatisfied(); + } + + private static Sample createWellSample(String permId, String code) + { + Sample result = new Sample(); + result.setPermId(permId); + result.setCode(code); + return result; + } + + private static WellIdentifier wellIdentifier(PlateIdentifier plate, String wellPermId, int row, + int col) + { + return new WellIdentifier(plate, wellPermId, new WellLocation(row, col)); + } + @Test public void testListImageDatasets() { diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/PlateIdentifierTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/PlateIdentifierTest.java index de457c50fc0..94530a98ef4 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/PlateIdentifierTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/PlateIdentifierTest.java @@ -19,6 +19,8 @@ package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; import org.testng.AssertJUnit; import org.testng.annotations.Test; +import ch.systemsx.cisd.openbis.generic.shared.util.SpaceCodeHelper; + /** * @author Chandrasekhar Ramakrishnan */ @@ -61,4 +63,44 @@ public class PlateIdentifierTest extends AssertJUnit assertEquals(plateId1.hashCode(), plateId2.hashCode()); } + @Test + public void testCreate() + { + PlateIdentifier homePlate = PlateIdentifier.createFromAugmentedCode("PLATE"); + assertFalse(homePlate.isSharedPlate()); + assertTrue(SpaceCodeHelper.isHomeSpace(homePlate.tryGetSpaceCode())); + assertEquals(null, homePlate.tryGetSpaceCode()); + assertEquals("PLATE", homePlate.getPlateCode()); + assertEquals(null, homePlate.getPermId()); + + PlateIdentifier sharedPlate = PlateIdentifier.createFromAugmentedCode("/PLATE"); + assertTrue(sharedPlate.isSharedPlate()); + assertFalse(SpaceCodeHelper.isHomeSpace(sharedPlate.tryGetSpaceCode())); + assertEquals("", sharedPlate.tryGetSpaceCode()); + assertEquals("PLATE", sharedPlate.getPlateCode()); + assertEquals(null, sharedPlate.getPermId()); + + PlateIdentifier spacePlate = PlateIdentifier.createFromAugmentedCode("/SPACE/PLATE"); + assertFalse(spacePlate.isSharedPlate()); + assertFalse(SpaceCodeHelper.isHomeSpace(spacePlate.tryGetSpaceCode())); + assertEquals("SPACE", spacePlate.tryGetSpaceCode()); + assertEquals("PLATE", spacePlate.getPlateCode()); + assertEquals(null, spacePlate.getPermId()); + + try + { + PlateIdentifier.createFromAugmentedCode("/FAKE/PLATE/ID"); + } catch (IllegalArgumentException ex) + { + assertEquals("Augmented code '/FAKE/PLATE/ID' needs to be of the form " + + "'/SPACE/PLATE', '/PLATE' or 'PLATE'.", ex.getMessage()); + } + + PlateIdentifier plateWithPermId = PlateIdentifier.createFromPermId("PERM_ID"); + assertFalse(plateWithPermId.isSharedPlate()); + assertEquals(null, plateWithPermId.tryGetSpaceCode()); + assertEquals(null, plateWithPermId.getPlateCode()); + assertEquals("PERM_ID", plateWithPermId.getPermId()); + } + } -- GitLab