use of org.powo.portal.view.Descriptions.DescriptionsBySource in project powop by RBGKew.
the class DescriptionsTest method testBySource.
@Test
public void testBySource() {
Description d2 = new Description();
Description d3 = new Description();
Organisation o2 = new Organisation();
o2.setAbbreviation("FTEA");
o2.setTitle("Flora of Tropical East Africa");
d1.setType(DescriptionType.morphologyGeneralHabit);
d1.setId(1L);
d1.setDescription("Perenial herb");
d2.setType(DescriptionType.morphologyLeaf);
d2.setId(3L);
d2.setDescription("Basal leaves");
d2.setAuthority(o1);
d3.setType(DescriptionType.morphologyReproductiveFlower);
d3.setId(2L);
d3.setDescription("Large");
d3.setAuthority(o2);
taxon.setDescriptions(ImmutableSet.<Description>of(d1, d2, d3));
Descriptions ds = new Descriptions(taxon);
Collection<DescriptionsBySource> dbs = ds.getBySource();
assertEquals(2, dbs.size());
List<String> abbreviations = new ArrayList<>();
for (DescriptionsBySource d : dbs) {
abbreviations.add(d.source.getAbbreviation());
}
assertThat(abbreviations, containsInAnyOrder("FWTA", "FTEA"));
}
use of org.powo.portal.view.Descriptions.DescriptionsBySource in project powop by RBGKew.
the class DescriptionsTest method testMultiTypeDescriptions.
@Test
public void testMultiTypeDescriptions() {
d1.setTypes(ImmutableSortedSet.<DescriptionType>of(useAnimalFoodBees, morphologyReproductiveFlower));
d1.setDescription("BEES!!!");
taxon.setDescriptions(ImmutableSet.<Description>of(d1));
Descriptions uses = new Descriptions(taxon, true);
for (DescriptionsBySource dbs : uses.getBySource()) {
for (DescriptionsByType dbt : dbs.byType) {
assertEquals("useAnimalFoodBees", dbt.type);
}
}
// Data tagged with use should not show up in the morphological descriptions
Descriptions desc = new Descriptions(taxon);
assertEquals(0, desc.getBySource().size());
}
use of org.powo.portal.view.Descriptions.DescriptionsBySource in project powop by RBGKew.
the class DescriptionsTest method testSynonymDescriptions.
@Test
public void testSynonymDescriptions() {
Description d2 = new Description();
Taxon synonym = new Taxon();
synonym.setScientificName("Eucalypton");
synonym.setTaxonomicStatus(TaxonomicStatus.Synonym);
d1.setType(DescriptionType.morphologyGeneral);
d1.setDescription("accepted description");
d2.setAuthority(o1);
d2.setType(DescriptionType.morphologyGeneralHabit);
d2.setDescription("synonym description");
synonym.setDescriptions(ImmutableSet.<Description>of(d2));
taxon.setDescriptions(ImmutableSet.<Description>of(d1));
taxon.setSynonymNameUsages(ImmutableSet.<Taxon>of(synonym));
Descriptions ds = new Descriptions(taxon);
for (DescriptionsBySource dbs : ds.getBySource()) {
if (dbs.asTaxon.getScientificName().equals("Eucalypton")) {
assertEquals(d2, dbs.byType.get(0).descriptions.get(0));
} else {
assertEquals(d1, dbs.byType.get(0).descriptions.get(0));
}
}
}
use of org.powo.portal.view.Descriptions.DescriptionsBySource in project powop by RBGKew.
the class DescriptionsTest method print.
private void print(Descriptions descriptions) {
for (DescriptionsBySource dbs : descriptions.getBySource()) {
System.out.print("{" + dbs.source.getTitle() + " as " + dbs.asTaxon.getScientificName() + ": ");
for (DescriptionsByType dbt : dbs.byType) {
System.out.print(dbt.type + " [");
for (Description d : dbt.descriptions) {
System.out.print(d.getDescription() + " ");
}
System.out.print("] ");
}
System.out.println("}");
}
}
use of org.powo.portal.view.Descriptions.DescriptionsBySource in project powop by RBGKew.
the class DescriptionsTest method testOrderingByDescriptionId.
@Test
public void testOrderingByDescriptionId() {
Description d2 = new Description();
Description d3 = new Description();
d1.setType(DescriptionType.morphologyGeneralHabit);
d1.setId(1L);
d1.setDescription("Perenial herb");
d2.setType(DescriptionType.morphologyLeaf);
d2.setId(3L);
d2.setDescription("Basal leaves");
d2.setAuthority(o1);
d3.setType(DescriptionType.morphologyReproductiveFlower);
d3.setId(2L);
d3.setDescription("Large");
d3.setAuthority(o1);
taxon.setDescriptions(ImmutableSet.<Description>of(d1, d2, d3));
Descriptions ds = new Descriptions(taxon);
print(ds);
DescriptionsBySource dbs = Iterators.getOnlyElement(ds.getBySource().iterator());
assertEquals(d1.getType().toString(), dbs.byType.get(0).type);
assertEquals(d3.getType().toString(), dbs.byType.get(1).type);
assertEquals(d2.getType().toString(), dbs.byType.get(2).type);
}
Aggregations