001/* 002 * Copyright 2021 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.dwc.terms; 017 018import java.util.HashSet; 019import java.util.List; 020 021import org.junit.jupiter.api.Test; 022 023import static org.junit.jupiter.api.Assertions.assertEquals; 024import static org.junit.jupiter.api.Assertions.assertFalse; 025import static org.junit.jupiter.api.Assertions.assertTrue; 026 027public class DwcTermTest extends TermBaseTest<DwcTerm> { 028 029 public DwcTermTest() { 030 super(DwcTerm.class); 031 } 032 033 @Test 034 public void testClassTerm() { 035 assertEquals("class", DwcTerm.class_.simpleName()); 036 assertEquals("http://rs.tdwg.org/dwc/terms/class", DwcTerm.class_.qualifiedName()); 037 038 assertEquals("order", DwcTerm.order.simpleName()); 039 assertEquals("http://rs.tdwg.org/dwc/terms/order", DwcTerm.order.qualifiedName()); 040 } 041 042 @Test 043 public void testIsClass() { 044 assertTrue(DwcTerm.Taxon.isClass()); 045 assertTrue(DwcTerm.Event.isClass()); 046 assertFalse(DwcTerm.scientificName.isClass()); 047 } 048 049 @Test 050 public void testNumberOfGroups() { 051 assertEquals(12, DwcTerm.GROUPS.length); 052 } 053 054 /** 055 * Test each group contains the expected number of terms, and contains no duplicates. 056 */ 057 @Test 058 public void testListByGroup() { 059 List<DwcTerm> occurrenceTerms = DwcTerm.listByGroup(DwcTerm.GROUP_OCCURRENCE); 060 assertEquals(26, occurrenceTerms.size()); 061 assertEquals(26, new HashSet<>(occurrenceTerms).size()); 062 063 List<DwcTerm> organismTerms = DwcTerm.listByGroup(DwcTerm.GROUP_ORGANISM); 064 assertEquals(7, organismTerms.size()); 065 assertEquals(7, new HashSet<>(organismTerms).size()); 066 067 List<DwcTerm> materialTerms = DwcTerm.listByGroup(DwcTerm.GROUP_MATERIAL_ENTITY); 068 assertEquals(7, materialTerms.size()); 069 assertEquals(7, new HashSet<>(materialTerms).size()); 070 071 List<DwcTerm> sampleTerms = DwcTerm.listByGroup(DwcTerm.GROUP_MATERIAL_SAMPLE); 072 assertEquals(2, sampleTerms.size()); 073 assertEquals(2, new HashSet<>(sampleTerms).size()); 074 075 List<DwcTerm> eventTerms = DwcTerm.listByGroup(DwcTerm.GROUP_EVENT); 076 assertEquals(20, eventTerms.size()); 077 assertEquals(20, new HashSet<>(eventTerms).size()); 078 079 List<DwcTerm> locationTerms = DwcTerm.listByGroup(DwcTerm.GROUP_LOCATION); 080 assertEquals(44, locationTerms.size()); 081 assertEquals(44, new HashSet<>(locationTerms).size()); 082 083 List<DwcTerm> geologicalTerms = DwcTerm.listByGroup(DwcTerm.GROUP_GEOLOGICALCONTEXT); 084 assertEquals(19, geologicalTerms.size()); 085 assertEquals(19, new HashSet<>(geologicalTerms).size()); 086 087 List<DwcTerm> identificationTerms = DwcTerm.listByGroup(DwcTerm.GROUP_IDENTIFICATION); 088 assertEquals(11, identificationTerms.size()); 089 assertEquals(11, new HashSet<>(identificationTerms).size()); 090 091 List<DwcTerm> taxonTerms = DwcTerm.listByGroup(DwcTerm.GROUP_TAXON); 092 assertEquals(41, taxonTerms.size()); 093 assertEquals(41, new HashSet<>(taxonTerms).size()); 094 095 List<DwcTerm> measurementTerms = DwcTerm.listByGroup(DwcTerm.GROUP_MEASUREMENTORFACT); 096 assertEquals(11, measurementTerms.size()); 097 assertEquals(11, new HashSet<>(measurementTerms).size()); 098 099 List<DwcTerm> relationshipTerms = DwcTerm.listByGroup(DwcTerm.GROUP_RESOURCERELATIONSHIP); 100 assertEquals(9, relationshipTerms.size()); 101 assertEquals(9, new HashSet<>(relationshipTerms).size()); 102 103 List<DwcTerm> recordTerms = DwcTerm.listByGroup("Record"); 104 assertEquals(11, recordTerms.size()); 105 assertEquals(11, new HashSet<>(recordTerms).size()); 106 107 List<DwcTerm> randomTerms = DwcTerm.listByGroup("Random"); 108 assertEquals(0, randomTerms.size()); 109 assertEquals(0, new HashSet<>(randomTerms).size()); 110 } 111 112 @Test 113 public void testGroupCoverage() { 114 HashSet<DwcTerm> arrayTerms = new HashSet<>(); 115 for (DwcTerm t : DwcTerm.TAXONOMIC_TERMS) { 116 arrayTerms.add(t); 117 assertFalse(t.isClass()); 118 assertEquals(DwcTerm.GROUP_TAXON, t.getGroup()); 119 } 120 121 for (DwcTerm t : DwcTerm.listByGroup(DwcTerm.GROUP_TAXON)) { 122 if (!arrayTerms.contains(t) && !t.isClass()) { 123 assertTrue(arrayTerms.contains(t), "Missing taxonomic term in DwcTerm.TAXONOMIC_TERMS: " + t.qualifiedName()); 124 } 125 } 126 } 127 128}