Project

General

Profile

Revision c56f0e4a

IDc56f0e4ade68ab3b779cc1f7b23778e302764c96
Parent bfc6a038
Child 7c52e886

Added by Andreas Müller about 3 years ago

ref #6965 fix TropicosNameImportTest

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/in/CsvImportBase.java
189 189
            String title = state.getConfig().getSourceNameString();
190 190
            sourceRef.setTitle(title);
191 191
            state.getConfig().setSourceReference(sourceRef);
192
            //we do not save here as we expect the reference to be cascaded
192
        }
193
        if (sourceRef.getId() == 0){
194
            //TODO move to base method for saving
195
            getReferenceService().saveOrUpdate(sourceRef);
196
            state.getResult().addNewRecords(Reference.class.getSimpleName(), 1);
193 197
        }
194 198
        state.setSourceReference(sourceRef);
195 199

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tropicos/in/TropicosNameImport.java
116 116
        state.getDedupHelper().replaceAuthorNamesAndNomRef(state, name);
117 117

  
118 118
        getNameService().saveOrUpdate(name);
119
        state.getResult().addNewRecords(TaxonName.class.getSimpleName(), 1);
120

  
119 121
        makeTaxon(state, name);
122

  
120 123
    }
121 124

  
122 125

  
......
361 364
            }
362 365
            addSourceReference(state, taxon);
363 366
            this.getTaxonService().saveOrUpdate(taxon);
367
            state.getResult().addNewRecords(Taxon.class.getSimpleName(), 1);
368

  
364 369
        }
365 370
    }
366 371

  
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/tropicos/TropicosNameImportTest.java
16 16

  
17 17
import org.junit.Assert;
18 18
import org.junit.Before;
19
import org.junit.Ignore;
19 20
import org.junit.Test;
20 21
import org.unitils.dbunit.annotation.DataSet;
21 22
import org.unitils.spring.annotation.SpringBeanByName;
22 23
import org.unitils.spring.annotation.SpringBeanByType;
23 24

  
24 25
import eu.etaxonomy.cdm.api.service.INameService;
26
import eu.etaxonomy.cdm.api.service.ITaxonService;
25 27
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
26 28
import eu.etaxonomy.cdm.io.common.ImportResult;
27 29
import eu.etaxonomy.cdm.io.tropicos.in.TropicosNameImportConfigurator;
28 30
import eu.etaxonomy.cdm.model.name.TaxonName;
29 31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 33
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
31 34
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
32 35

  
36

  
33 37
/**
34 38
 * @author a.mueller
35 39
 * @date 15.11.2017
......
43 47
    @SpringBeanByType
44 48
    private INameService nameService;
45 49

  
50
    @SpringBeanByType
51
    private ITaxonService taxonService;
46 52

  
47
    private TropicosNameImportConfigurator configurator;
53
    private TropicosNameImportConfigurator configShort;
48 54
    private TropicosNameImportConfigurator configLong;
49 55

  
50 56
    @Before
......
59 65
            URL urlLong = this.getClass().getResource(inputFileLong);
60 66
            assertNotNull("URL for the test file '" + inputFileLong + "' does not exist", urlLong);
61 67

  
62
            configurator = TropicosNameImportConfigurator.NewInstance(url.toURI(), null);
68
            configShort = TropicosNameImportConfigurator.NewInstance(url.toURI(), null);
63 69
            configLong = TropicosNameImportConfigurator.NewInstance(urlLong.toURI(), null);
64 70

  
65 71

  
......
67 73
            e.printStackTrace();
68 74
            Assert.fail();
69 75
        }
70
        assertNotNull("Configurator could not be created", configurator);
76
        assertNotNull("Configurator could not be created", configShort);
71 77
        assertNotNull("Configurator could not be created", configLong);
72 78
        assertNotNull("nameService should not be null", nameService);
73 79
    }
......
78 84
    @DataSet( value="/eu/etaxonomy/cdm/database/BlankDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
79 85
    //@Ignore
80 86
    public void testShort() {
81

  
82
        ImportResult result = defaultImport.invoke(configurator);
87
        configShort.setCreateTaxa(true);
88
        ImportResult result = defaultImport.invoke(configShort);
83 89
        String report = result.createReport().toString();
84
        Assert.assertTrue(report.length() > 0);
85
        System.out.println(report);
90

  
91

  
86 92

  
87 93
        Integer expected = 2;
88 94
        Assert.assertEquals(expected, result.getNewRecords(TaxonName.class));
89 95

  
96
        Assert.assertTrue(report.length() > 0);
97
        System.out.println(report);
98

  
90 99
        List<TaxonName> list = nameService.list(TaxonName.class, null, null, null, null);
91
        Assert.assertEquals("There should be 3 references, the article and the journal and the source reference",
92
                3, list.size());
100
        Assert.assertEquals("There should be 2 new taxon names", 2, list.size());
93 101
        for (TaxonName name : list){
94
//            Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
95
//            if (ref.getType() == ReferenceType.Article){
96
//                //title
97
//                Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
98
//                        ref.getTitle());
99
//                //author
100
//                TeamOrPersonBase<?> author = ref.getAuthorship();
101
//                Assert.assertNotNull(author);
102
//                Assert.assertTrue(author.isInstanceOf(Person.class));
103
//                Person person = CdmBase.deproxy(author, Person.class);
104
//                //this may change in future depending on the correct formatting strategy
105
//                Assert.assertEquals("Jongkind, C.C.H." ,person.getTitleCache());
106
//                Assert.assertEquals("Jongkind" ,person.getLastname());
107
//                Assert.assertEquals("Carel C. H." ,person.getFirstname());
108
//                //date
109
//                TimePeriod date = ref.getDatePublished();
110
//                Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
111
//                //vol
112
//                Assert.assertEquals("47(1)" ,ref.getVolume());
113
//                Assert.assertEquals("43-47" ,ref.getPages());
114
//
115
//                //doi
116
//                //Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
117
//
118
//                //Abstract
119
//                Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
120
//                        ref.getReferenceAbstract());
121
//
122
//                //TODO still missing Y1, Y2, M3, UR
123
//
124
//            }else if (ref.getType() == ReferenceType.Journal){
125
//                Assert.assertEquals("Willdenowia", ref.getTitle());
126
//                //or is this part of article?
127
//                Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
128
//
129
//                //ISSN
130
//                Assert.assertEquals("0511-9618" ,ref.getIssn());
131
//
132
//            }else{
133
//                Assert.fail("Only an article and a journal should exist");
134
//            }
102
            //TODO
135 103
        }
136 104

  
105
        expected = 1;
106
        Assert.assertEquals(expected, result.getNewRecords(Reference.class));
137 107
    }
138 108

  
139 109
    @Test
110
    @DataSet( value="/eu/etaxonomy/cdm/database/BlankDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
140 111
    //@Ignore
112
    public void testShortCreateTaxa() {
113
        configShort.setCreateTaxa(true);
114
        ImportResult result = defaultImport.invoke(configShort);
115

  
116
        Integer expected = 2;
117
        Assert.assertEquals(expected, result.getNewRecords(Taxon.class));
118

  
119
        List<Taxon> list = taxonService.list(Taxon.class, null, null, null, null);
120
        Assert.assertEquals("There should be 2 new taxa", 2, list.size());
121
    }
122

  
123
    @Test
124
    @Ignore
141 125
    public void testLongFile() {
142 126
        ImportResult result = defaultImport.invoke(configLong);
143 127
        String report = result.createReport().toString();
......
146 130
        Integer expected = 118;  //did not count yet
147 131
        Assert.assertEquals(expected, result.getNewRecords(Reference.class));
148 132

  
149
//        List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
150
//        Assert.assertEquals("There should be 2 references, the article and the journal", 2, list.size());
151
//        for (Reference ref : list){
152
//            Assert.assertTrue(ref.getType() == ReferenceType.Article || ref.getType() == ReferenceType.Journal);
153
//            if (ref.getType() == ReferenceType.Article){
154
//                //title
155
//                Assert.assertEquals("Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea",
156
//                        ref.getTitle());
157
//                //author
158
//                TeamOrPersonBase<?> author = ref.getAuthorship();
159
//                Assert.assertNotNull(author);
160
//                Assert.assertTrue(author.isInstanceOf(Person.class));
161
//                Person person = CdmBase.deproxy(author, Person.class);
162
//                //this may change in future depending on the correct formatting strategy
163
//                Assert.assertEquals("Carel C. H. Jongkind" ,person.getTitleCache());
164
//                Assert.assertEquals("Jongkind" ,person.getLastname());
165
//                Assert.assertEquals("Carel C. H." ,person.getFirstname());
166
//                //date
167
//                TimePeriod date = ref.getDatePublished();
168
//                Assert.assertEquals(Integer.valueOf(2017) ,date.getStartYear());
169
//                //vol
170
//                Assert.assertEquals("47(1)" ,ref.getVolume());
171
//                Assert.assertEquals("43-47" ,ref.getPages());
172
//
173
//                //doi
174
//                Assert.assertEquals(DOI.fromString("10.3372/wi.47.47105"),ref.getDoi());
175
//
176
//                //Abstract
177
//                Assert.assertEquals("Abstract: A new species of Violaceae, Decorsella arborea Jongkind, is described and illustrated. The new species differs from the only other species in the genus, D. paradoxa A. Chev., by the larger size of the plants, smaller leaves, more slender flowers, and stamen filaments that are free for a much larger part. Both species are from the Guineo-Congolian forest of tropical Africa. The differences between Decorsella and Rinorea are discussed. Confirming recent reports, some species of Rinorea can have zygomorphic flowers and some of these can be almost equal in shape to Decorsella flowers. Citation: Jongkind C. C. H. 2017: Decorsella arborea, a second species in Decorsella (Violaceae), and Decorsella versus Rinorea. ? Willdenowia 47: 43?47. doi: https://doi.org/10.3372/wi.47.47105 Version of record first published online on 13 February 2017 ahead of inclusion in April 2017 issue.",
178
//                        ref.getReferenceAbstract());
179
//
180
//                //TODO still missing Y1, Y2, M3, UR
181
//
182
//            }else if (ref.getType() == ReferenceType.Journal){
183
//                Assert.assertEquals("Willdenowia", ref.getTitle());
184
//                //or is this part of article?
185
//                Assert.assertEquals("Botanic Garden and Botanical Museum Berlin (BGBM)", ref.getPublisher());
186
//
187
//                //ISSN
188
//                Assert.assertEquals("0511-9618" ,ref.getIssn());
189
//
190
//            }else{
191
//                Assert.fail("Only an article and a journal should exist");
192
//            }
193
//        }
133

  
194 134

  
195 135
    }
196 136

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)