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 org.junit.jupiter.api.Test; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertFalse; 022 023public class DcElementTest { 024 025 private static final TermFactory TERM_FACTORY = TermFactory.instance(); 026 027 @Test 028 public void testNames() { 029 for (DcElement t : DcElement.values()) { 030 assertFalse(t.simpleName().contains("_"), "Bad term: " + t.simpleName()); 031 assertFalse(t.qualifiedName().contains("_"), "Bad term: " + t.qualifiedName()); 032 assertFalse(t.isClass(), "Bad term: " + t.qualifiedName()); 033 } 034 } 035 036 /** 037 * Test that iterates over all DcElement values and uses the qualified name alone as input to the factory and then 038 * verifies the Term returned is the same as the original one. 039 */ 040 @Test 041 public void testTermEquality() { 042 for (DcTerm t : DcTerm.values()) { 043 assertEquals(t, TERM_FACTORY.findTerm(t.qualifiedName())); 044 } 045 } 046 047 /** 048 * A lookup for "http://purl.org/dc/elements/1.1/rights" shouldn't return "http://purl.org/dc/terms/rights" 049 */ 050 @Test 051 public void testFindTermWithValidNamespace() { 052 String qualifiedName = "http://purl.org/dc/elements/1.1/rights"; 053 Term term = TERM_FACTORY.findTerm(qualifiedName); 054 assertEquals(qualifiedName, term.qualifiedName()); 055 } 056 057 /** 058 * There are 15 terms in DcElement that share the same name with DcTerm elements. This test ensures, that 059 * when a term lookup is done with the prefix "dc", the DcElement under the /elements/1.1/ namespace 060 * is returned, not the DcTerm under the /terms namespace. 061 */ 062 @Test 063 public void testFindTermWithDcPrefix() { 064 String name = "dc:rights"; 065 Term term = TERM_FACTORY.findTerm(name); 066 assertEquals("http://purl.org/dc/elements/1.1/rights", term.qualifiedName()); 067 } 068}