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 GbifTermTest extends TermBaseTest<GbifTerm> {
028
029  public GbifTermTest() {
030    super(GbifTerm.class);
031  }
032
033  @Test
034  public void testTerm() {
035    assertEquals("taxonKey", GbifTerm.taxonKey.simpleName());
036    assertEquals("http://rs.gbif.org/terms/1.0/taxonKey", GbifTerm.taxonKey.qualifiedName());
037
038    assertEquals("lastInterpreted", GbifTerm.lastInterpreted.simpleName());
039    assertEquals("http://rs.gbif.org/terms/1.0/lastInterpreted", GbifTerm.lastInterpreted.qualifiedName());
040  }
041
042  @Test
043  public void testIsClass() {
044    assertTrue(GbifTerm.VernacularName.isClass());
045    assertTrue(GbifTerm.Distribution.isClass());
046    assertFalse(GbifTerm.datasetKey.isClass());
047  }
048
049  @Test
050  public void testNumberOfGroups() {
051    assertEquals(9, GbifTerm.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<GbifTerm> datasetTerms = GbifTerm.listByGroup(GbifTerm.GROUP_DATASET);
060    assertEquals(2, datasetTerms.size());
061    assertEquals(2, new HashSet<>(datasetTerms).size());
062
063    List<GbifTerm> occurrenceTerms = GbifTerm.listByGroup(DwcTerm.GROUP_OCCURRENCE);
064    assertEquals(16, occurrenceTerms.size());
065    assertEquals(16, new HashSet<>(occurrenceTerms).size());
066
067    List<GbifTerm> locationTerms = GbifTerm.listByGroup(DwcTerm.GROUP_LOCATION);
068    assertEquals(9, locationTerms.size());
069    assertEquals(9, new HashSet<>(locationTerms).size());
070
071    List<GbifTerm> rowTerms = GbifTerm.listByGroup(GbifTerm.GROUP_ROW_TYPE);
072    assertEquals(9, rowTerms.size());
073    assertEquals(9, new HashSet<>(rowTerms).size());
074
075    List<GbifTerm> distributionTerms = GbifTerm.listByGroup(GbifTerm.GROUP_SPECIES_DISTRIBUTION_EXTENSION);
076    assertEquals(2, distributionTerms.size());
077    assertEquals(2, new HashSet<>(distributionTerms).size());
078
079    List<GbifTerm> profileTerms = GbifTerm.listByGroup(GbifTerm.GROUP_SPECIES_PROFILE_EXTENSION);
080    assertEquals(10, profileTerms.size());
081    assertEquals(10, new HashSet<>(profileTerms).size());
082
083    List<GbifTerm> taxonTerms = GbifTerm.listByGroup(DwcTerm.GROUP_TAXON);
084    assertEquals(15, taxonTerms.size());
085    assertEquals(15, new HashSet<>(taxonTerms).size());
086
087    List<GbifTerm> crawlingTerms = GbifTerm.listByGroup(GbifTerm.GROUP_CRAWLING);
088    assertEquals(3, crawlingTerms.size());
089    assertEquals(3, new HashSet<>(crawlingTerms).size());
090
091    List<GbifTerm> vernacularTerms = GbifTerm.listByGroup(GbifTerm.GROUP_VERNACULAR_NAME_EXTENSION);
092    assertEquals(3, vernacularTerms.size());
093    assertEquals(3, new HashSet<>(vernacularTerms).size());
094  }
095
096  @Test
097  public void testGroupCoverage() {
098    HashSet<GbifTerm> arrayTerms = new HashSet<>();
099    for (GbifTerm t : GbifTerm.TAXONOMIC_TERMS) {
100      arrayTerms.add(t);
101      assertFalse(t.isClass());
102      assertEquals(DwcTerm.GROUP_TAXON, t.getGroup());
103    }
104
105    for (GbifTerm t : GbifTerm.listByGroup(DwcTerm.GROUP_TAXON)) {
106      if (!arrayTerms.contains(t)) {
107        assertTrue(arrayTerms.contains(t), "Missing taxonomic term in GbifTerm.TAXONOMIC_TERMS: " + t.qualifiedName());
108      }
109    }
110  }
111
112  @Test
113  public void testDeprecated() {
114    assertFalse(GbifTerm.gbifID.isDeprecated());
115    assertTrue(GbifTerm.coordinateAccuracy.isDeprecated());
116  }
117}