package edu.columbia.gemma.common.description;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataIntegrityViolationException;

import edu.columbia.gemma.BaseDAOTestCase;

/**
 * <hr>
 * <p>
 * Copyright (c) 2004 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class BibliographicReferenceDaoImplTest extends BaseDAOTestCase {

   private BibliographicReferenceDao dao = null;
   private DatabaseEntryDao dedao = null;

   protected void setUp() throws Exception {
      Log log = LogFactory.getLog( BibliographicReferenceDaoImplTest.class );
      dao = ( BibliographicReferenceDao ) ctx.getBean( "bibliographicReferenceDao" );
      dedao = ( DatabaseEntryDao ) ctx.getBean( "databaseEntryDao" );
   }

   protected void tearDown() throws Exception {
      dao = null;
   }

   /*
    * Class under test for Object findByExternalId(int, java.lang.String)
    */
   public final void testFindByExternalIdintString() {

      BibliographicReference f = new BibliographicReferenceImpl();

      String random = ( new Date() ).toString();

      DatabaseEntry de = ( DatabaseEntry ) dedao.create( "2", "", "", ( new Date() ).toString(), "foo" );
      DatabaseEntry deb = ( DatabaseEntry ) dedao.create( "3", "", "", ( new Date() ).toString(), "foo" );

      f.setPubAccession( de );
      f.setIdentifier( random );
      dao.create( f );

      f = dao.findByExternalId( de );

      assertTrue( f != null );
      assertTrue( dao.findByExternalId( deb ) == null );

      try {
         dao.create( f );
         fail( "Create didn't throw DataIntegrityViolationException" );
      } catch ( DataIntegrityViolationException e ) {
         assertNotNull( e );
         log.debug( "Good, expected exception: " + e.getMessage() );
      }

   }

}
@@ -438,24 +438,25 @@
 tCase %7B%0A%0A   
+ 
 private Bibl
@@ -492,16 +492,17 @@
 ull;%0A   
+ 
 private 
@@ -533,16 +533,17 @@
  null;%0A%0A
+ 
    prote
@@ -575,24 +575,26 @@
 Exception %7B%0A
+  
       Log lo
@@ -661,24 +661,26 @@
 ss );%0A      
+  
 dao = ( Bibl
@@ -743,24 +743,26 @@
 enceDao%22 );%0A
+  
       dedao 
@@ -822,19 +822,21 @@
 %22 );%0A   
+ 
 %7D%0A%0A
+ 
    prote
@@ -877,24 +877,26 @@
 ion %7B%0A      
+  
 dao = null;%0A
@@ -895,16 +895,17 @@
 = null;%0A
+ 
    %7D%0A%0A  
@@ -909,11 +909,13 @@
 %0A   
+ 
 /*%0A
+ 
     
@@ -988,19 +988,21 @@
 ng)%0A    
+ 
 */%0A
+ 
    publi
@@ -1055,16 +1055,18 @@
 %0A%0A      
+  
 Bibliogr
@@ -1083,20 +1083,16 @@
 ence f =
- new
  Bibliog
@@ -1110,17 +1110,35 @@
 ence
-Impl
+.Factory.newInstance
 ();%0A%0A
+  
     
@@ -1185,24 +1185,26 @@
 g();%0A%0A      
+  
 DatabaseEntr
@@ -1209,34 +1209,16 @@
 try de =
- ( DatabaseEntry )
  dedao.c
@@ -1227,17 +1227,8 @@
 ate(
- %222%22, %22%22,
  %22%22,
@@ -1266,24 +1266,26 @@
 o%22 );%0A      
+  
 DatabaseEntr
@@ -1295,26 +1295,8 @@
 eb =
- ( DatabaseEntry )
  ded
@@ -1309,17 +1309,8 @@
 ate(
- %223%22, %22%22,
  %22%22,
@@ -1343,24 +1343,26 @@
 , %22foo%22 );%0A%0A
+  
       f.setP
@@ -1382,24 +1382,26 @@
 de );%0A      
+  
 f.setIdentif
@@ -1411,24 +1411,26 @@
 ( random );%0A
+  
       dao.cr
@@ -1447,16 +1447,18 @@
 %0A%0A      
+  
 f = dao.
@@ -1478,24 +1478,26 @@
 lId( de );%0A%0A
+  
       assert
@@ -1517,24 +1517,26 @@
 ll );%0A      
+  
 assertTrue( 
@@ -1571,24 +1571,26 @@
 == null );%0A%0A
+  
       try %7B%0A
@@ -1590,32 +1590,35 @@
  try %7B%0A         
+   
 dao.create( f );
@@ -1614,24 +1614,27 @@
 reate( f );%0A
+   
          fai
@@ -1699,16 +1699,18 @@
 ;%0A      
+  
 %7D catch 
@@ -1754,24 +1754,27 @@
  %7B%0A         
+ 
+  
 assertNotNul
@@ -1777,24 +1777,27 @@
 tNull( e );%0A
+   
          log
@@ -1859,18 +1859,21 @@
 ;%0A      
+  
 %7D%0A%0A
+ 
    %7D%0A%0A%7D

change due to difference in DatabaseEntry.