001/*
002 * Copyright 2020 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.api.model.crawler;
017
018import org.junit.jupiter.api.Test;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021import static org.junit.jupiter.api.Assertions.assertFalse;
022import static org.junit.jupiter.api.Assertions.assertNull;
023import static org.junit.jupiter.api.Assertions.assertTrue;
024
025public class OccurrenceValidationReportTest {
026
027  @Test
028  public void testEmpty() {
029    OccurrenceValidationReport report = new OccurrenceValidationReport(0, 0, 0, 0, 0, true);
030    assertNull(report.getInvalidationReason());
031    assertTrue(report.isValid());
032  }
033
034  @Test
035  public void testGoodTripletsNoOccId() {
036    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 100, 0, 0, 100, true);
037    assertNull(report.getInvalidationReason());
038    assertTrue(report.isValid());
039  }
040
041  @Test
042  public void testMissingTripletsGoodOccId() {
043    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 0, 100, 100, 0, true);
044    assertNull(report.getInvalidationReason());
045    assertTrue(report.isValid());
046  }
047
048  @Test
049  public void testDuplicateTripletsGoodOccId() {
050    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 80, 0, 100, 0, true);
051    assertNull(report.getInvalidationReason());
052    assertTrue(report.isValid());
053  }
054
055  @Test
056  public void testMissingTripletsNoOccId() {
057    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 70, 30, 0, 100, true);
058    assertFalse(report.isValid());
059    assertEquals(
060      "Archive invalid because [30% invalid triplets is > than threshold of 25%; 100 records without an occurrence id "
061      + "(should be 0)]",
062      report.getInvalidationReason());
063  }
064
065  @Test
066  public void testDuplicateTripletsNoOccId() {
067    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 80, 0, 0, 100, false);
068    assertEquals(
069      "Archive invalid because [20 duplicate triplets detected; 100 records without an occurrence id (should be 0)]",
070      report.getInvalidationReason());
071    assertFalse(report.isValid());
072  }
073
074  @Test
075  public void testBadEverything() {
076    OccurrenceValidationReport report = new OccurrenceValidationReport(100, 50, 28, 80, 5, true);
077    assertEquals(
078      "Archive invalid because [28% invalid triplets is > than threshold of 25%; 22 duplicate triplets detected; 5 "
079      + "records without an occurrence id (should be 0); 15 duplicate occurrence ids detected]",
080      report.getInvalidationReason());
081    assertFalse(report.isValid());
082  }
083}