Altered ReferringObjectMetadataFactoryImpl to exclude bidirectional relationships...
[cdmlib.git] / cdmlib-persistence / src / test / java / eu / etaxonomy / cdm / persistence / hibernate / replace / ReferringObjectMetadataFactoryTest.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.hibernate.replace;
11
12
13 import java.io.FileOutputStream;
14 import java.util.UUID;
15
16 import org.apache.log4j.Logger;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.unitils.dbunit.annotation.DataSet;
20 import org.unitils.dbunit.annotation.ExpectedDataSet;
21 import org.unitils.spring.annotation.SpringBeanByType;
22
23 import eu.etaxonomy.cdm.model.agent.Institution;
24 import eu.etaxonomy.cdm.model.agent.Person;
25 import eu.etaxonomy.cdm.model.description.MediaKey;
26 import eu.etaxonomy.cdm.model.media.Media;
27 import eu.etaxonomy.cdm.model.name.BotanicalName;
28 import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
29 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
30 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
31
32 /**
33 * @author ben.clark
34 * @created 22.12.2009
35 * @version 1.0
36 */
37 public class ReferringObjectMetadataFactoryTest extends CdmTransactionalIntegrationTest {
38 @SuppressWarnings("unused")
39 private static Logger logger = Logger.getLogger(ReferringObjectMetadataFactoryTest.class);
40
41 @SpringBeanByType
42 private ReferringObjectMetadataFactory referringObjectMetadataFactory;
43
44 @SpringBeanByType
45 private IAgentDao agentDao;
46
47 private UUID institution1;
48
49 private UUID institution2;
50
51 private UUID person1;
52
53 private UUID person2;
54
55 private UUID person3;
56
57 /**
58 * @throws java.lang.Exception
59 */
60 @Before
61 public void setUp() throws Exception {
62 institution1 = UUID.fromString("18679846-7343-4e5f-b14e-5eb56b967989");
63 institution2 = UUID.fromString("28f6aaa5-e03e-4831-9ce2-71eaf56cdebe");
64 person1 = UUID.fromString("ed6ac546-8c6c-48c4-9b91-40b1157c05c6");
65 person2 = UUID.fromString("e4ec436a-3e8c-4166-a834-3bb84c2b5ad6");
66 person3 = UUID.fromString("c62cd389-d787-47f4-99c3-b80eb12a1ef2");
67 }
68
69 /**
70 * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#CdmEntityDaoBase(java.lang.Class)}.
71 * @throws Exception
72 */
73 @Test
74 public void testReferringObjectMetadataFactory() throws Exception {
75 referringObjectMetadataFactory.get(Person.class);
76 }
77
78 @Test
79 @DataSet
80 public void testReplaceUnmapped() throws Exception {
81 Institution x = (Institution)agentDao.findByUuid(institution1);
82 Institution y = (Institution)agentDao.findByUuid(institution2);
83
84 assert x != null;
85 assert y != null;
86
87 agentDao.replace(x,y);
88 }
89
90 @Test
91 @DataSet
92 @ExpectedDataSet
93 public void testReplaceToOneProperty() throws Exception {
94 Person x = (Person)agentDao.findByUuid(person1);
95 Person y = (Person)agentDao.findByUuid(person2);
96
97 assert x != null;
98 assert y != null;
99
100 agentDao.replace(x,y);
101 this.setComplete();
102 this.endTransaction();
103
104 }
105
106 @Test
107 @DataSet
108 @ExpectedDataSet
109 public void testReplaceToManyProperty() throws Exception {
110 Person x = (Person)agentDao.findByUuid(person3);
111 Person y = (Person)agentDao.findByUuid(person2);
112
113 assert x != null;
114 assert y != null;
115
116 agentDao.replace(x,y);
117 }
118
119 @Test
120 public void testIgnoreBidirectionalRelationship() {
121 referringObjectMetadataFactory.get(BotanicalName.class);
122 }
123 }
124
125