Revision 66aeb5aa
Added by Andreas Kohlbecker almost 12 years ago
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/DescriptionServiceImplTest.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2009 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
21 | 21 |
import org.apache.log4j.Logger; |
22 | 22 |
import org.junit.Test; |
23 | 23 |
import org.unitils.dbunit.annotation.DataSet; |
24 |
import org.unitils.spring.annotation.SpringApplicationContext; |
|
25 | 24 |
import org.unitils.spring.annotation.SpringBeanByType; |
26 | 25 |
|
27 | 26 |
import eu.etaxonomy.cdm.api.service.pager.Pager; |
... | ... | |
40 | 39 |
* @version 1.0 |
41 | 40 |
*/ |
42 | 41 |
|
43 |
@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml") |
|
44 | 42 |
public class DescriptionServiceImplTest extends CdmIntegrationTest { |
45 |
@SuppressWarnings("unused")
|
|
46 |
private static Logger logger = Logger.getLogger(DescriptionServiceImplTest.class);
|
|
47 |
|
|
48 |
@SpringBeanByType
|
|
49 |
private IDescriptionService service;
|
|
50 |
|
|
51 |
@SpringBeanByType
|
|
52 |
private ITermService termService;
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
@Test
|
|
57 |
public void testGetDefaultFeatureVocabulary() {
|
|
58 |
|
|
59 |
service.getDefaultFeatureVocabulary();
|
|
60 |
}
|
|
61 |
|
|
62 |
@Test
|
|
63 |
@DataSet("CommonServiceImplTest.xml")
|
|
64 |
public void testChangeDescriptionElement(){
|
|
65 |
DescriptionBase descBase = service.find(UUID.fromString("eb17b80a-9be6-4642-a6a8-b19a318925e6"));
|
|
66 |
Set<DescriptionElementBase> elements = descBase.getElements();
|
|
67 |
Iterator iterator = elements.iterator();
|
|
68 |
while (iterator.hasNext()){
|
|
69 |
DescriptionElementBase base = (DescriptionElementBase) iterator.next();
|
|
70 |
if (base instanceof TextData){
|
|
71 |
TextData textdata = (TextData) base;
|
|
72 |
Set <Entry<Language,LanguageString>> entries = textdata.getMultilanguageText().entrySet();
|
|
73 |
Iterator entryIterator = entries.iterator();
|
|
74 |
while (entryIterator.hasNext()){
|
|
75 |
Entry <Language, LanguageString> entry = (Entry<Language, LanguageString>) entryIterator.next();
|
|
76 |
LanguageString langString = entry.getValue();
|
|
43 |
@SuppressWarnings("unused")
|
|
44 |
private static Logger logger = Logger.getLogger(DescriptionServiceImplTest.class);
|
|
45 |
|
|
46 |
@SpringBeanByType
|
|
47 |
private IDescriptionService service;
|
|
48 |
|
|
49 |
@SpringBeanByType
|
|
50 |
private ITermService termService;
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
@Test
|
|
55 |
public void testGetDefaultFeatureVocabulary() {
|
|
56 |
|
|
57 |
service.getDefaultFeatureVocabulary();
|
|
58 |
}
|
|
59 |
|
|
60 |
@Test
|
|
61 |
@DataSet("CommonServiceImplTest.xml")
|
|
62 |
public void testChangeDescriptionElement(){
|
|
63 |
DescriptionBase descBase = service.find(UUID.fromString("eb17b80a-9be6-4642-a6a8-b19a318925e6"));
|
|
64 |
Set<DescriptionElementBase> elements = descBase.getElements();
|
|
65 |
Iterator iterator = elements.iterator();
|
|
66 |
while (iterator.hasNext()){
|
|
67 |
DescriptionElementBase base = (DescriptionElementBase) iterator.next();
|
|
68 |
if (base instanceof TextData){
|
|
69 |
TextData textdata = (TextData) base;
|
|
70 |
Set <Entry<Language,LanguageString>> entries = textdata.getMultilanguageText().entrySet();
|
|
71 |
Iterator entryIterator = entries.iterator();
|
|
72 |
while (entryIterator.hasNext()){
|
|
73 |
Entry <Language, LanguageString> entry = (Entry<Language, LanguageString>) entryIterator.next();
|
|
74 |
LanguageString langString = entry.getValue();
|
|
77 | 75 |
// System.out.println(langString); |
78 |
langString.setText("blablubber");
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
}
|
|
83 |
service.saveOrUpdate(descBase);
|
|
84 |
Pager<DescriptionElementBase> allElements = service.getDescriptionElements(null, null, null, null, null, null);
|
|
85 |
Assert.assertEquals(1, allElements.getCount().intValue());
|
|
86 |
DescriptionElementBase test = allElements.getRecords().get(0);
|
|
87 |
if (test instanceof TextData){
|
|
88 |
|
|
89 |
Set <Entry<Language,LanguageString>> entries = ((TextData) test).getMultilanguageText().entrySet();
|
|
90 |
Iterator entryIterator = entries.iterator();
|
|
91 |
while (entryIterator.hasNext()){
|
|
92 |
Entry <Language, LanguageString> entry = (Entry<Language, LanguageString>) entryIterator.next();
|
|
93 |
LanguageString langString = entry.getValue();
|
|
76 |
langString.setText("blablubber");
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
}
|
|
81 |
service.saveOrUpdate(descBase);
|
|
82 |
Pager<DescriptionElementBase> allElements = service.getDescriptionElements(null, null, null, null, null, null);
|
|
83 |
Assert.assertEquals(1, allElements.getCount().intValue());
|
|
84 |
DescriptionElementBase test = allElements.getRecords().get(0);
|
|
85 |
if (test instanceof TextData){
|
|
86 |
|
|
87 |
Set <Entry<Language,LanguageString>> entries = ((TextData) test).getMultilanguageText().entrySet();
|
|
88 |
Iterator entryIterator = entries.iterator();
|
|
89 |
while (entryIterator.hasNext()){
|
|
90 |
Entry <Language, LanguageString> entry = (Entry<Language, LanguageString>) entryIterator.next();
|
|
91 |
LanguageString langString = entry.getValue();
|
|
94 | 92 |
// System.out.println(langString); |
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
@Test
|
|
100 |
public void testMoveDescriptionElementsToTaxon(){
|
|
101 |
UUID commonNameFeatureUuid = Feature.COMMON_NAME().getUuid();
|
|
102 |
|
|
103 |
Feature commonNameFeature = (Feature)termService.find(commonNameFeatureUuid);
|
|
104 |
|
|
105 |
TaxonDescription sourceDescription = TaxonDescription.NewInstance();
|
|
106 |
|
|
107 |
TextData element = TextData.NewInstance();
|
|
108 |
element.setFeature(commonNameFeature);
|
|
109 |
sourceDescription.addElement(element);
|
|
110 |
|
|
111 |
TextData element2 = TextData.NewInstance();
|
|
112 |
element2.setFeature(commonNameFeature);
|
|
113 |
sourceDescription.addElement(element2);
|
|
114 |
|
|
115 |
Collection<DescriptionElementBase> sourceCollection = new HashSet<DescriptionElementBase>();
|
|
116 |
sourceCollection.addAll(sourceDescription.getElements());
|
|
117 |
TextData element3 = TextData.NewInstance();
|
|
118 |
element3.setFeature(commonNameFeature);
|
|
119 |
|
|
120 |
sourceDescription.addElement(element3);
|
|
121 |
|
|
122 |
Assert.assertEquals(3, sourceDescription.getElements().size());
|
|
123 |
|
|
124 |
TaxonDescription targetDescription = TaxonDescription.NewInstance();
|
|
125 |
this.service.save(sourceDescription);
|
|
126 |
this.service.save(targetDescription);
|
|
127 |
|
|
128 |
service.moveDescriptionElementsToDescription(sourceCollection, targetDescription, false);
|
|
129 |
|
|
130 |
Assert.assertEquals("Source descirption should have 1 element left", 1, sourceDescription.getElements().size());
|
|
131 |
Assert.assertEquals("Target descriptoin should have 2 new elements", 2, targetDescription.getElements().size());
|
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
@Test
|
|
98 |
public void testMoveDescriptionElementsToTaxon(){
|
|
99 |
UUID commonNameFeatureUuid = Feature.COMMON_NAME().getUuid();
|
|
100 |
|
|
101 |
Feature commonNameFeature = (Feature)termService.find(commonNameFeatureUuid);
|
|
102 |
|
|
103 |
TaxonDescription sourceDescription = TaxonDescription.NewInstance();
|
|
104 |
|
|
105 |
TextData element = TextData.NewInstance();
|
|
106 |
element.setFeature(commonNameFeature);
|
|
107 |
sourceDescription.addElement(element);
|
|
108 |
|
|
109 |
TextData element2 = TextData.NewInstance();
|
|
110 |
element2.setFeature(commonNameFeature);
|
|
111 |
sourceDescription.addElement(element2);
|
|
112 |
|
|
113 |
Collection<DescriptionElementBase> sourceCollection = new HashSet<DescriptionElementBase>();
|
|
114 |
sourceCollection.addAll(sourceDescription.getElements());
|
|
115 |
TextData element3 = TextData.NewInstance();
|
|
116 |
element3.setFeature(commonNameFeature);
|
|
117 |
|
|
118 |
sourceDescription.addElement(element3);
|
|
119 |
|
|
120 |
Assert.assertEquals(3, sourceDescription.getElements().size());
|
|
121 |
|
|
122 |
TaxonDescription targetDescription = TaxonDescription.NewInstance();
|
|
123 |
this.service.save(sourceDescription);
|
|
124 |
this.service.save(targetDescription);
|
|
125 |
|
|
126 |
service.moveDescriptionElementsToDescription(sourceCollection, targetDescription, false);
|
|
127 |
|
|
128 |
Assert.assertEquals("Source descirption should have 1 element left", 1, sourceDescription.getElements().size());
|
|
129 |
Assert.assertEquals("Target descriptoin should have 2 new elements", 2, targetDescription.getElements().size());
|
|
132 | 130 |
//the following tests are not valid anymore as elements are cloned now even if isCopy is false |
133 | 131 |
// Assert.assertTrue("The moved element should be in the new description", targetDescription.getElements().contains(element)); |
134 | 132 |
// Assert.assertTrue("The moved element2 should be in the new description", targetDescription.getElements().contains(element2)); |
135 | 133 |
// Assert.assertFalse("Element3 should not be in the new description", targetDescription.getElements().contains(element3)); |
136 |
Assert.assertTrue("Element3 should remain in the old description", sourceDescription.getElements().contains(element3));
|
|
137 |
this.service.save(sourceDescription);
|
|
138 |
this.service.save(targetDescription);
|
|
139 |
|
|
140 |
try {
|
|
141 |
service.moveDescriptionElementsToDescription(targetDescription.getElements(), sourceDescription, false);
|
|
142 |
} catch (Exception e) {
|
|
143 |
//asserting that no ConcurrentModificationException is thrown when the elements collection is passed as a parameter
|
|
144 |
e.printStackTrace();
|
|
145 |
Assert.fail();
|
|
146 |
}
|
|
147 |
|
|
148 |
Assert.assertEquals("Source description should have 3 elements again", 3, sourceDescription.getElements().size());
|
|
149 |
Assert.assertEquals("Destination description should have no elements again", 0, targetDescription.getElements().size());
|
|
150 |
this.service.save(sourceDescription);
|
|
151 |
this.service.save(targetDescription);
|
|
152 |
|
|
153 |
//test copy
|
|
154 |
sourceCollection.clear();
|
|
155 |
sourceCollection.add(sourceDescription.getElements().iterator().next());
|
|
156 |
service.moveDescriptionElementsToDescription(sourceCollection, targetDescription, true);
|
|
157 |
|
|
158 |
Assert.assertEquals("Source description should still have 3 elements", 3, sourceDescription.getElements().size());
|
|
159 |
int size = targetDescription.getElements().size();
|
|
160 |
Assert.assertEquals("Destination descirption should have 1 element again", 1, size);
|
|
161 |
for (DescriptionElementBase targetElement : targetDescription.getElements()){
|
|
162 |
Assert.assertFalse("Target elements may not be in sourced description as they are only clones (but not same).", sourceDescription.getElements().contains(targetElement));
|
|
163 |
}
|
|
164 |
this.service.save(targetDescription);
|
|
165 |
this.service.save(sourceDescription);
|
|
166 |
|
|
167 |
|
|
168 |
}
|
|
134 |
Assert.assertTrue("Element3 should remain in the old description", sourceDescription.getElements().contains(element3));
|
|
135 |
this.service.save(sourceDescription);
|
|
136 |
this.service.save(targetDescription);
|
|
137 |
|
|
138 |
try {
|
|
139 |
service.moveDescriptionElementsToDescription(targetDescription.getElements(), sourceDescription, false);
|
|
140 |
} catch (Exception e) {
|
|
141 |
//asserting that no ConcurrentModificationException is thrown when the elements collection is passed as a parameter
|
|
142 |
e.printStackTrace();
|
|
143 |
Assert.fail();
|
|
144 |
}
|
|
145 |
|
|
146 |
Assert.assertEquals("Source description should have 3 elements again", 3, sourceDescription.getElements().size());
|
|
147 |
Assert.assertEquals("Destination description should have no elements again", 0, targetDescription.getElements().size());
|
|
148 |
this.service.save(sourceDescription);
|
|
149 |
this.service.save(targetDescription);
|
|
150 |
|
|
151 |
//test copy
|
|
152 |
sourceCollection.clear();
|
|
153 |
sourceCollection.add(sourceDescription.getElements().iterator().next());
|
|
154 |
service.moveDescriptionElementsToDescription(sourceCollection, targetDescription, true);
|
|
155 |
|
|
156 |
Assert.assertEquals("Source description should still have 3 elements", 3, sourceDescription.getElements().size());
|
|
157 |
int size = targetDescription.getElements().size();
|
|
158 |
Assert.assertEquals("Destination descirption should have 1 element again", 1, size);
|
|
159 |
for (DescriptionElementBase targetElement : targetDescription.getElements()){
|
|
160 |
Assert.assertFalse("Target elements may not be in sourced description as they are only clones (but not same).", sourceDescription.getElements().contains(targetElement));
|
|
161 |
}
|
|
162 |
this.service.save(targetDescription);
|
|
163 |
this.service.save(sourceDescription);
|
|
164 |
|
|
165 |
|
|
166 |
}
|
|
169 | 167 |
} |
Also available in: Unified diff
modifying FirstDataInserter for existing tests