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.dwc;
015
016import org.gbif.dwc.record.StarRecord;
017import org.gbif.utils.file.FileUtils;
018
019import java.io.File;
020import java.io.IOException;
021
022import org.junit.jupiter.api.Test;
023
024import static org.junit.jupiter.api.Assertions.assertEquals;
025import static org.junit.jupiter.api.Assertions.assertNotNull;
026
027public class ArchivePlaziTest {
028
029  private void assertNumberStarRecords(Archive arch, int expectedRecords) {
030    int rows = 0;
031    for (StarRecord rec : arch) {
032      assertNotNull(rec);
033      rows++;
034    }
035    assertEquals(expectedRecords, rows);
036  }
037
038  @Test
039  public void testBuildReaderFile() throws IOException {
040    File zip = FileUtils.getClasspathFile("plazi/6632D8151686A3F8C71D4B5A5B1181A4.zip");
041    File tmpDir = FileUtils.createTempDir();
042    tmpDir.deleteOnExit();
043
044    Archive arch = DwcFiles.fromCompressed(zip.toPath(), tmpDir.toPath());
045    assertNumberStarRecords(arch, 10);
046  }
047}