001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014package org.gbif.api.util.comparators; 015 016import org.gbif.api.model.registry.Endpoint; 017import org.gbif.api.vocabulary.EndpointType; 018 019import org.junit.jupiter.api.Test; 020 021import static org.junit.jupiter.api.Assertions.assertEquals; 022import static org.junit.jupiter.api.Assertions.assertThrows; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025@SuppressWarnings("ResultOfMethodCallIgnored") 026public class EndpointPriorityComparatorTest { 027 028 private static final EndpointPriorityComparator COMP = new EndpointPriorityComparator(); 029 030 @Test 031 public void testSuccessfulSimpleComparisons() { 032 Endpoint e1 = new Endpoint(); 033 Endpoint e2 = new Endpoint(); 034 035 e1.setType(EndpointType.TAPIR); 036 e2.setType(EndpointType.BIOCASE); 037 assertTrue(COMP.compare(e1, e2) > 0); 038 039 e1.setType(EndpointType.BIOCASE); 040 e2.setType(EndpointType.BIOCASE); 041 assertEquals(0, COMP.compare(e1, e2)); 042 043 e1.setType(EndpointType.BIOCASE); 044 e2.setType(EndpointType.TAPIR); 045 assertTrue(COMP.compare(e1, e2) < 0); 046 047 e1.setType(EndpointType.BIOCASE); 048 e2.setType(EndpointType.DIGIR_MANIS); 049 assertTrue(COMP.compare(e1, e2) > 0); 050 051 e1.setType(EndpointType.DWC_ARCHIVE); 052 e2.setType(EndpointType.TAPIR); 053 assertTrue(COMP.compare(e1, e2) > 0); 054 055 e1.setType(EndpointType.BIOCASE_XML_ARCHIVE); 056 e2.setType(EndpointType.BIOCASE); 057 assertTrue(COMP.compare(e1, e2) > 0); 058 059 e1.setType(EndpointType.DWC_ARCHIVE); 060 e2.setType(EndpointType.BIOCASE_XML_ARCHIVE); 061 assertTrue(COMP.compare(e1, e2) > 0); 062 } 063 064 @Test 065 public void testPriorityComparisons() { 066 Endpoint e1 = new Endpoint(); 067 Endpoint e2 = new Endpoint(); 068 069 e1.setType(EndpointType.TAPIR); 070 e2.setType(EndpointType.BIOCASE); 071 assertTrue(COMP.compare(e1, e2) > 0); 072 073 e1.setType(EndpointType.DIGIR_MANIS); 074 e2.setType(EndpointType.DIGIR_MANIS); 075 assertEquals(0, COMP.compare(e1, e2)); 076 077 e1.setType(EndpointType.CAMTRAP_DP); 078 e2.setType(EndpointType.DWC_ARCHIVE); 079 assertTrue(COMP.compare(e1, e2) > 0); 080 } 081 082 @Test 083 public void testInvalidComparison1() { 084 Endpoint e1 = new Endpoint(); 085 Endpoint e2 = new Endpoint(); 086 087 e1.setType(EndpointType.TAPIR); 088 e2.setType(EndpointType.WMS); 089 assertThrows(ClassCastException.class, () -> COMP.compare(e1, e2)); 090 } 091 092 @Test 093 public void testInvalidComparison2() { 094 Endpoint e1 = new Endpoint(); 095 Endpoint e2 = new Endpoint(); 096 097 e1.setType(EndpointType.WMS); 098 e2.setType(EndpointType.TAPIR); 099 assertThrows(ClassCastException.class, () -> COMP.compare(e1, e2)); 100 } 101}