Project

General

Profile

« Previous | Next » 

Revision 8e53bbac

Added by Andreas Müller over 2 years ago

ref #9888 add book section handling to RIS import

View differences:

cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/referenceris/in/RisReferenceImportTest.java
11 11
import static org.junit.Assert.assertNotNull;
12 12

  
13 13
import java.io.FileNotFoundException;
14
import java.io.IOException;
14 15
import java.net.URL;
15 16
import java.util.List;
16 17

  
......
27 28
import eu.etaxonomy.cdm.io.common.ImportResult;
28 29
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
29 30
import eu.etaxonomy.cdm.model.agent.Person;
31
import eu.etaxonomy.cdm.model.agent.Team;
30 32
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
31 33
import eu.etaxonomy.cdm.model.common.CdmBase;
32 34
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
......
137 139
		        Assert.fail("Only an article and a journal should exist");
138 140
		    }
139 141
		}
142
	}
143

  
144
	@Test
145
	public void testChapter() throws IOException{
146
        String inputFileLong = "/eu/etaxonomy/cdm/io/reference/ris/in/Arias2012.ris";
147
        URL urlLong = this.getClass().getResource(inputFileLong);
148
        configurator = RisReferenceImportConfigurator.NewInstance(urlLong, null);
149

  
150
        ImportResult result = defaultImport.invoke(configurator);
151
        String report = result.createReport().toString();
152
        Assert.assertTrue(report.contains("Reference: 2"));
153
        Assert.assertEquals(0, result.getErrors().size() + result.getExceptions().size() + result.getWarnings().size());
154

  
155
        Integer expected = 2;
156
        Assert.assertEquals(expected, result.getNewRecords(Reference.class));
157

  
158
        List<Reference> list = referenceService.list(Reference.class, null, null, null, null);
159
        Assert.assertEquals("There should be 3 references, the book-section, the book and the source reference",
160
                3, list.size());
161

  
162
        //book section
163
        Reference bookSection = list.stream().filter(r->r.getType() == ReferenceType.BookSection).findFirst().get();
164
        //... title
165
        Assert.assertEquals("Cactaceae", bookSection.getTitle());
166
        //... author
167
        TeamOrPersonBase<?> author = bookSection.getAuthorship();
168
        Assert.assertNotNull(author);
169
        Team team = CdmBase.deproxy(author, Team.class);
170
        Assert.assertEquals(4, team.getTeamMembers().size());
171
        Person firstPerson = CdmBase.deproxy(team.getTeamMembers().get(0));
172
        //this may change in future depending on the correct formatting strategy
173
        Assert.assertEquals("Arias, S." , firstPerson.getTitleCache());
174
        Assert.assertEquals("Arias" , firstPerson.getFamilyName());
175
        Assert.assertNull(firstPerson.getGivenName());
176
        Assert.assertEquals("S." , firstPerson.getInitials());
177
        Person secondPerson = CdmBase.deproxy(team.getTeamMembers().get(1));
178
        Assert.assertEquals("Gama-L\u00F3pez, S." , secondPerson.getTitleCache());
179
        VerbatimTimePeriod date = bookSection.getDatePublished();
180
        Assert.assertEquals(Integer.valueOf(2012), date.getStartYear());
181
        //TODO correct?
182
        Assert.assertEquals("1-235", bookSection.getPages());
183

  
184
        //book
185
        Reference book = list.stream().filter(r->r.getType() == ReferenceType.Book).findFirst().get();
186
        //... title
187
        Assert.assertEquals("Flora del Valle de Tehuac\u00E1n-Cuicatl\u00E1n", book.getTitle());
188
        Assert.assertEquals("Fasc\u00EDculo 95", book.getVolume());
189
        Assert.assertEquals("M\u00E9xico D. F.", book.getPlacePublished());
190
        Assert.assertEquals("Instituto de Biolog\u00EDa, Universidad Nacional Aut\u00F3noma de M\u00E9xico", book.getPublisher());
191

  
192
        //source reference
193
        Reference sourceRef = list.stream().filter(r->r.equals(configurator.getSourceReference())).findFirst().get();
194
        Assert.assertNotNull(sourceRef);
195
        //TODO cont.
140 196

  
141 197
	}
142 198

  

Also available in: Unified diff