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.gbif.api.vocabulary.EndpointType; 019 020import java.io.IOException; 021import java.net.URI; 022import java.util.Date; 023import java.util.UUID; 024 025import org.junit.jupiter.api.Test; 026 027import com.fasterxml.jackson.databind.ObjectMapper; 028 029import static org.junit.jupiter.api.Assertions.assertEquals; 030 031public class DatasetProcessStatusTest { 032 033 @Test 034 public void testEquals() throws IOException { 035 UUID uuid = UUID.randomUUID(); 036 Date now = new Date(); 037 DatasetProcessStatus s1 = DatasetProcessStatus.builder() 038 .datasetKey(uuid) 039 .startedCrawling(now) 040 .crawlJob(new CrawlJob(uuid, EndpointType.BIOCASE, URI.create("http://www.foo.com"), 1, null)) 041 .crawlContext("foo") 042 .processStateOccurrence(ProcessState.RUNNING) 043 .processStateChecklist(ProcessState.EMPTY) 044 .declaredCount(100L) 045 .pagesCrawled(10L) 046 .pagesFragmentedSuccessful(11L) 047 .pagesFragmentedError(12L) 048 .fragmentsEmitted(13L) 049 .fragmentsReceived(14L) 050 .fragmentsProcessed(15L) 051 .rawOccurrencesPersistedNew(16L) 052 .rawOccurrencesPersistedUnchanged(17L) 053 .rawOccurrencesPersistedUpdated(18L) 054 .rawOccurrencesPersistedError(19L) 055 .verbatimOccurrencesPersistedSuccessful(20L) 056 .verbatimOccurrencesPersistedError(21L) 057 .interpretedOccurrencesPersistedSuccessful(22L) 058 .interpretedOccurrencesPersistedError(23L) 059 .build(); 060 061 DatasetProcessStatus s2 = DatasetProcessStatus.builder() 062 .datasetKey(uuid) 063 .startedCrawling(new Date(now.getTime())) 064 .crawlJob(new CrawlJob(uuid, EndpointType.BIOCASE, URI.create("http://www.foo.com"), 1, null)) 065 .crawlContext("foo") 066 .processStateOccurrence(ProcessState.RUNNING) 067 .processStateChecklist(ProcessState.EMPTY) 068 .declaredCount(100L) 069 .pagesCrawled(10L) 070 .pagesFragmentedSuccessful(11L) 071 .pagesFragmentedError(12L) 072 .fragmentsEmitted(13L) 073 .fragmentsReceived(14L) 074 .fragmentsProcessed(15L) 075 .rawOccurrencesPersistedNew(16L) 076 .rawOccurrencesPersistedUnchanged(17L) 077 .rawOccurrencesPersistedUpdated(18L) 078 .rawOccurrencesPersistedError(19L) 079 .verbatimOccurrencesPersistedSuccessful(20L) 080 .verbatimOccurrencesPersistedError(21L) 081 .interpretedOccurrencesPersistedSuccessful(22L) 082 .interpretedOccurrencesPersistedError(23L) 083 .build(); 084 085 assertEquals(s1, s2); 086 assertEquals(s1.hashCode(), s2.hashCode()); 087 088 ObjectMapper om = new ObjectMapper(); 089 090 byte[] bytes = om.writeValueAsBytes(s1); 091 DatasetProcessStatus s3 = om.readValue(bytes, DatasetProcessStatus.class); 092 assertEquals(s1, s3); 093 assertEquals(s1.hashCode(), s3.hashCode()); 094 } 095}