Changeset 7670


Ignore:
Timestamp:
Mar 21, 2019, 1:34:37 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2161: Import data from Excel files

Extended the TestAnnotationFlatFileImporter and TestFlatFileParser with test cases that read data from Excel.

Location:
trunk/src/test
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/test/TestAnnotation.java

    r7340 r7670  
    2424
    2525import net.sf.basedb.core.*;
     26import net.sf.basedb.core.Annotation.Source;
    2627import net.sf.basedb.core.snapshot.AnnotationSnapshot;
    2728import net.sf.basedb.core.snapshot.AnnotationTypeFilter;
     
    338339    }
    339340  }
     341 
     342  static void test_remove_all_annotations(Item itemType, int itemId)
     343  {
     344    if (itemId == 0 ) return;
     345    DbControl dc = null;
     346    try
     347    {
     348      dc = TestUtil.getDbControl();
     349      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
     350      AnnotationSet as = annotatable.getAnnotationSet();
     351      for (Annotation a : as.getAnnotations(Source.PRIMARY).list(dc))
     352      {
     353        as.removeAnnotation(a.getAnnotationType());
     354      }
     355      dc.commit();
     356      write("--Remove all annotations OK");
     357    }
     358    catch (Throwable ex)
     359    {
     360      write("--Remove all annotations FAILED");
     361      ex.printStackTrace();
     362      ok = false;
     363    }
     364    finally
     365    {
     366      if (dc != null) dc.close();
     367    }
     368  }
    340369
    341370  static void test_list_annotations(Item itemType, int itemId, Annotation.Source source, int expectedResults)
  • trunk/src/test/TestAnnotationFlatFileImporter.java

    r7592 r7670  
    8181   
    8282    int fileId = TestFile.test_create("data/test.annotation.import.txt", false, false);
     83    int excelFileId = TestFile.test_create("data/test.annotation.import.xlsx", false, false);
    8384   
    8485    // Create job
     
    104105    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    105106
     107    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sample1);
     108    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sample2);
     109    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sample3);
     110    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sample4);
     111    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sampleDup1);
     112    TestAnnotation.test_remove_all_annotations(Item.SAMPLE, sampleDup2);
     113
     114    // One more time to check import from Excel file
     115    int jobId3 = test_create_job(pluginDefinitionId, excelFileId, timeId, ageId, enumId, timestampId, commentId, commentId);
     116    ok &= TestJob.test_execute(jobId3, false);
     117   
     118    TestAnnotation.test_list_annotations(Item.SAMPLE, sample1, Annotation.Source.PRIMARY, 5);
     119    TestAnnotation.test_list_annotations(Item.SAMPLE, sample2, Annotation.Source.PRIMARY, 4);
     120    TestAnnotation.test_list_annotations(Item.SAMPLE, sample3, Annotation.Source.PRIMARY, 3);
     121    TestAnnotation.test_list_annotations(Item.SAMPLE, sample4, Annotation.Source.PRIMARY, 3);
     122    TestAnnotation.test_list_annotations(Item.SAMPLE, sampleDup1, Annotation.Source.PRIMARY, 5);
     123    TestAnnotation.test_list_annotations(Item.SAMPLE, sampleDup2, Annotation.Source.PRIMARY, 5);
     124    ok &= TestAnnotation.ok;
     125   
     126    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     127   
    106128    TestJob.test_delete(jobId);
    107129    TestJob.test_delete(jobId2);
     130    TestJob.test_delete(jobId3);
    108131    TestFile.test_delete(fileId);
     132    TestFile.test_delete(excelFileId);
    109133    TestSample.test_delete(sample1);
    110134    TestSample.test_delete(sample2);
  • trunk/src/test/TestFlatFileParser.java

    r7666 r7670  
    7070    test_parse_section(ffp, "data/test.parse.printmap.mwbr");
    7171
     72    ffp = test_create(null, "Name\\t.*", null, "\\t", "#.*", null, 20, 0, 10);
     73    test_parse(ffp, "data/test.annotation.import.xlsx", "\\Name\\", "\\Time (hours)\\", "\\Age (years)\\", "\\Timestamp\\", "\\Comment #1\\", "\\Comment #2\\");
     74   
    7275    write("++Testing file parser " + (ok ? "OK" : "Failed") + "\n");
    7376    return ok;
Note: See TracChangeset for help on using the changeset viewer.