Changeset 6430


Ignore:
Timestamp:
Mar 10, 2014, 11:16:36 AM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #1784: Add support for logging old values

Extending the test case with updating some properties of a sample and making sure that log entries are created.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/log/db/DbLogManagerFactory.java

    r6420 r6430  
    3737import net.sf.basedb.core.log.LogManager;
    3838import net.sf.basedb.core.log.LogManagerFactory;
     39import net.sf.basedb.core.log.db.AnnotationLogger;
     40import net.sf.basedb.core.log.db.AnnotationSetLogger;
     41import net.sf.basedb.core.log.db.AnyToAnyLogger;
     42import net.sf.basedb.core.log.db.BioMaterialEventLogger;
     43import net.sf.basedb.core.log.db.DefaultEntityLogger;
     44import net.sf.basedb.core.log.db.FileSetMemberLogger;
     45import net.sf.basedb.core.log.db.PlateEventLogger;
    3946import net.sf.basedb.util.extensions.ActionFactory;
    4047import net.sf.basedb.util.extensions.InvokationContext;
     
    6067  public DbLogManagerFactory()
    6168  {
     69    this(Config.getBoolean("changelog.dblogger.detailed-properties"), Config.getBoolean("changelog.dblogger.old-property-values"));
     70  }
     71 
     72  public DbLogManagerFactory(boolean detailedProperties, boolean oldValues)
     73  {
    6274    this.specialLoggers = new HashMap<Class, EntityLogger>();
    63     this.detailedProperties = Config.getBoolean("changelog.dblogger.detailed-properties");
    64     this.oldPropertyValues = detailedProperties ? Config.getBoolean("changelog.dblogger.old-property-values") : false;
     75    this.detailedProperties = detailedProperties;
     76    this.oldPropertyValues = detailedProperties && oldValues;
    6577
    6678    this.defaultLogger = new DefaultEntityLogger(this);
     
    7183    setSpecialLogger(AnnotationSetData.class, new AnnotationSetLogger(this));
    7284    setSpecialLogger(AnyToAnyData.class, new AnyToAnyLogger(this));
     85   
    7386  }
    7487 
  • trunk/src/test/TestChangeHistory.java

    r6100 r6430  
    2828import net.sf.basedb.core.BasicItem;
    2929import net.sf.basedb.core.ChangeHistory;
     30import net.sf.basedb.core.Sample;
    3031import net.sf.basedb.core.DbControl;
    3132import net.sf.basedb.core.Item;
     
    7980   
    8081    Extension<LogManagerFactory> logger = new ExtensionBean<LogManagerFactory>(
    81       "test.db-logger", "net.sf.basedb.core.log-manager", 1, null, new DbLogManagerFactory(), null);
     82      "test.db-logger", "net.sf.basedb.core.log-manager", 1, null, new DbLogManagerFactory(true, true), null);
    8283    xtRegistry.registerExtension(logger, null);
    8384   
     
    8687    int bioSourceId = TestBioSource.test_create("Biosource 1", false);
    8788    int sampleId = TestSample.test_create(bioSourceId, "Sample 1", 0, false);
     89    test_update_sample(sampleId);
    8890    int annotationTypeId = TestAnnotationType.test_create("change", Type.INT, 0, null, null, Item.SAMPLE, 1, null, false);
    8991    TestAnnotation.test_annotatate(Item.SAMPLE, sampleId, annotationTypeId, 0, 1);
     
    9496   
    9597    test_list_by_item(Item.BIOSOURCE, bioSourceId, 1);
    96     test_list_by_item(Item.SAMPLE, sampleId, 6);
     98    test_list_by_item(Item.SAMPLE, sampleId, 7);
    9799    /*
    98100      Total change log events:
    99       4 CREATE (biosource, sample, annotationtype, extract)
    100       5 UPDATE (when adding, updating and removing the annotation from the sample)
    101       1 DELETE (extract)
     101      5 CREATE (biosource, sample, annotationtype, extract, annotation)
     102      4 UPDATE (when updating and removing the annotation from the sample)
     103      2 DELETE (extract, annotation)
    102104    */
    103     test_list_by_user(TestUtil.getSessionControl().getLoggedInUserId(), since, 10);
     105    test_list_by_user(TestUtil.getSessionControl().getLoggedInUserId(), since, 11);
    104106   
    105107    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     
    108110    TestBioSource.test_delete(bioSourceId);
    109111    TestAnnotationType.test_delete(annotationTypeId);
    110     // 13 = The original 10 create+update + 3 delete
    111     test_delete_stray(13);
     112    // 14 = The original 11 create+update + 3 delete
     113    test_delete_stray(14);
    112114   
    113115    xtRegistry.unregisterExtension("test.db-logger");
     
    194196    if (!TestUtil.getSilent())
    195197    {
    196       write("   \tID \tTime     \tType\tItem  \tChange info\tUser");
    197       write("-- \t-- \t---------\t----\t------\t-----------\t----");
     198      write("   \tID \tTime     \tType\tItem  \tChange info\tOld value\tNew value\tUser");
     199      write("-- \t-- \t---------\t----\t------\t-----------\t---------\t---------\t----");
    198200    }
    199201  }
     
    212214    }
    213215    if (!TestUtil.getSilent()) System.out.println(i+":\t"+c.getId()+"\t"+c.getTime()+"\t"+
    214       c.getChangeType() + "\t" + item + "\t" + c.getChangeInfo()+"\t"+c.getUser(null));
     216      c.getChangeType() + "\t" + item + "\t" + c.getChangeInfo()+"\t"+c.getOldValue()+"\t"+c.getNewValue()+"\t"+c.getUser(null));
    215217  }
    216218  static void write(String message)
     
    242244  }
    243245
     246  static void test_update_sample(int sampleId)
     247  {
     248    DbControl dc = null;
     249    try
     250    {
     251      dc = TestUtil.getDbControl();
     252      Sample s = Sample.getById(dc, sampleId);
     253      s.setName("Updated name");
     254      s.setExternalId("Added external id");
     255      dc.commit();
     256      write("--Updated sample OK");
     257    }
     258    catch (Throwable ex)
     259    {
     260      write("--Updated sample FAILED");
     261      ex.printStackTrace();
     262      ok = false;
     263    }
     264    finally
     265    {
     266      if (dc != null) dc.close();
     267    }
     268  }
    244269}
    245270
Note: See TracChangeset for help on using the changeset viewer.