Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for LoadDatasets.run() #160

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Thumbs.db
.settings
.classpath
.project
src/test/resources/
src/test/resources/*
!src/test/resources/datasets/
.idea
development/test/datasets.xml
development/test/datasets.xml*
Expand Down
45 changes: 45 additions & 0 deletions src/test/java/gov/noaa/pfel/erddap/LoadDatasetsTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package gov.noaa.pfel.erddap;

import com.cohort.util.File2;
import gov.noaa.pfel.erddap.util.EDStatic;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import testDataset.Initialization;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class LoadDatasetsTests {
LoadDatasets loadDatasets;
@BeforeAll
static void init() {
Initialization.edStatic();
}

@Test
void failedToLoadDatasetsTest() throws Throwable {
String pathToDatasetsXml = Objects.requireNonNull(LoadDatasets.class.getResource("/datasets/failedToLoadDatasetsTest.xml")).getPath();
loadDatasets = new LoadDatasets(new Erddap(), EDStatic.datasetsRegex, File2.getBufferedInputStream(pathToDatasetsXml), true);
loadDatasets.run();
assertEquals(EDStatic.datasetsThatFailedToLoad, "n Datasets Failed To Load (in the last major LoadDatasets) = 1\n" +
" etopo36, (end)\n");
}

@Test
void duplicateDatasetsTest() throws Throwable {
String pathToDatasetsXml = Objects.requireNonNull(LoadDatasets.class.getResource("/datasets/duplicateDatasetsTest.xml")).getPath();
loadDatasets = new LoadDatasets(new Erddap(), EDStatic.datasetsRegex, File2.getBufferedInputStream(pathToDatasetsXml), true);
loadDatasets.run();
assertEquals(EDStatic.errorsDuringMajorReload, "ERROR: Duplicate datasetIDs in datasets.xml:\n" +
" etopo180\n");
}

@Test
void numberOfGridAndTableDatasetsTest() throws Throwable {
String pathToDatasetsXml = Objects.requireNonNull(LoadDatasets.class.getResource("/datasets/numberOfGridAndTableDatasetsTest.xml")).getPath();
loadDatasets = new LoadDatasets(new Erddap(), EDStatic.datasetsRegex, File2.getBufferedInputStream(pathToDatasetsXml), true);
loadDatasets.run();
assertEquals(EDStatic.nTableDatasets - 1, 1); // -1 because Erddap makes a table listing all the datasets
assertEquals(EDStatic.nGridDatasets, 3);
}
}
5 changes: 5 additions & 0 deletions src/test/resources/datasets/duplicateDatasetsTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<erddapDatasets>
<dataset type="EDDGridFromEtopo" datasetID="etopo180" />
<dataset type="EDDGridFromEtopo" datasetID="etopo180" />
</erddapDatasets>
6 changes: 6 additions & 0 deletions src/test/resources/datasets/failedToLoadDatasetsTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<erddapDatasets>
<dataset type="EDDGridFromEtopo" datasetID="etopo180" />
<!-- Made a typo in the ID here so the dataset fails to load -->
<dataset type="EDDGridFromEtopo" datasetID="etopo36" />
</erddapDatasets>
13 changes: 13 additions & 0 deletions src/test/resources/datasets/numberOfGridAndTableDatasetsTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<erddapDatasets>
<dataset type="EDDTableFromErddap" datasetID="pmelTaoDyQnet" active="true">
<!-- TAO/TRITON, RAMA, and PIRATA Buoys, Daily, Total Heat Flux -->
<sourceUrl>https://coastwatch.pfeg.noaa.gov/erddap/tabledap/pmelTaoDyQnet</sourceUrl>
</dataset>
<dataset type="EDDGridFromErddap" datasetID="erdMH1chla1day" active="true">
<!-- Chlorophyll-a, Aqua MODIS, NPP, L3SMI, Global, Science Quality (1 Day Composite) -->
<sourceUrl>https://coastwatch.pfeg.noaa.gov/erddap/griddap/erdMH1chla1day</sourceUrl>
</dataset>
<dataset type="EDDGridFromEtopo" datasetID="etopo180" />
<dataset type="EDDGridFromEtopo" datasetID="etopo360" />
</erddapDatasets>