Project

General

Profile

Revision 9f1aa368

ID9f1aa3686f94a5067682ae1dee6421b76075062f
Parent 19ef2a42
Child e5605065

Added by Andreas Müller about 3 years ago

Cleanup; Delete unnecessary test classes.

View differences:

cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/test/function/TestDatabase.java
1
/**
2
* Copyright (C) 2008 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*/
6

  
7
package eu.etaxonomy.cdm.io.test.function;
8

  
9
import java.util.ArrayList;
10
import java.util.GregorianCalendar;
11
import java.util.List;
12

  
13
import org.apache.log4j.Logger;
14
import org.springframework.transaction.TransactionStatus;
15

  
16
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
17
import eu.etaxonomy.cdm.common.AccountStore;
18
import eu.etaxonomy.cdm.database.CdmDataSource;
19
import eu.etaxonomy.cdm.database.DbSchemaValidation;
20
import eu.etaxonomy.cdm.database.ICdmDataSource;
21
import eu.etaxonomy.cdm.io.jaxb.DataSet;
22
import eu.etaxonomy.cdm.model.agent.AgentBase;
23
import eu.etaxonomy.cdm.model.agent.Institution;
24
import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
25
import eu.etaxonomy.cdm.model.agent.Person;
26
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.common.TimePeriod;
29
import eu.etaxonomy.cdm.model.common.VersionableEntity;
30
import eu.etaxonomy.cdm.model.name.BotanicalName;
31
import eu.etaxonomy.cdm.model.name.Rank;
32
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
35
import eu.etaxonomy.cdm.model.taxon.Synonym;
36
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
37
import eu.etaxonomy.cdm.model.taxon.Taxon;
38
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
39

  
40
/**
41
 * @author a.babadshanjan
42
 * @created 28.10.2008
43
 */
44
public class TestDatabase {
45

  
46
	private static final String server = "192.168.2.10";
47
	private static final String username = "edit";
48

  
49
	private static final Logger logger = Logger.getLogger(TestDatabase.class);
50

  
51
	public static ICdmDataSource CDM_DB(String dbname) {
52

  
53
		logger.info("Setting DB " + dbname);
54
		String password = AccountStore.readOrStorePassword(dbname, server, username, null);
55
		ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, dbname, username, password);
56
		return datasource;
57
	}
58

  
59
    public static CdmApplicationController
60
    		initDb(ICdmDataSource db, DbSchemaValidation dbSchemaValidation, boolean omitTermLoading) {
61

  
62
		logger.info("Initializing database '" + db.getName() + "'");
63

  
64
		CdmApplicationController appCtrInit =
65
			CdmApplicationController.NewInstance(db, dbSchemaValidation, omitTermLoading);
66

  
67
		return appCtrInit;
68
    }
69

  
70
	public static void loadTestData(String dbname, CdmApplicationController appCtr) {
71

  
72
		logger.info("Loading test data into " + dbname);
73

  
74
		TransactionStatus txStatus = appCtr.startTransaction();
75
		DataSet dataSet = buildDataSet();
76

  
77
		appCtr.getTaxonService().save((List)dataSet.getTaxonBases());
78

  
79
		appCtr.commitTransaction(txStatus);
80
		appCtr.close();
81
    }
82

  
83
	/**
84
	 * This method constructs a small sample classification to test JAXB marshaling.
85
	 * The sample tree contains four taxa. The root taxon has two children taxa, and
86
	 * there is one "free" taxon without a parent and children.
87
	 */
88
	private static DataSet buildDataSet() {
89

  
90
		List<AgentBase> agents = new ArrayList<AgentBase>();
91
	    List<VersionableEntity> agentData = new ArrayList<VersionableEntity>();
92
	    //List<TermBase> terms = new ArrayList<TermBase>();
93
	    List<DefinedTermBase> terms = new ArrayList<DefinedTermBase>();
94
	    List<Reference> references = new ArrayList<Reference>();
95
	    List<TaxonNameBase> taxonomicNames = new ArrayList<TaxonNameBase>();
96
	    List<TaxonBase> taxonBases = new ArrayList<TaxonBase>();
97
	    List<AnnotatableEntity> homotypicalGroups;
98

  
99
		Reference citRef, sec;
100
		BotanicalName name1, name2, name21, nameRoot1, nameFree, synName11, synName12, synName2, synNameFree;
101
		BotanicalName nameRoot2, nameR2_1, nameR2_2;
102
		Taxon child1, child2, child21, root1T, root2T, freeT;
103
		Taxon childR2_1, childR2_2;
104
		Synonym syn11, syn12, syn2, synFree;
105
		Rank rankSpecies, rankSubspecies, rankGenus;
106

  
107
		// agents
108
		// - persons, institutions
109

  
110
		Person linne = new Person("Carl", "Linné", "L.");
111
		GregorianCalendar birth = new GregorianCalendar(1707, 4, 23);
112
		GregorianCalendar death = new GregorianCalendar(1778, 0, 10);
113
		TimePeriod period = TimePeriod.NewInstance(birth, death);
114
		linne.setLifespan(period);
115

  
116
//		Keyword keyword = Keyword.NewInstance("plantarum", "lat", "");
117
//		linne.addKeyword(keyword);
118

  
119
		Institution institute = Institution.NewInstance();
120

  
121
		agents.add(linne);
122
		agents.add(institute);
123

  
124
		// agent data
125
		// - contacts, addresses, memberships
126

  
127
		//Contact contact1 = new Contact();
128
		//contact1.setEmail("someone@somewhere.org");
129
		InstitutionalMembership membership = new InstitutionalMembership(institute, linne, period, "Biodiversity", "Head");
130
		//agentData.add(contact1);
131
        linne.getInstitutionalMemberships().add(membership);
132

  
133
		// terms
134
		// - ranks, keywords
135

  
136
		rankSpecies = Rank.SPECIES();
137
		rankSubspecies = Rank.SUBSPECIES();
138
		rankGenus = Rank.GENUS();
139

  
140
//		terms.add(keyword);
141

  
142
        // taxonomic names
143

  
144
		nameRoot1 = BotanicalName.NewInstance(rankGenus,"Calendula",null,null,null,linne,null,"p.100", null);
145

  
146
		name1 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"arvensis",null,linne,null,"p.1", null);
147
		synName11 = BotanicalName.NewInstance(rankSpecies,"Caltha",null,"arvensis",null,linne,null,"p.11", null);
148
		synName12 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"sancta",null,linne,null,"p.12", null);
149

  
150
		name2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzae",null,linne,null,"p.2", null);
151
		synName2 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"echinata",null,linne,null,"p.2", null);
152

  
153
		name21 = BotanicalName.NewInstance(rankSubspecies,"Calendula",null,"lanzea","something",linne,null,"p.1", null);
154
		//name211 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzea",null,linne,null,"p.1", null);
155
		//name212 = BotanicalName.NewInstance(rankSpecies,"Calendula",null,"lanzea",null,linne,null,"p.1", null);
156

  
157
		nameRoot2 =
158
			BotanicalName.NewInstance(rankGenus,"Sonchus",null,null,null,linne,null,"p.200", null);
159
		nameR2_1 = BotanicalName.NewInstance(rankSpecies,"Sonchus",null,"child1",null,linne,null,"p.1", null);
160
		nameR2_2 = BotanicalName.NewInstance(rankSpecies,"Sonchus",null,"child2",null,linne,null,"p.2", null);
161

  
162
		nameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"intybus",null,linne,null,"p.200", null);
163
		synNameFree = BotanicalName.NewInstance(rankSpecies,"Cichorium",null,"balearicum",null,linne,null,"p.2", null);
164

  
165
		taxonomicNames.add(nameRoot1);
166
		taxonomicNames.add(name1);
167
		taxonomicNames.add(synName11);
168
		taxonomicNames.add(synName12);
169
		taxonomicNames.add(name2);
170
		taxonomicNames.add(name21);
171
		taxonomicNames.add(synName2);
172
		taxonomicNames.add(nameFree);
173
		taxonomicNames.add(synNameFree);
174
		taxonomicNames.add(nameRoot2);
175

  
176
        // references
177
		sec = ReferenceFactory.newBook();
178
		sec.setAuthorship(linne);
179
		sec.setTitleCache("Plant Speciation", true);
180
		references.add(sec);
181

  
182
		citRef = ReferenceFactory.newDatabase();
183
		citRef.setAuthorship(linne);
184
		citRef.setTitleCache("BioCASE", true);
185
		references.add(citRef);
186

  
187
		// taxa
188

  
189
		root1T = Taxon.NewInstance(nameRoot1, sec);
190
		root2T = Taxon.NewInstance(nameRoot2, sec);
191
		freeT = Taxon.NewInstance(nameFree, sec);
192
		child1 = Taxon.NewInstance(name1, sec);
193
		child2 = Taxon.NewInstance(name2, sec);
194
		child21 = Taxon.NewInstance(name21, sec);
195
		childR2_1 = Taxon.NewInstance(nameR2_1, sec);
196
		childR2_2 = Taxon.NewInstance(nameR2_2, sec);
197

  
198
		// synonyms
199

  
200
		synFree = Synonym.NewInstance(synNameFree, sec);
201
		syn11 = Synonym.NewInstance(synName11, sec);
202
		syn12 = Synonym.NewInstance(synName12, sec);
203
		syn2 = Synonym.NewInstance(synName2, sec);
204

  
205
		child1.addSynonym(syn11, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
206
		child1.addSynonym(syn12, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
207
		child2.addSynonym(syn2, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
208
		freeT.addSynonym(synFree, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
209

  
210
		taxonBases.add(synFree);
211
		taxonBases.add(syn11);
212
		taxonBases.add(syn12);
213
		taxonBases.add(syn2);
214

  
215
		// taxonomic children
216

  
217
		root1T.addTaxonomicChild(child1, sec, "p.1010");
218
		root1T.addTaxonomicChild(child2, sec, "p.1020");
219
		child2.addTaxonomicChild(child21, sec, "p.2000");
220

  
221
		root2T.addTaxonomicChild(child1, sec, "p.1010");
222
		root2T.addTaxonomicChild(child2, sec, "p.1020");
223

  
224
		taxonBases.add(root1T);
225
		taxonBases.add(root2T);
226
		taxonBases.add(freeT);
227
		taxonBases.add(child1);
228
		taxonBases.add(child2);
229
		taxonBases.add(child21);
230
		taxonBases.add(childR2_1);
231
		taxonBases.add(childR2_2);
232

  
233
		DataSet dataSet = new DataSet();
234

  
235
		dataSet.setAgents(agents);
236
//		dataSet.setAgentData(agentData);
237
		dataSet.setTerms(terms);
238
		dataSet.setReferences(references);
239
		dataSet.setTaxonomicNames(taxonomicNames);
240
		dataSet.setTaxonBases((List)taxonBases);
241

  
242
		return dataSet;
243

  
244
	}
245
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonNode.java
730 730
        }
731 731
        return nodeSet;
732 732
    }
733
    
733

  
734 734
    /**
735 735
     * Retrieves the first ancestor of the given rank
736 736
     * @param rank the rank the ancestor should have
cdmlib-model/src/test/java/eu/etaxonomy/cdm/test/function/TestModel.java
1
/* just for testing */
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.test.function;
12

  
13
import java.util.UUID;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.aspectj.PropertyChangeTest;
18
import eu.etaxonomy.cdm.model.agent.Person;
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.description.TaxonDescription;
21
import eu.etaxonomy.cdm.model.name.BotanicalName;
22
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
23
import eu.etaxonomy.cdm.model.name.NonViralName;
24
import eu.etaxonomy.cdm.model.name.Rank;
25
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
26
import eu.etaxonomy.cdm.model.name.ZoologicalName;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.model.taxon.Synonym;
30
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32

  
33

  
34
public class TestModel {
35
	private static final UUID TEST_TAXON_UUID = UUID.fromString("b3084573-343d-4279-ba92-4ab01bb47db5");
36
	static Logger logger = Logger.getLogger(TestModel.class);
37

  
38
	public void testSomething(){
39

  
40
		logger.info("Create name objects...");
41
		logger.info(NomenclaturalStatusType.NUDUM().getRepresentation(Language.LATIN()).getAbbreviatedLabel());
42
		NonViralName<?> tn = NonViralName.NewInstance(Rank.SPECIES());
43
		BotanicalName tn3 = BotanicalName.NewInstance(Rank.SUBSPECIES());
44
		ZoologicalName parentName = ZoologicalName.NewInstance(Rank.FAMILY());
45

  
46
		logger.info("Create reference objects...");
47
		Reference sec = ReferenceFactory.newJournal();
48
		sec.setTitleCache("TestJournal", true);
49

  
50
		logger.info("Create taxon objects...");
51
		Taxon childTaxon = Taxon.NewInstance(tn, sec);
52
		Synonym syn = Synonym.NewInstance(tn3, sec);
53
		childTaxon.addSynonym(syn, SynonymRelationshipType.SYNONYM_OF());
54
		Taxon parentTaxon = Taxon.NewInstance(parentName, sec);
55
		parentTaxon.setUuid(TEST_TAXON_UUID);
56
		parentTaxon.addTaxonomicChild(childTaxon, sec, null);
57

  
58
		// setup listeners
59
		PropertyChangeTest listener = new PropertyChangeTest();
60
		tn.addPropertyChangeListener(listener);
61
		tn3.addPropertyChangeListener(listener);
62

  
63
		// test listeners
64
		tn.setGenusOrUninomial("tn1-Genus1");
65
		tn3.setGenusOrUninomial("tn3-genus");
66
		tn3.getGenusOrUninomial();
67

  
68
		logger.info("Create new Author agent...");
69
		Person team= Person.NewInstance();
70
		team.addPropertyChangeListener(listener);
71
		team.setTitleCache("AuthorAgent1", true);
72
		tn.setCombinationAuthorship(team);
73
	}
74

  
75
	public void testParentRelation(){
76
		TaxonNameBase<?,?> taxonName = BotanicalName.NewInstance(Rank.SPECIES());
77
		Reference ref = ReferenceFactory.newJournal();
78
		Taxon parent = Taxon.NewInstance(taxonName, ref);
79
		Taxon child = Taxon.NewInstance(taxonName, null);
80
		parent.addTaxonomicChild(child, null, null);
81
		if (child.getTaxonomicParent() != parent){
82
			logger.warn("Error");
83
		}
84
	}
85

  
86
	public void testDescription(){
87
		Reference ref = ReferenceFactory.newJournal();
88
		Taxon taxon = Taxon.NewInstance(null, ref);
89
		TaxonDescription desc = TaxonDescription.NewInstance();
90
		taxon.addDescription(desc);
91
		taxon.removeDescription(desc);
92
	}
93

  
94
	public void testTDWG(){
95
//		NamedArea tdwgArea = TdwgArea.getAreaByTdwgAbbreviation("GER");
96
//		NamedArea tdwgArea2 = TdwgArea.getAreaByTdwgLabel("Qatar");
97
//		System.out.println(tdwgArea.getLabel());
98
//		System.out.println(tdwgArea2.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
99
	}
100

  
101
	private void test(){
102
		System.out.println("Start ...");
103
		TestModel sc = new TestModel();
104
		//sc.testSomething();
105
		//sc.testParentRelation();
106
		//sc.testDescription();
107
		sc.testTDWG();
108
		System.out.println("\nEnd ...");
109
	}
110

  
111
	/**
112
	 * @param args
113
	 */
114
	public static void  main(String[] args) {
115
		TestModel sc = new TestModel();
116
		sc.test();
117
	}
118

  
119
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestPersistence.java
1
/* just for testing */
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.test.function;
12

  
13
import java.util.UUID;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.name.BotanicalName;
19
import eu.etaxonomy.cdm.model.name.NonViralName;
20
import eu.etaxonomy.cdm.model.name.Rank;
21
import eu.etaxonomy.cdm.model.name.ZoologicalName;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24
import eu.etaxonomy.cdm.model.taxon.Synonym;
25
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27

  
28

  
29
public class TestPersistence {
30
	private static final UUID TEST_TAXON_UUID = UUID.fromString("b3084573-343d-4279-ba92-4ab01bb47db5");
31
	static Logger logger = Logger.getLogger(TestPersistence.class);
32

  
33

  
34
	public void testAppController(){
35

  
36
		logger.info("Create name objects...");
37
		NonViralName<?> tn = NonViralName.NewInstance(Rank.SPECIES());
38
		BotanicalName tn3 = BotanicalName.NewInstance(Rank.SUBSPECIES());
39
		ZoologicalName parentName = ZoologicalName.NewInstance(Rank.FAMILY());
40

  
41
		logger.info("Create reference objects...");
42
		Reference sec = ReferenceFactory.newJournal();
43
		sec.setTitleCache("TestJournal", true);
44

  
45
		logger.info("Create taxon objects...");
46
		Taxon childTaxon = Taxon.NewInstance(tn, sec);
47
		Synonym syn = Synonym.NewInstance(tn3, sec);
48
		childTaxon.addSynonym(syn, SynonymRelationshipType.SYNONYM_OF());
49
		Taxon parentTaxon = Taxon.NewInstance(parentName, sec);
50
		parentTaxon.setUuid(TEST_TAXON_UUID);
51
		parentTaxon.addTaxonomicChild(childTaxon, sec, null);
52

  
53

  
54
		// test
55
		tn.setGenusOrUninomial("tn1-Genus1");
56
		tn3.setGenusOrUninomial("tn3-genus");
57

  
58
		logger.info("Create new Author agent...");
59
		Person team= Person.NewInstance();
60
		team.setTitleCache("AuthorAgent1", true);
61
		tn.setCombinationAuthorship(team);
62

  
63
		logger.info("Save objects ...");
64

  
65
//		appCtr.getTaxonService().saveTaxon(parentTaxon);
66
//
67
//		// load Name list
68
//		logger.info("Load existing names from db...");
69
//		List<TaxonNameBase> tnList = appCtr.getNameService().getAllNames(1000, 0);
70
//		for (TaxonNameBase tn2: tnList){
71
//			logger.info("Title: "+ tn2.getTitleCache() + " UUID: " + tn2.getUuid()+";");
72
//		}
73
//
74
//		// load Name list
75
//		logger.info("Load taxon from db...");
76
//		Taxon taxon = (Taxon)appCtr.getTaxonService().getTaxonByUuid(parentTaxon.getUuid());
77
//		logger.info("Parent: "+ taxon.toString());
78
//		for (Taxon child: taxon.getTaxonomicChildren()){
79
//			logger.info("Child: "+ child.toString());
80
//			for (Synonym synonym: child.getSynonyms()){
81
//				logger.info("Synonym: "+ synonym.toString());
82
//			}
83
//		}
84
//
85
//		// close
86
//		appCtr.close();
87
	}
88

  
89

  
90

  
91

  
92
	private void test(){
93
		System.out.println("Start ...");
94
		TestPersistence sc = new TestPersistence();
95
    	sc.testAppController();
96
    	System.out.println("\nEnd ...");
97
	}
98

  
99
	/**
100
	 * @param args
101
	 */
102
	public static void  main(String[] args) {
103
		TestPersistence sc = new TestPersistence();
104
    	sc.test();
105
	}
106

  
107
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestTaxonFunction.java
1
/**
2
* Copyright (C) 2009 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.test.function;
11

  
12
import java.util.List;
13
import java.util.UUID;
14

  
15
import org.apache.log4j.Logger;
16
import org.junit.Ignore;
17

  
18
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
19
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
20
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
21
import eu.etaxonomy.cdm.database.DbSchemaValidation;
22
import eu.etaxonomy.cdm.model.name.BotanicalName;
23
import eu.etaxonomy.cdm.model.name.Rank;
24
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27
import eu.etaxonomy.cdm.model.taxon.Synonym;
28
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
31
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
32
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
33

  
34
/**
35
 * <h2>NOTE</h2>
36
 * This is a test for sole development purposes, it is not
37
 * touched by mvn test since it is not matching the "\/**\/*Test" pattern,
38
 * but it should be annotate with @Ignore when running the project a s junit suite in eclipse
39
 *
40
 */
41
@Ignore
42
public class TestTaxonFunction {
43
	private static final Logger logger = Logger.getLogger(TestTaxonFunction.class);
44

  
45
	private CdmApplicationController getCdmApplicationController(String strDataSource, DbSchemaValidation hbm2dll){
46
		CdmApplicationController cdmApp= null;
47
		try {
48
			CdmPersistentDataSource dataSource = CdmPersistentDataSource.NewInstance(strDataSource);
49
			cdmApp = CdmApplicationController.NewInstance(dataSource, hbm2dll);
50
		} catch (DataSourceNotFoundException e) {
51
			e.printStackTrace();
52
		}
53
		return cdmApp;
54

  
55
	}
56

  
57
	private UUID getRefUuid(){
58
		return UUID.fromString("5d5363e2-f560-4da2-857d-dfa344b9f5ae");
59
	}
60

  
61
	private void initDatabase(){
62
		logger.info("init Database start ...");
63
		DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
64
		CdmApplicationController cdmApp = getCdmApplicationController("defaultMySql", hbm2dll);
65

  
66
		INonViralNameParser<?> parser = NonViralNameParserImpl.NewInstance();
67
		Reference sec = ReferenceFactory.newBook();
68
		sec.setTitleCache("ConceptRef", true);
69

  
70
		//root
71
		String rootName = "Hieracium L.";
72
		TaxonNameBase<?,?> botanicalName= parser.parseFullName(rootName);
73
		sec.setUuid(getRefUuid());
74
		Taxon genusTaxon = Taxon.NewInstance(botanicalName, sec);
75

  
76
		//child1
77
		String child1Name = "Hieracium asturianum Pau";
78
		TaxonNameBase<?,?> botSpecies= parser.parseFullName(child1Name);
79
		Taxon childTaxon = Taxon.NewInstance(botSpecies, sec);
80
		childTaxon.setTaxonomicParent(genusTaxon, null, null);
81

  
82
		//child2
83
		String child2Name = "Hieracium wolffii Zahn";
84
		TaxonNameBase<?,?> botSpecies2= parser.parseFullName(child2Name);
85
		Taxon childTaxon2 = Taxon.NewInstance(botSpecies2, sec);
86
		childTaxon2.setTaxonomicParent(childTaxon, null, null);
87

  
88
		//synonym
89
		String synonymName = "Acacium wolffii Syn.";
90
		TaxonNameBase<?,?> botSynName= parser.parseFullName(synonymName);
91

  
92
		Synonym synTaxon = Synonym.NewInstance(botSynName, sec);
93
		childTaxon2.addSynonym(synTaxon, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
94
		//save
95
		cdmApp.getTaxonService().save(genusTaxon);
96

  
97
		//other taxon
98
		BotanicalName otherName = BotanicalName.NewInstance(Rank.GENUS());
99
		otherName.setTitleCache("otherName", true);
100
		Taxon otherTaxon = Taxon.NewInstance(otherName, sec);
101

  
102
		cdmApp.getTaxonService().save(otherTaxon);
103
		cdmApp.close();
104
		logger.info("init Database end ...");
105
	}
106

  
107
	private boolean testHasTaxonomicChild(){
108
		logger.info("testHasTaxonomicChild start ...");
109
		if (false){
110
			initDatabase();
111
		}
112
		CdmApplicationController cdmApp = getCdmApplicationController("defaultMySql", DbSchemaValidation.VALIDATE);
113
		Reference sec = cdmApp.getReferenceService().find(getRefUuid());
114
		List<Taxon> rootList = cdmApp.getTaxonService().getRootTaxa(sec, CdmFetch.NO_FETCH(), false);
115
		for (Taxon taxon:rootList){
116
			System.out.println(taxon);
117
			//taxon.getT
118
			taxon.hasTaxonomicChildren();
119
			Taxon child = taxon.getTaxonomicChildren().iterator().next();
120
			logger.warn("Child has children: " + child.hasTaxonomicChildren());
121
			Taxon child2 = child.getTaxonomicChildren().iterator().next();
122
			logger.warn("Child2 has children: " + child2.hasTaxonomicChildren());
123
			logger.warn("Child2 has synonym: " + child2.hasSynonyms());
124
			Synonym syn = child2.getSynonyms().iterator().next();
125
			logger.warn("Syn has reference: " + syn.getSec());
126
		}
127
		logger.info("testHasTaxonomicChild end . ..");
128
		return true;
129
	}
130

  
131

  
132
	/**
133
	 * @param args
134
	 */
135
	public static void main(String[] args) {
136
		TestTaxonFunction testClass = new TestTaxonFunction();
137
		testClass.testHasTaxonomicChild();
138
		System.out.println("End");
139
	}
140

  
141
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/integration/CreateDataTest.java
1
/**
2
* Copyright (C) 2009 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.test.integration;
11

  
12

  
13
import static org.junit.Assert.assertEquals;
14
import static org.junit.Assert.assertNotNull;
15
import static org.junit.Assert.fail;
16

  
17
import java.util.Set;
18
import java.util.UUID;
19

  
20
import org.apache.log4j.Logger;
21
import org.joda.time.DateTime;
22
import org.junit.After;
23
import org.junit.AfterClass;
24
import org.junit.Before;
25
import org.junit.BeforeClass;
26
import org.junit.Ignore;
27
import org.junit.Test;
28

  
29
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
30
import eu.etaxonomy.cdm.api.service.ITaxonService;
31
import eu.etaxonomy.cdm.common.CdmUtils;
32
import eu.etaxonomy.cdm.database.CdmDataSource;
33
import eu.etaxonomy.cdm.database.DbSchemaValidation;
34
import eu.etaxonomy.cdm.database.ICdmDataSource;
35
import eu.etaxonomy.cdm.model.common.Language;
36
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
37
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
38
import eu.etaxonomy.cdm.model.description.TaxonDescription;
39
import eu.etaxonomy.cdm.model.description.TextData;
40
import eu.etaxonomy.cdm.model.name.BotanicalName;
41
import eu.etaxonomy.cdm.model.name.Rank;
42
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
43
import eu.etaxonomy.cdm.model.taxon.Taxon;
44
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
45

  
46
public class CreateDataTest {
47
	private static Logger logger = Logger.getLogger(CreateDataTest.class);
48

  
49
	private static boolean isCreated;
50
	private CdmApplicationController app;
51
	public static final String genusUuid = "c399e245-3def-427d-8502-afa0ae87e875";
52
	public static final String genusNameUuid = "d399e245-3def-427d-8502-afa0ae87e875";
53

  
54
	private static boolean ignore = true;
55

  
56
	@BeforeClass
57
	public static void setUpBeforeClass() throws Exception {
58
		if (ignore){
59
			logger.warn("\nCreateDataTest ignored !\n");
60
			return;
61
		}
62
		logger.info("setUpBeforeClass");
63
		isCreated = false;
64
	}
65

  
66
	@AfterClass
67
	public static void tearDownAfterClass() throws Exception {
68
	}
69

  
70
	@Before
71
	public void setUp() throws Exception {
72
		if (ignore){return;}
73
		DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
74
		if (isCreated == false){
75
			 dbSchemaValidation = DbSchemaValidation.CREATE;
76
		}
77
		ICdmDataSource dataSource = cdm_test();
78
		app  = CdmApplicationController.NewInstance(dataSource, dbSchemaValidation);
79
	}
80

  
81
	@After
82
	public void tearDown() throws Exception {
83
		if (ignore){return;}
84
		isCreated = true;
85
		app.close();
86
	}
87

  
88
	//just temporarly
89
	public static ICdmDataSource cdm_test(){
90
		//DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
91
		String cdmServer = "192.168.2.10";
92
		String cdmDB = "cdm_test_andreasM";
93
		String cdmUserName = "edit";
94
		return makeDestination(cdmServer, cdmDB, -1, cdmUserName, null);
95
	}
96

  
97

  
98
	//just temporarly
99
	public static ICdmDataSource paddie(){
100
//		DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005;
101
		String cdmServer = "PADDIE";
102
		String cdmDB = "edit_test";
103
		String cdmUserName = "andreas";
104
		return makeDestination(cdmServer, cdmDB, -1, cdmUserName, null);
105
	}
106

  
107
	/**
108
	 * initializes source
109
	 * @return true, if connection establisehd
110
	 */
111
	private static ICdmDataSource makeDestination(String cdmServer, String cdmDB, int port, String cdmUserName, String pwd ){
112
		//establish connection
113
		try {
114
			if (pwd == null){
115
				pwd = CdmUtils.readInputLine("Please insert password for " + CdmUtils.Nz(cdmUserName) + ": ");
116
			}
117
			//TODO not MySQL
118
			ICdmDataSource destination = CdmDataSource.NewMySqlInstance(cdmServer, cdmDB, port, cdmUserName, pwd, null);
119
			//ICdmDataSource destination = CdmDataSource.NewSqlServer2005Instance(cdmServer, cdmDB, cdmUserName, pwd);
120
			return destination;
121
		} catch (Exception e) {
122
			logger.error(e);
123
			return null;
124
		}
125
	}
126

  
127

  
128
/* ********************* TESTS *********************************/
129

  
130
	@Ignore
131
	@Test
132
	public void testCreateTaxon(){
133
		if (ignore){return;}
134
		//Taxon with childs, basionym, childrens synonyms, child misapplied Name
135
		Taxon genusTaxon = eu.etaxonomy.cdm.datagenerator.TaxonGenerator.getTestTaxon();
136
		genusTaxon.setUuid(UUID.fromString(genusUuid));
137
		genusTaxon.getName().setUuid(UUID.fromString(genusNameUuid));
138

  
139
//		Synonym syn2 = Synonym.NewInstance(genusTaxon.getName(), null);
140

  
141
		app.getTaxonService().save(genusTaxon);
142
		//app.getTaxonService().saveTaxon(syn2);
143
	}
144

  
145
	@Test
146
	public void testLoadTaxon(){
147
		if (ignore){return;}
148
		//Taxon with childs, basionym, childrens synonyms, child misapplied Name
149

  
150

  
151
		TaxonNameBase<?,?> genusName2 = app.getNameService().find(UUID.fromString(genusNameUuid));
152
		Set<TaxonBase> set = genusName2.getTaxonBases();
153
		System.out.println("Size:" + set.size());
154
		for (TaxonBase tb : set){
155
			System.out.println(tb.getName());
156
		}
157

  
158
		//taxon
159
		Taxon genusTaxon = (Taxon)app.getTaxonService().find(UUID.fromString(genusUuid));
160
		assertNotNull(genusTaxon);
161
		//name
162
		BotanicalName genusName = (BotanicalName)genusTaxon.getName();
163
		assertNotNull(genusName);
164
		Set<TaxonBase> taxaSet = genusName.getTaxonBases();
165
		for (TaxonBase tb : taxaSet){
166
			System.out.println(tb.getName());
167
		}
168

  
169
		//taxonBases of Name
170
		Set<TaxonBase> taxonBases = genusName.getTaxonBases();
171
		logger.warn(taxonBases.size());
172
		Set<Taxon> children = genusTaxon.getTaxonomicChildren();
173
		for (Taxon child : children){
174
			child.getSynonyms();
175
			child.getMisappliedNames();
176
			child.getHomotypicGroup();
177
			child.getHomotypicSynonymsByHomotypicGroup();
178
			child.getHomotypicSynonymsByHomotypicRelationship();
179
		}
180

  
181
		Set<TaxonDescription> descriptions = genusTaxon.getDescriptions();
182
		assertEquals(1, descriptions.size());
183
		TaxonDescription firstDescription = descriptions.iterator().next();
184

  
185

  
186
		Set<DescriptionElementBase> descriptionElements = firstDescription.getElements();
187
		//assertEquals(2, descriptions.size());
188

  
189
		Language language = Language.DEFAULT();
190
		for (DescriptionElementBase descriptionElement : descriptionElements){
191
			if (descriptionElement instanceof TextData){
192
				TextData textData = (TextData)descriptionElement;
193
				textData.getText(language);
194
				System.out.println(textData);
195
			}else if(descriptionElement instanceof CommonTaxonName){
196
				CommonTaxonName commonTaxonName = (CommonTaxonName)descriptionElement;
197
				commonTaxonName.getName();
198
				commonTaxonName.getLanguage();
199
				System.out.println(commonTaxonName);
200
			}else{
201
				fail();
202
			}
203
		}
204

  
205
	}
206

  
207

  
208
	@Ignore
209
	@Test
210
	public void testSave(){
211
		if (ignore){return;}
212
		logger.warn("testSave");
213
		ITaxonService taxonService = app.getTaxonService();
214
		Taxon genusTaxon = (Taxon)taxonService.find(UUID.fromString(genusUuid));
215
		BotanicalName genusName = (BotanicalName)genusTaxon.getName();
216
		genusName.setGenusOrUninomial("newGenusUninomial");
217
		genusName.setUpdated(new DateTime());
218
		BotanicalName newName = BotanicalName.NewInstance(Rank.SPECIES());
219
		Taxon newTaxon = Taxon.NewInstance(newName, genusTaxon.getSec());
220
		genusTaxon.addTaxonomicChild(newTaxon, null, "5677");
221
		UUID uuid = taxonService.save(newTaxon).getUuid();
222
		assertNotNull(uuid);
223
	}
224

  
225

  
226
}
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/integration/CreateDataTestNoUnit.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.test.integration;
11

  
12
import static org.junit.Assert.assertEquals;
13
import static org.junit.Assert.assertNotNull;
14
import static org.junit.Assert.fail;
15

  
16
import java.util.Set;
17
import java.util.UUID;
18

  
19
import org.apache.log4j.Logger;
20

  
21
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
22
import eu.etaxonomy.cdm.database.DbSchemaValidation;
23
import eu.etaxonomy.cdm.database.ICdmDataSource;
24
import eu.etaxonomy.cdm.model.common.Language;
25
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
26
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
27
import eu.etaxonomy.cdm.model.description.TaxonDescription;
28
import eu.etaxonomy.cdm.model.description.TextData;
29
import eu.etaxonomy.cdm.model.name.BotanicalName;
30
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
33

  
34
/**
35
 * @author a.mueller
36
 * @created 28.05.2008
37
 * @version 1.0
38
 */
39
public class CreateDataTestNoUnit {
40
	private static Logger logger = Logger.getLogger(CreateDataTestNoUnit.class);
41
	
42
	private CdmApplicationController app;
43
	
44
	
45
	public void test(){
46
		boolean isCreated = true;
47
		DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
48
		if (isCreated == false){
49
			 dbSchemaValidation = DbSchemaValidation.CREATE;
50
		}
51
		ICdmDataSource dataSource = CreateDataTest.cdm_test();
52
		app  = CdmApplicationController.NewInstance(dataSource, dbSchemaValidation);
53

  
54
		TaxonNameBase<?,?> genusName2 = (TaxonNameBase<?,?>)app.getNameService().find(UUID.fromString(CreateDataTest.genusNameUuid));
55
		Set<TaxonBase> set = (Set<TaxonBase>)genusName2.getTaxonBases();
56
		System.out.println("Size:" + set.size());
57
		for (TaxonBase tb : set){
58
			System.out.println(tb.getName());
59
		}
60
		
61
		//taxon
62
		Taxon genusTaxon = (Taxon)app.getTaxonService().find(UUID.fromString(CreateDataTest.genusUuid));
63
		assertNotNull(genusTaxon);
64
		//name
65
		BotanicalName genusName = (BotanicalName)genusTaxon.getName();
66
		assertNotNull(genusName);
67
		Set<TaxonBase> taxaSet = genusName.getTaxonBases();
68
		for (TaxonBase tb : taxaSet){
69
			System.out.println(tb.getName());
70
		}
71
		
72
		//taxonBases of Name
73
		Set<TaxonBase> taxonBases = genusName.getTaxonBases();
74
		logger.warn(taxonBases.size());
75
		Set<Taxon> children = genusTaxon.getTaxonomicChildren();
76
		for (Taxon child : children){
77
			child.getSynonyms();
78
			child.getMisappliedNames();
79
			child.getHomotypicGroup();
80
			child.getHomotypicSynonymsByHomotypicGroup();
81
			child.getHomotypicSynonymsByHomotypicRelationship();
82
		}
83
		
84
		Set<TaxonDescription> descriptions = genusTaxon.getDescriptions();
85
		assertEquals(2, descriptions.size());
86
		TaxonDescription description = descriptions.iterator().next();
87
		
88
		
89
		Set<DescriptionElementBase> descriptionElements = description.getElements();
90
		
91
		Language language = Language.DEFAULT(); 
92
		for (DescriptionElementBase descriptionElement : descriptionElements){
93
			if (descriptionElement instanceof TextData){
94
				TextData textData = (TextData)descriptionElement;
95
				textData.getText(language);
96
			}else if(descriptionElement instanceof CommonTaxonName){
97
				CommonTaxonName commonTaxonName = (CommonTaxonName)descriptionElement;
98
				commonTaxonName.getName();
99
				commonTaxonName.getLanguage();
100
			}else{
101
				fail();
102
			}
103
		}
104

  
105
	}
106
	
107
	
108
	/**
109
	 * @param args
110
	 */
111
	public static void main(String[] args) {
112
		CreateDataTestNoUnit test = new CreateDataTestNoUnit();
113
		test.test();
114
	}
115
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)