Changeset 6209


Ignore:
Timestamp:
05/03/10 05:34:40 (10 years ago)
Author:
callan
Message:

Moved test cases to a mock based foundation.

Location:
trunk/components/ome-xml/test/ome/xml/utests
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/ome-xml/test/ome/xml/utests/InOut201004Test.java

    r6196 r6209  
    3838import java.io.OutputStreamWriter; 
    3939import java.io.UnsupportedEncodingException; 
     40import java.lang.reflect.Constructor; 
     41import java.lang.reflect.InvocationTargetException; 
    4042import java.util.List; 
    4143import java.util.Map; 
     
    101103 
    102104import org.testng.annotations.BeforeClass; 
     105import org.testng.annotations.BeforeMethod; 
     106import org.testng.annotations.Parameters; 
    103107import org.testng.annotations.Test; 
    104108import org.w3c.dom.Document; 
     
    111115 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/ome-xml/test/ome/xml/utests/InOut201004Test.java">SVN</a></dd></dl> 
    112116 */ 
     117@Test(groups={"inOutTests"}) 
    113118public class InOut201004Test { 
    114   private static String IMAGE_ID = "Image:0"; 
    115  
    116   private static String IMAGE_ANNOTATION_ID = "Annotation:Boolean0"; 
    117  
    118   private static String PIXELS_ID = "Pixels:0"; 
    119  
    120   private static String PIXELS_ANNOTATION_ID = "Annotation:Double0"; 
    121  
    122   private static String CHANNEL_ANNOTATION_ID = "Annotation:XML0"; 
    123  
    124   private static String INSTRUMENT_ID = "Instrument:0"; 
    125  
    126   private static String DETECTOR_ID = "Detector:0"; 
    127  
    128   private static String LIGHTSOURCE_ID = "LightSource:0"; 
    129  
    130   private static String DICHROIC_ID = "Dichroic:0"; 
    131  
    132   private static String FILTERSET_ID = "FilterSet:0"; 
    133  
    134   private static String EM_FILTER_ID = "Filter:0"; 
    135  
    136   private static String EX_FILTER_ID = "Filter:1"; 
    137  
    138   private static String OBJECTIVE_ID = "Objective:0"; 
    139  
    140   private static String OTF_ID = "OTF:0"; 
    141  
    142   private static String PLATE_ID = "Plate:0"; 
    143  
    144   private static String PLATE_ANNOTATION_ID = "Annotation:Timestamp0"; 
    145  
    146   private static String WELL_ANNOTATION_ID = "Annotation:Long0"; 
    147  
    148   private static String ROI_ID = "ROI:5"; 
    149  
    150   private static String ROI_ANNOTATION_ID = "Annotation:String0"; 
    151  
    152   private static String SHAPE_ID = "Shape:0"; 
    153  
    154   private static DimensionOrder DIMENSION_ORDER = DimensionOrder.XYZCT; 
    155  
    156   private static PixelType PIXEL_TYPE = PixelType.UINT16; 
    157  
    158   private static final Integer SIZE_X = 512; 
    159  
    160   private static final Integer SIZE_Y = 512; 
    161  
    162   private static final Integer SIZE_Z = 64; 
    163  
    164   private static final Integer SIZE_C = 3; 
    165  
    166   private static final Integer SIZE_T = 50; 
    167  
    168   private static final String DETECTOR_MODEL = "ReallySensitive!"; 
    169  
    170   private static final String LIGHTSOURCE_MODEL = "ReallyBright!"; 
    171  
    172   private static final String OBJECTIVE_MODEL = "ReallyClear!"; 
    173  
    174   private static final String DICHROIC_SN = "0123456789"; 
    175  
    176   private static final String FILTERSET_LOT = "RandomLot"; 
    177  
    178   private static final FilterType EM_FILTER_TYPE = FilterType.LONGPASS; 
    179  
    180   private static final FilterType EX_FILTER_TYPE = FilterType.NEUTRALDENSITY; 
    181  
    182   private static final PixelType OTF_PIXELTYPE = PixelType.FLOAT; 
    183  
    184   private static final Double LIGHTSOURCE_POWER = 1000.0; 
    185  
    186   private static final LaserType LASER_TYPE = LaserType.DYE; 
    187  
    188   private static final Integer OTF_SIZE_X = 512; 
    189  
    190   private static final Integer OTF_SIZE_Y = 512; 
    191  
    192   private static final Boolean OTF_OPTICAL_AXIS_AVERAGED = Boolean.FALSE; 
    193  
    194   private static final Boolean IMAGE_ANNOTATION_VALUE = Boolean.FALSE; 
    195  
    196   private static final String CHANNEL_ANNOTATION_VALUE = 
     119  public static final String IMAGE_ID = "Image:0"; 
     120 
     121  public static final String IMAGE_ANNOTATION_ID = "Annotation:Boolean0"; 
     122 
     123  public static final String PIXELS_ID = "Pixels:0"; 
     124 
     125  public static final String PIXELS_ANNOTATION_ID = "Annotation:Double0"; 
     126 
     127  public static final String CHANNEL_ANNOTATION_ID = "Annotation:XML0"; 
     128 
     129  public static final String INSTRUMENT_ID = "Instrument:0"; 
     130 
     131  public static final String DETECTOR_ID = "Detector:0"; 
     132 
     133  public static final String LIGHTSOURCE_ID = "LightSource:0"; 
     134 
     135  public static final String DICHROIC_ID = "Dichroic:0"; 
     136 
     137  public static final String FILTERSET_ID = "FilterSet:0"; 
     138 
     139  public static final String EM_FILTER_ID = "Filter:0"; 
     140 
     141  public static final String EX_FILTER_ID = "Filter:1"; 
     142 
     143  public static final String OBJECTIVE_ID = "Objective:0"; 
     144 
     145  public static final String OTF_ID = "OTF:0"; 
     146 
     147  public static final String PLATE_ID = "Plate:0"; 
     148 
     149  public static final String PLATE_ANNOTATION_ID = "Annotation:Timestamp0"; 
     150 
     151  public static final String WELL_ANNOTATION_ID = "Annotation:Long0"; 
     152 
     153  public static final String ROI_ID = "ROI:5"; 
     154 
     155  public static final String ROI_ANNOTATION_ID = "Annotation:String0"; 
     156 
     157  public static final String SHAPE_ID = "Shape:0"; 
     158 
     159  public static final DimensionOrder DIMENSION_ORDER = DimensionOrder.XYZCT; 
     160 
     161  public static final PixelType PIXEL_TYPE = PixelType.UINT16; 
     162 
     163  public static final Integer SIZE_X = 512; 
     164 
     165  public static final Integer SIZE_Y = 512; 
     166 
     167  public static final Integer SIZE_Z = 64; 
     168 
     169  public static final Integer SIZE_C = 3; 
     170 
     171  public static final Integer SIZE_T = 50; 
     172 
     173  public static final String DETECTOR_MODEL = "ReallySensitive!"; 
     174 
     175  public static final String LIGHTSOURCE_MODEL = "ReallyBright!"; 
     176 
     177  public static final String OBJECTIVE_MODEL = "ReallyClear!"; 
     178 
     179  public static final String DICHROIC_SN = "0123456789"; 
     180 
     181  public static final String FILTERSET_LOT = "RandomLot"; 
     182 
     183  public static final FilterType EM_FILTER_TYPE = FilterType.LONGPASS; 
     184 
     185  public static final FilterType EX_FILTER_TYPE = FilterType.NEUTRALDENSITY; 
     186 
     187  public static final PixelType OTF_PIXELTYPE = PixelType.FLOAT; 
     188 
     189  public static final Double LIGHTSOURCE_POWER = 1000.0; 
     190 
     191  public static final LaserType LASER_TYPE = LaserType.DYE; 
     192 
     193  public static final Integer OTF_SIZE_X = 512; 
     194 
     195  public static final Integer OTF_SIZE_Y = 512; 
     196 
     197  public static final Boolean OTF_OPTICAL_AXIS_AVERAGED = Boolean.FALSE; 
     198 
     199  public static final Boolean IMAGE_ANNOTATION_VALUE = Boolean.FALSE; 
     200 
     201  public static final String CHANNEL_ANNOTATION_VALUE = 
    197202  "<TestData><key>foo</key><value>bar</value></TestData>"; 
    198203 
    199   private static final Double PIXELS_ANNOTATION_VALUE = 3.14; 
    200  
    201   private static final String PLATE_ANNOTATION_VALUE = "1970-01-01T00:00:00"; 
    202  
    203   private static final Long WELL_ANNOTATION_VALUE = 262144L; 
    204  
    205   private static final Integer WELL_ROWS = 3; 
    206  
    207   private static final Integer WELL_COLS = 2; 
    208  
    209   private static final NamingConvention WELL_ROW = NamingConvention.LETTER; 
    210  
    211   private static final NamingConvention WELL_COL = NamingConvention.NUMBER; 
    212  
    213   private static final String ROI_ANNOTATION_VALUE = "Some extra ROI data"; 
    214  
    215   private static final Double RECTANGLE_X = 10.0; 
    216  
    217   private static final Double RECTANGLE_Y = 20.0; 
    218  
    219   private static final Double RECTANGLE_WIDTH = 128.0; 
    220  
    221   private static final Double RECTANGLE_HEIGHT = 256.0; 
    222  
    223   private static final String OTF_BINARY_FILE_NAME = "abc.bin"; 
    224  
    225   private static final Integer OTF_BINARY_FILE_SIZE = 64; 
    226  
    227   private static final String OTF_BINARY_FILE_EXTERNAL_HREF = "file:///abc.bin"; 
    228  
    229   private static final String OTF_BINARY_FILE_EXTERNAL_SHA1 = 
     204  public static final Double PIXELS_ANNOTATION_VALUE = 3.14; 
     205 
     206  public static final String PLATE_ANNOTATION_VALUE = "1970-01-01T00:00:00"; 
     207 
     208  public static final Long WELL_ANNOTATION_VALUE = 262144L; 
     209 
     210  public static final Integer WELL_ROWS = 3; 
     211 
     212  public static final Integer WELL_COLS = 2; 
     213 
     214  public static final NamingConvention WELL_ROW = NamingConvention.LETTER; 
     215 
     216  public static final NamingConvention WELL_COL = NamingConvention.NUMBER; 
     217 
     218  public static final String ROI_ANNOTATION_VALUE = "Some extra ROI data"; 
     219 
     220  public static final Double RECTANGLE_X = 10.0; 
     221 
     222  public static final Double RECTANGLE_Y = 20.0; 
     223 
     224  public static final Double RECTANGLE_WIDTH = 128.0; 
     225 
     226  public static final Double RECTANGLE_HEIGHT = 256.0; 
     227 
     228  public static final String OTF_BINARY_FILE_NAME = "abc.bin"; 
     229 
     230  public static final Integer OTF_BINARY_FILE_SIZE = 64; 
     231 
     232  public static final String OTF_BINARY_FILE_EXTERNAL_HREF = "file:///abc.bin"; 
     233 
     234  public static final String OTF_BINARY_FILE_EXTERNAL_SHA1 = 
    230235    "1234567890123456789012345678901234567890"; 
    231236 
     
    246251  public String asString; 
    247252 
     253  public OMEModelMock mock; 
     254 
    248255  public OME ome; 
    249256 
    250   public StructuredAnnotations annotations; 
    251  
    252257  public OMEModel model; 
    253258 
     259  @Parameters({"mockClassName"}) 
    254260  @BeforeClass 
    255   public void setUp() 
    256   throws ParserConfigurationException, TransformerException, UnsupportedEncodingException { 
     261  public void setUp(String mockClassName) throws Exception { 
     262    Class mockClass = Class.forName(mockClassName); 
     263    Constructor constructor = mockClass.getDeclaredConstructor(); 
     264    mock = (OMEModelMock) constructor.newInstance(); 
    257265    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    258266    DocumentBuilder parser = factory.newDocumentBuilder(); 
    259267    document = parser.newDocument(); 
    260     // Put <Image/> under <OME/> 
    261     ome = new OME(); 
    262     annotations = new StructuredAnnotations(); 
    263     ome.addImage(makeImage()); 
    264     ome.addPlate(makePlate()); 
    265     ome.addInstrument(makeInstrument()); 
    266     ome.addROI(makeROI()); 
    267     ome.setStructuredAnnotations(annotations); 
     268    ome = mock.getRoot(); 
    268269    // Produce a valid OME DOM element hierarchy 
    269270    Element root = ome.asXMLElement(document); 
     
    550551  } 
    551552 
    552   private Image makeImage() { 
    553     // Create <Image/> 
    554     Image image = new Image(); 
    555     image.setID(IMAGE_ID); 
    556     BooleanAnnotation annotation = new BooleanAnnotation(); 
    557     annotation.setID(IMAGE_ANNOTATION_ID); 
    558     annotation.setValue(IMAGE_ANNOTATION_VALUE); 
    559     image.linkAnnotation(annotation); 
    560     annotations.addBooleanAnnotation(annotation); 
    561     // Create <Pixels/> 
    562     Pixels pixels = new Pixels(); 
    563     pixels.setID(PIXELS_ID); 
    564     pixels.setSizeX(new PositiveInteger(SIZE_X)); 
    565     pixels.setSizeY(new PositiveInteger(SIZE_Y)); 
    566     pixels.setSizeZ(new PositiveInteger(SIZE_Z)); 
    567     pixels.setSizeC(new PositiveInteger(SIZE_C)); 
    568     pixels.setSizeT(new PositiveInteger(SIZE_T)); 
    569     pixels.setDimensionOrder(DIMENSION_ORDER); 
    570     pixels.setType(PIXEL_TYPE); 
    571     pixels.setMetadataOnly(new MetadataOnly()); 
    572     // Create <Channel/> under <Pixels/> 
    573     for (int i = 0; i < SIZE_C; i++) { 
    574       Channel channel = new Channel(); 
    575       channel.setID("Channel:" + i); 
    576       if (i == 0) { 
    577         XMLAnnotation channelAnnotation = new XMLAnnotation(); 
    578         channelAnnotation.setID(CHANNEL_ANNOTATION_ID); 
    579         channelAnnotation.setValue(CHANNEL_ANNOTATION_VALUE); 
    580         channel.linkAnnotation(channelAnnotation); 
    581         annotations.addXMLAnnotation(channelAnnotation); 
    582       } 
    583       pixels.addChannel(channel); 
    584     } 
    585     // create Annotation for Pixels 
    586     DoubleAnnotation pixelsAnnotation = new DoubleAnnotation(); 
    587     pixelsAnnotation.setID(PIXELS_ANNOTATION_ID); 
    588     pixelsAnnotation.setValue(PIXELS_ANNOTATION_VALUE); 
    589     pixels.linkAnnotation(pixelsAnnotation); 
    590     annotations.addDoubleAnnotation(pixelsAnnotation); 
    591     // Put <Pixels/> under <Image/> 
    592     image.setPixels(pixels); 
    593     return image; 
    594   } 
    595  
    596   private Instrument makeInstrument() { 
    597     // Create <Instrument/> 
    598     Instrument instrument = new Instrument(); 
    599     instrument.setID(INSTRUMENT_ID); 
    600     // Create <Detector/> under <Instrument/> 
    601     Detector detector = new Detector(); 
    602     detector.setID(DETECTOR_ID); 
    603     detector.setModel(DETECTOR_MODEL); 
    604     instrument.addDetector(detector); 
    605     // Create <Laser/> under <Instrument/> 
    606     Laser laser = new Laser(); 
    607     laser.setID(LIGHTSOURCE_ID); 
    608     laser.setModel(LIGHTSOURCE_MODEL); 
    609     laser.setType(LASER_TYPE); 
    610     laser.setPower(LIGHTSOURCE_POWER); 
    611     instrument.addLightSource(laser); 
    612  
    613     // Create <Dichroic/> under <Instrument/> 
    614     Dichroic dichroic = new Dichroic(); 
    615     dichroic.setID(DICHROIC_ID); 
    616     dichroic.setSerialNumber(DICHROIC_SN); 
    617     // Create <FilterSet/> under <Dichroic/> 
    618     FilterSet filterSet = new FilterSet(); 
    619     filterSet.setID(FILTERSET_ID); 
    620     filterSet.setLotNumber(FILTERSET_LOT); 
    621     filterSet.linkDichroic(dichroic); 
    622  
    623     Filter emFilter = new Filter(); 
    624     Filter exFilter = new Filter(); 
    625     OTF otf = new OTF(); 
    626     // Create <Objective/> under <Instrument/> 
    627     Objective objective = new Objective(); 
    628     objective.setID(OBJECTIVE_ID); 
    629     objective.setModel(OBJECTIVE_MODEL); 
    630  
    631     emFilter.setID(EM_FILTER_ID); 
    632     emFilter.setType(EM_FILTER_TYPE); 
    633     exFilter.setID(EX_FILTER_ID); 
    634     exFilter.setType(EX_FILTER_TYPE); 
    635     otf.setID(OTF_ID); 
    636     otf.setType(OTF_PIXELTYPE); 
    637     otf.setSizeX(new PositiveInteger(OTF_SIZE_X)); 
    638     otf.setSizeY(new PositiveInteger(OTF_SIZE_Y)); 
    639     otf.setOpticalAxisAveraged(OTF_OPTICAL_AXIS_AVERAGED); 
    640     // Create <ObjectiveSettings/> under <OTF/> 
    641     ObjectiveSettings otfObjectiveSettings = new ObjectiveSettings(); 
    642     otfObjectiveSettings.setID(objective.getID()); 
    643     otf.setObjectiveSettings(otfObjectiveSettings); 
    644     // Create <BinaryFile/> under <OTF/> 
    645     BinaryFile otfBinaryFile = new BinaryFile(); 
    646     otfBinaryFile.setFileName(OTF_BINARY_FILE_NAME); 
    647     otfBinaryFile.setSize(OTF_BINARY_FILE_SIZE); 
    648     External otfBinaryFileExternal = new External(); 
    649     otfBinaryFileExternal.sethref(OTF_BINARY_FILE_EXTERNAL_HREF); 
    650     otfBinaryFileExternal.setSHA1(OTF_BINARY_FILE_EXTERNAL_SHA1); 
    651     otfBinaryFile.setExternal(otfBinaryFileExternal); 
    652     otf.setBinaryFile(otfBinaryFile); 
    653     otf.linkFilterSet(filterSet); 
    654  
    655     instrument.addFilter(emFilter); 
    656     instrument.addFilter(exFilter); 
    657     instrument.addOTF(otf); 
    658     instrument.addObjective(objective); 
    659  
    660     filterSet.linkEmissionFilter(emFilter); 
    661     filterSet.linkExcitationFilter(exFilter); 
    662     filterSet.linkDichroic(dichroic); 
    663     instrument.addFilterSet(filterSet); 
    664     instrument.addDichroic(dichroic); 
    665  
    666     // link Instrument to the first Image 
    667     Image image = ome.getImage(0); 
    668     image.linkInstrument(instrument); 
    669  
    670     return instrument; 
    671   } 
    672  
    673   private Plate makePlate() { 
    674     Plate plate = new Plate(); 
    675     plate.setID(PLATE_ID); 
    676     plate.setRows(WELL_ROWS); 
    677     plate.setColumns(WELL_COLS); 
    678     plate.setRowNamingConvention(WELL_ROW); 
    679     plate.setColumnNamingConvention(WELL_COL); 
    680  
    681     TimestampAnnotation plateAnnotation = new TimestampAnnotation(); 
    682     plateAnnotation.setID(PLATE_ANNOTATION_ID); 
    683     plateAnnotation.setValue(PLATE_ANNOTATION_VALUE); 
    684     plate.linkAnnotation(plateAnnotation); 
    685     annotations.addTimestampAnnotation(plateAnnotation); 
    686  
    687     int wellSampleIndex = 0; 
    688     for (int row=0; row<WELL_ROWS; row++) { 
    689       for (int col=0; col<WELL_COLS; col++) { 
    690         Well well = new Well(); 
    691         well.setID(String.format("Well:%d_%d", row, col)); 
    692         well.setRow(new NonNegativeInteger(row)); 
    693         well.setColumn(new NonNegativeInteger(col)); 
    694  
    695         if (row == 0 && col == 0) { 
    696           LongAnnotation annotation = new LongAnnotation(); 
    697           annotation.setID(WELL_ANNOTATION_ID); 
    698           annotation.setValue(WELL_ANNOTATION_VALUE); 
    699           well.linkAnnotation(annotation); 
    700           annotations.addLongAnnotation(annotation); 
    701         } 
    702  
    703         WellSample sample = new WellSample(); 
    704         sample.setID(String.format("WellSample:%d_%d", row, col)); 
    705         sample.setIndex(new NonNegativeInteger(wellSampleIndex)); 
    706         sample.linkImage(ome.getImage(0)); 
    707         well.addWellSample(sample); 
    708         plate.addWell(well); 
    709         wellSampleIndex++; 
    710       } 
    711     } 
    712  
    713     return plate; 
    714   } 
    715  
    716   private ROI makeROI() { 
    717     ROI roi = new ROI(); 
    718     roi.setID(ROI_ID); 
    719  
    720     StringAnnotation roiAnnotation = new StringAnnotation(); 
    721     roiAnnotation.setID(ROI_ANNOTATION_ID); 
    722     roiAnnotation.setValue(ROI_ANNOTATION_VALUE); 
    723     roi.linkAnnotation(roiAnnotation); 
    724     annotations.addStringAnnotation(roiAnnotation); 
    725  
    726     Union shapeUnion = new Union(); 
    727     Rectangle rect = new Rectangle(); 
    728     rect.setID(SHAPE_ID); 
    729     rect.setX(RECTANGLE_X); 
    730     rect.setY(RECTANGLE_Y); 
    731     rect.setWidth(RECTANGLE_WIDTH); 
    732     rect.setHeight(RECTANGLE_HEIGHT); 
    733  
    734     shapeUnion.addShape(rect); 
    735     roi.setUnion(shapeUnion); 
    736  
    737     return roi; 
    738   } 
    739  
    740553  private String asString() 
    741554  throws TransformerException, UnsupportedEncodingException { 
     
    754567  } 
    755568 
     569  @Test(groups={"disabled"}) 
    756570  public static void main(String[] args) throws Exception { 
    757571    InOut201004Test t = new InOut201004Test(); 
    758     t.setUp(); 
     572    t.setUp("ome.xml.utests.ObjectBasedOMEModelMock"); 
    759573    System.out.println("###\n### XML\n###"); 
    760574    System.out.println(t.asString); 
  • trunk/components/ome-xml/test/ome/xml/utests/testng.xml

    r6143 r6209  
    11<suite name="OMEXMLTests"> 
    2     <test name="2010-04Schema"> 
    3         <groups/> 
     2    <test name="2010-04SchemaPrimitives"> 
     3        <groups> 
     4            <run> 
     5                <exclude name="inOutTests"/> 
     6            </run> 
     7        </groups> 
    48        <packages> 
    59            <package name="ome.xml.utests"/> 
    610        </packages> 
    711    </test> 
     12    <test name="2010-04Schema"> 
     13        <groups> 
     14            <run> 
     15                <exclude name="disabled"/> 
     16            </run> 
     17        </groups>        <parameter name="mockClassName" 
     18                   value="ome.xml.utests.ObjectBasedOMEModelMock"/> 
     19        <classes> 
     20            <class name="ome.xml.utests.InOut201004Test"/> 
     21        </classes> 
     22    </test> 
    823</suite> 
Note: See TracChangeset for help on using the changeset viewer.