Committing large number of changes relating to versioning implementation (#108)
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / dao / hibernate / common / CdmEntityDaoBaseTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.persistence.dao.hibernate.common;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.List;
18 import java.util.UUID;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.unitils.dbunit.annotation.DataSet;
23 import org.unitils.dbunit.annotation.ExpectedDataSet;
24 import org.unitils.spring.annotation.SpringBeanByType;
25
26 import eu.etaxonomy.cdm.model.common.CdmBase;
27 import eu.etaxonomy.cdm.model.taxon.Taxon;
28 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
29 import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
30 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
31
32 /**
33 * @author a.mueller
34 *
35 */
36 public class CdmEntityDaoBaseTest extends CdmIntegrationTest {
37
38 private UUID uuid;
39 private TaxonBase cdmBase;
40
41 @SpringBeanByType
42 private ITaxonDao cdmEntityDaoBase;
43
44 /**
45 * @throws java.lang.Exception
46 */
47 @Before
48 public void setUp() throws Exception {
49 uuid = UUID.fromString("8d77c380-c76a-11dd-ad8b-0800200c9a66");
50 cdmBase = Taxon.NewInstance(null, null);
51 cdmBase.setUuid(UUID.fromString("e463b270-c76b-11dd-ad8b-0800200c9a66"));
52 }
53
54 /************ TESTS ********************************/
55
56
57 /**
58 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
59 * @throws Exception
60 */
61 @Test
62 public void testCdmEntityDaoBase() throws Exception {
63 assertNotNull("cdmEntityDaoBase should exist",cdmEntityDaoBase);
64 }
65
66 /**
67 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
68 */
69 @Test
70 @DataSet("CdmEntityDaoBaseTest.xml")
71 @ExpectedDataSet
72 public void testSaveOrUpdate() {
73 TaxonBase cdmBase = cdmEntityDaoBase.findByUuid(uuid);
74 cdmBase.setUuid(UUID.fromString("61410dd0-c774-11dd-ad8b-0800200c9a66"));
75 cdmEntityDaoBase.saveOrUpdate(cdmBase);
76 }
77
78 /**
79 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#save(eu.etaxonomy.cdm.model.common.CdmBase)}.
80 */
81 @Test
82 @DataSet("CdmEntityDaoBaseTest.xml")
83 @ExpectedDataSet
84 public void testSave() throws Exception {
85 cdmEntityDaoBase.save(cdmBase);
86 }
87
88 /**
89 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#update(eu.etaxonomy.cdm.model.common.CdmBase)}.
90 */
91 @Test
92 @DataSet("CdmEntityDaoBaseTest.xml")
93 @ExpectedDataSet
94 public void testUpdate() {
95 TaxonBase cdmBase = cdmEntityDaoBase.findByUuid(uuid);
96 cdmBase.setUuid(UUID.fromString("65bc7d70-c76c-11dd-ad8b-0800200c9a66"));
97 cdmEntityDaoBase.update(cdmBase);
98 }
99
100 /**
101 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#findById(int)}.
102 */
103 @Test
104 @DataSet("CdmEntityDaoBaseTest.xml")
105 public void testFindById() {
106 CdmBase cdmBase = cdmEntityDaoBase.findById(1);
107 assertNotNull("There should be an entity with an id of 1",cdmBase);
108 }
109
110 /**
111 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#findByUuid(java.util.UUID)}.
112 */
113 @Test
114 @DataSet("CdmEntityDaoBaseTest.xml")
115 public void testFindByUuid() {
116 CdmBase cdmBase = cdmEntityDaoBase.findByUuid(uuid);
117 assertNotNull("testFindByUuid() an entity with a uuid of " + uuid.toString(),cdmBase);
118 }
119
120 /**
121 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#exists(java.util.UUID)}.
122 */
123 @Test
124 @DataSet("CdmEntityDaoBaseTest.xml")
125 public void testExists() {
126 boolean exists = cdmEntityDaoBase.exists(uuid);
127 assertTrue("exists() should return true for uuid " + uuid.toString(), exists);
128 boolean existsRandom = cdmEntityDaoBase.exists(UUID.randomUUID());
129 assertFalse("exists() should return false for any other uuid", existsRandom);
130 }
131
132 /**
133 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#list(int, int)}.
134 */
135 @Test
136 @DataSet("CdmEntityDaoBaseTest.xml")
137 public void testList() {
138 List<TaxonBase> list = cdmEntityDaoBase.list(1000, 0);
139 assertNotNull("list() should not return null",list);
140 assertEquals("list() should return a list with two entities in it",list.size(),2);
141 }
142
143 /**
144 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
145 */
146 @Test
147 @DataSet("CdmEntityDaoBaseTest.xml")
148 @ExpectedDataSet
149 public void testDelete() {
150 TaxonBase cdmBase = cdmEntityDaoBase.findByUuid(uuid);
151 assertNotNull(cdmBase);
152 cdmEntityDaoBase.delete(cdmBase);
153 }
154
155 }