(no commit message)
[cdmlib.git] / cdmlibrary / src / test / java / eu / etaxonomy / cdm / persistence / dao / EnumerationDaoHibernateImplTest.java
1 package eu.etaxonomy.cdm.persistence.dao;
2
3
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6
7 import java.io.FileNotFoundException;
8 import java.util.List;
9
10 import org.apache.log4j.Logger;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.test.context.ContextConfiguration;
15
16 import eu.etaxonomy.cdm.model.common.Enumeration;
17 import eu.etaxonomy.cdm.model.common.Keyword;
18 import eu.etaxonomy.cdm.model.name.Rank;
19 import eu.etaxonomy.cdm.test.unit.CdmUnitTestBase;
20
21
22 public class EnumerationDaoHibernateImplTest extends CdmUnitTestBase{
23 static Logger logger = Logger.getLogger(EnumerationDaoHibernateImplTest.class);
24
25 @Autowired
26 private IEnumerationDAO dao;
27 private Enumeration enumeration;
28
29 @Before
30 // generate enumeration for every test to play with
31 public void onSetUp() throws Exception {
32 logger.debug(EnumerationDaoHibernateImplTest.class.getSimpleName() + " setup()");
33 this.enumeration = new Enumeration("Biological subdomains","biodomain","http://myterms.org/biodomain");
34 String [] repres = {"genetics","physiology","systematics","taxonomy","nomenclature"};
35 for (String r : repres){
36 Keyword term = new Keyword(r,r,null);
37 enumeration.addTerm(term);
38 }
39 }
40
41 @Test
42 public void testSave() {
43 dao.saveOrUpdate(this.enumeration);
44 this.enumeration.addTerm(new Keyword("cladistics","cladistics",null));
45 dao.saveOrUpdate(this.enumeration);
46 }
47
48 @Test
49 public void testFindString() {
50 List<Enumeration> myEnum = dao.find("biodomain");
51 assertTrue(myEnum.contains(this.enumeration));
52 }
53
54 @Test
55 public void loadTerms() {
56 try {
57 dao.loadTerms(Rank.class, "Rank.csv", true);
58 } catch (FileNotFoundException e) {
59 // TODO Auto-generated catch block
60 e.printStackTrace();
61 } catch (NoDefinedTermClassException e) {
62 // TODO Auto-generated catch block
63 e.printStackTrace();
64 }
65 }
66
67 @Test
68 public void testList100() {
69 assertFalse(dao.list(100,1).isEmpty());
70 }
71 }