2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
;
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
;
17 import java
.util
.List
;
18 import java
.util
.UUID
;
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
;
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
;
36 public class CdmEntityDaoBaseTest
extends CdmIntegrationTest
{
39 private TaxonBase cdmBase
;
42 private ITaxonDao cdmEntityDaoBase
;
45 * @throws java.lang.Exception
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"));
54 /************ TESTS ********************************/
58 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
62 public void testCdmEntityDaoBase() throws Exception
{
63 assertNotNull("cdmEntityDaoBase should exist",cdmEntityDaoBase
);
67 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#saveOrUpdate(eu.etaxonomy.cdm.model.common.CdmBase)}.
70 @DataSet("CdmEntityDaoBaseTest.xml")
72 public void testSaveOrUpdate() {
73 TaxonBase cdmBase
= cdmEntityDaoBase
.findByUuid(uuid
);
74 cdmBase
.setUuid(UUID
.fromString("61410dd0-c774-11dd-ad8b-0800200c9a66"));
75 cdmEntityDaoBase
.saveOrUpdate(cdmBase
);
79 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#save(eu.etaxonomy.cdm.model.common.CdmBase)}.
82 @DataSet("CdmEntityDaoBaseTest.xml")
84 public void testSave() throws Exception
{
85 cdmEntityDaoBase
.save(cdmBase
);
89 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#update(eu.etaxonomy.cdm.model.common.CdmBase)}.
92 @DataSet("CdmEntityDaoBaseTest.xml")
94 public void testUpdate() {
95 TaxonBase cdmBase
= cdmEntityDaoBase
.findByUuid(uuid
);
96 cdmBase
.setUuid(UUID
.fromString("65bc7d70-c76c-11dd-ad8b-0800200c9a66"));
97 cdmEntityDaoBase
.update(cdmBase
);
101 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#findById(int)}.
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
);
111 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#findByUuid(java.util.UUID)}.
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
);
121 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#exists(java.util.UUID)}.
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
);
133 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#list(int, int)}.
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);
144 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#delete(eu.etaxonomy.cdm.model.common.CdmBase)}.
147 @DataSet("CdmEntityDaoBaseTest.xml")
149 public void testDelete() {
150 TaxonBase cdmBase
= cdmEntityDaoBase
.findByUuid(uuid
);
151 assertNotNull(cdmBase
);
152 cdmEntityDaoBase
.delete(cdmBase
);