Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import com.cohort.util.Image2Tests;
import com.cohort.util.String2;
import com.cohort.util.Test;
import gov.noaa.pfel.coastwatch.util.SSR;
import gov.noaa.pfel.erddap.util.EDStatic;
import gov.noaa.pfel.erddap.variable.EDV;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import tags.TagImageComparison;
import tags.TagLargeFiles;
import tags.TagLocalERDDAP;
import testDataset.EDDTestDataset;
import testDataset.Initialization;

Expand Down Expand Up @@ -635,112 +633,5 @@ void testTransparentPng() throws Throwable {
/* */
}

/** This tests the /files/ "files" system. This requires erdTAgeo1day in the localhost ERDDAP. */
@org.junit.jupiter.api.Test
@TagLocalERDDAP
void testFiles() throws Throwable {
String results, expected;

// get /files/datasetID/.csv
results =
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/.csv");
expected =
"Name,Last modified,Size,Description\n"
+ "erdTAugeo1day/,NaN,NaN,\n"
+ "erdTAvgeo1day/,NaN,NaN,\n";
Test.ensureEqual(results, expected, "results=\n" + results);

// get /files/datasetID/
results =
SSR.getUrlResponseStringNewline("http://localhost:8080/cwexperimental/files/erdTAgeo1day/");
Test.ensureTrue(results.indexOf("erdTAugeo1day/") > 0, "results=\n" + results);
Test.ensureTrue(results.indexOf("erdTAugeo1day/") > 0, "results=\n" + results);

// get /files/datasetID/subdir/.csv
results =
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/erdTAvgeo1day/.csv");
expected =
"Name,Last modified,Size,Description\n"
+ "TA1992288_1992288_vgeo.nc,1354883738000,4178528,\n"
+ "TA1992295_1992295_vgeo.nc,1354883742000,4178528,\n";
Test.ensureEqual(results, expected, "results=\n" + results);

// download a file in root

// download a file in subdir
results =
String2.annotatedString(
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/erdTAvgeo1day/TA1992288_1992288_vgeo.nc")
.substring(0, 50));
expected =
"CDF[1][0][0][0][0][0][0][0][10]\n"
+ "[0][0][0][4][0][0][0][4]time[0][0][0][1][0][0][0][8]altitude[0][0][0][1][0][0][0][3]la[end]";
Test.ensureEqual(results.substring(0, expected.length()), expected, "results=\n" + results);

// try to download a non-existent dataset
try {
results =
SSR.getUrlResponseStringNewline("http://localhost:8080/cwexperimental/files/gibberish/");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: http://localhost:8080/cwexperimental/files/gibberish/\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: Currently unknown datasetID=gibberish\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent directory
try {
results =
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/gibberish/");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: http://localhost:8080/cwexperimental/files/erdTAgeo1day/gibberish/\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: Resource not found: directory=gibberish/\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent file
try {
results =
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/gibberish.csv");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: http://localhost:8080/cwexperimental/files/erdTAgeo1day/gibberish.csv\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: File not found: gibberish.csv .\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent file in existant subdir
try {
results =
SSR.getUrlResponseStringNewline(
"http://localhost:8080/cwexperimental/files/erdTAgeo1day/subdir/gibberish.csv");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: http://localhost:8080/cwexperimental/files/erdTAgeo1day/subdir/gibberish.csv\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: File not found: gibberish.csv .\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);
}

}
118 changes: 113 additions & 5 deletions src/test/java/jetty/JettyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.semver4j.Semver;
import tags.TagFlaky;
import tags.TagImageComparison;
import tags.TagIncompleteTest;
import tags.TagJetty;
Expand Down Expand Up @@ -17122,8 +17121,6 @@ void testInPortXml() throws Throwable {
/** This tests dapToNc DGrid. */
@org.junit.jupiter.api.Test
@TagJetty
@TagFlaky // It seems if data is not cached to frequently fail for one of the sides
// in erdQSwindmday
void testDapToNcDGrid() throws Throwable {
String2.log("\n\n*** OpendapHelper.testDapToNcDGrid");
String fileName, expected, results;
Expand Down Expand Up @@ -17553,8 +17550,6 @@ void testDapToNcDGrid() throws Throwable {
/** This tests findVarsWithSharedDimensions. */
@org.junit.jupiter.api.Test
@TagJetty
@TagFlaky // It seems if data is not cached to frequently fail for one of the sides
// in erdQSwindmday
void testFindVarsWithSharedDimensions() throws Throwable {
String2.log("\n\n*** OpendapHelper.findVarsWithSharedDimensions");
String expected, results;
Expand Down Expand Up @@ -20258,4 +20253,117 @@ void testSchemaEDDTableFromErddap(boolean generateCroissantSchema) throws Throwa
tResults = results.substring(0, Math.min(results.length(), expected.length()));
Test.ensureEqual(tResults, expected, "results=\n" + results);
}

/** This tests the /files/ "files" system. This requires erdQSwindmday in the localhost ERDDAP. */
@org.junit.jupiter.api.Test
@TagJetty
void testEDDGridSideBySideFiles() throws Throwable {
String results, expected;

// get /files/datasetID/.csv
results = SSR.getUrlResponseStringNewline(EDStatic.erddapUrl + "/files/erdQSwindmday/.csv");
expected =
"Name,Last modified,Size,Description\n"
+ "erdQSux10mday/,NaN,NaN,\n"
+ "erdQSuy10mday/,NaN,NaN,\n";
Test.ensureEqual(results, expected, "results=\n" + results);

// get /files/datasetID/
results = SSR.getUrlResponseStringNewline(EDStatic.erddapUrl + "/files/erdQSwindmday/");
Test.ensureTrue(results.indexOf("erdQSux10mday/") > 0, "results=\n" + results);
Test.ensureTrue(results.indexOf("erdQSux10mday/") > 0, "results=\n" + results);

// get /files/datasetID/subdir/.csv
results =
SSR.getUrlResponseStringNewline(
EDStatic.erddapUrl + "/files/erdQSwindmday/erdQSux10mday/.csv");
expected =
"Name,Last modified,Size,Description\n"
+ "QS1999213_1999243_ux10.nc,1278088334000,13878880,\n"
+ "QS1999244_1999273_ux10.nc,1278088418000,13878868,\n";
Test.ensureEqual(results, expected, "results=\n" + results);

// download a file in root

// download a file in subdir
results =
String2.annotatedString(
SSR.getUrlResponseStringNewline(
EDStatic.erddapUrl
+ "/files/erdQSwindmday/erdQSux10mday/QS1999213_1999243_ux10.nc")
.substring(0, 50));
expected =
"CDF[1][0][0][0][0][0][0][0][10]\n"
+ "[0][0][0][4][0][0][0][4]time[0][0][0][1][0][0][0][8]altitude[0][0][0][1][0][0][0][3]la[end]";
Test.ensureEqual(results.substring(0, expected.length()), expected, "results=\n" + results);

// try to download a non-existent dataset
try {
results = SSR.getUrlResponseStringNewline(EDStatic.erddapUrl + "/files/gibberish/");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: "
+ EDStatic.erddapUrl
+ "/files/gibberish/\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: Currently unknown datasetID=gibberish\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent directory
try {
results =
SSR.getUrlResponseStringNewline(EDStatic.erddapUrl + "/files/erdQSwindmday/gibberish/");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: "
+ EDStatic.erddapUrl
+ "/files/erdQSwindmday/gibberish/\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: Resource not found: directory=gibberish/\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent file
try {
results =
SSR.getUrlResponseStringNewline(
EDStatic.erddapUrl + "/files/erdQSwindmday/gibberish.csv");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: "
+ EDStatic.erddapUrl
+ "/files/erdQSwindmday/gibberish.csv\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: File not found: gibberish.csv .\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);

// try to download a non-existent file in existant subdir
try {
results =
SSR.getUrlResponseStringNewline(
EDStatic.erddapUrl + "/files/erdQSwindmday/subdir/gibberish.csv");
} catch (Exception e) {
results = e.toString();
}
expected =
"java.io.IOException: HTTP status code=404 java.io.FileNotFoundException: "
+ EDStatic.erddapUrl
+ "/files/erdQSwindmday/subdir/gibberish.csv\n"
+ "(Error {\n"
+ " code=404;\n"
+ " message=\"Not Found: File not found: gibberish.csv .\";\n"
+ "})";
Test.ensureEqual(results, expected, "results=\n" + results);
}
}