Skip to content

Commit

Permalink
Merge pull request #238 from ChrisJohnNOAA/minor_cleanup
Browse files Browse the repository at this point in the history
Some minor cleanup. Fixing several tests that had dependencies on the…
  • Loading branch information
ChrisJohnNOAA authored Jan 8, 2025
2 parents 3b8ba99 + 04285c1 commit 9141fb9
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 30 deletions.
5 changes: 2 additions & 3 deletions WEB-INF/classes/com/cohort/util/Script2.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import org.apache.commons.jexl3.introspection.JexlSandbox;

/**
* A class with static Jexl script methods. For tests, see
* gov.noaa.pfel.coastwatch.pointdata.ScriptRow.testScript().
* A class with static Jexl script methods. For tests, see com.cohort.util.ScriptRow.testScript().
*/
public class Script2 {

Expand Down Expand Up @@ -86,7 +85,7 @@ public static JexlEngine jexlEngine() {
jsandbox.allow("com.cohort.util.ScriptCalendar2");
jsandbox.allow("com.cohort.util.ScriptMath");
jsandbox.allow("com.cohort.util.ScriptMath2");
jsandbox.allow("gov.noaa.pfel.coastwatch.pointdata.ScriptRow");
jsandbox.allow("com.cohort.util.ScriptRow");
jsandbox.allow("java.lang.String");
jsandbox.allow("com.cohort.util.ScriptString2");
jexlEngine =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* Table Copyright 2005, NOAA.
* See the LICENSE.txt file in this file's directory.
*/
package gov.noaa.pfel.coastwatch.pointdata;
package com.cohort.util;

import com.cohort.util.File2;
import com.cohort.util.String2;
import gov.noaa.pfel.coastwatch.pointdata.Table;

/**
* This class makes the data on 1 row of a table accessible to JexlScript scripts via
Expand Down
2 changes: 1 addition & 1 deletion WEB-INF/classes/gov/noaa/pfel/erddap/dataset/EDDTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.cohort.util.Math2;
import com.cohort.util.MustBe;
import com.cohort.util.Script2;
import com.cohort.util.ScriptRow;
import com.cohort.util.SimpleException;
import com.cohort.util.String2;
import com.cohort.util.Test;
Expand All @@ -29,7 +30,6 @@
import gov.noaa.pfel.coastwatch.griddata.Grid;
import gov.noaa.pfel.coastwatch.griddata.Matlab;
import gov.noaa.pfel.coastwatch.griddata.NcHelper;
import gov.noaa.pfel.coastwatch.pointdata.ScriptRow;
import gov.noaa.pfel.coastwatch.pointdata.Table;
import gov.noaa.pfel.coastwatch.sgt.CompoundColorMap;
import gov.noaa.pfel.coastwatch.sgt.GraphDataLayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package gov.noaa.pfel.coastwatch.pointdata;
package com.cohort.util;

import com.cohort.array.DoubleArray;
import com.cohort.array.IntArray;
import com.cohort.array.StringArray;
import com.cohort.util.Script2;
import com.cohort.util.String2;
import com.cohort.util.Test;
import gov.noaa.pfel.coastwatch.pointdata.Table;
import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
Expand Down Expand Up @@ -86,7 +84,7 @@ void basicTest() throws Exception {
results = "Caught: " + e.toString();
}
expected =
"Caught: org.apache.commons.jexl3.JexlException: gov.noaa.pfel.coastwatch.pointdata.ScriptRowTests.basicTest:ERROR_LOCATION JEXL error : + error caused by null operand";
"Caught: org.apache.commons.jexl3.JexlException: com.cohort.util.ScriptRowTests.basicTest:ERROR_LOCATION JEXL error : + error caused by null operand";
results = results.replaceAll("[0-9]+@[0-9]+:[0-9]+", "ERROR_LOCATION");
Test.ensureEqual(results.substring(0, expected.length()), expected, "results=\n" + results);

Expand Down Expand Up @@ -180,7 +178,7 @@ void basicTest() throws Exception {
Test.ensureEqual(
results,
"org.apache.commons.jexl3.JexlException$Method: "
+ "gov.noaa.pfel.coastwatch.pointdata.ScriptRowTests.basicTest:ERROR_LOCATION unsolvable function/method 'java.lang.StringBuilder(String)'",
+ "com.cohort.util.ScriptRowTests.basicTest:ERROR_LOCATION unsolvable function/method 'java.lang.StringBuilder(String)'",
"");

// work with static functions by making a shell class (ScriptMath) that can be
Expand Down Expand Up @@ -235,7 +233,7 @@ void basicTest() throws Exception {
results = results.replaceAll("[0-9]+@[0-9]+:[0-9]+", "ERROR_LOCATION");
Test.ensureEqual(
results,
"org.apache.commons.jexl3.JexlException: gov.noaa.pfel.coastwatch.pointdata.ScriptRowTests.basicTest:ERROR_LOCATION JEXL error : + error caused by null operand",
"org.apache.commons.jexl3.JexlException: com.cohort.util.ScriptRowTests.basicTest:ERROR_LOCATION JEXL error : + error caused by null operand",
"");

// String static methods are accessible if String in MapContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void basicTest() throws Exception {
coastwatchDir + "griddata/SaveOpendap.class",
coastwatchDir + "netcheck/",
coastwatchDir + "pointdata/",
coastwatchDir + "pointdata/ScriptRow.class",
coastwatchDir + "pointdata/parquet/",
coastwatchDir + "sgt/",
coastwatchDir + "sgt/SGTPointsVector.class",
Expand All @@ -67,7 +66,6 @@ void basicTest() throws Exception {
shouldBe =
new String[] {
coastwatchDir + "griddata/SaveOpendap.class",
coastwatchDir + "pointdata/ScriptRow.class",
coastwatchDir + "sgt/SGTPointsVector.class",
coastwatchDir + "sgt/SgtGraph.class",
coastwatchDir + "sgt/SgtMap.class",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
import com.cohort.util.File2;
import com.cohort.util.Math2;
import java.nio.file.Path;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import tags.TagSlowTests;
import testDataset.Initialization;

class SharedWatchServiceTests {
@BeforeAll
static void init() {
Initialization.edStatic();
}

private static class EventHandler implements WatchUpdateHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11137,6 +11137,7 @@ void testActualRange() throws Throwable {
* @throws Throwable if trouble
*/
@org.junit.jupiter.api.Test
@TagThredds // external server is failing to respond, so disable the test for now
void testActualRange2() throws Throwable {
// String2.log("\n*** EDDGridFromDap.testActualRange2");
int language = 0;
Expand Down
48 changes: 34 additions & 14 deletions src/test/java/jetty/JettyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.file.Path;
import java.time.Year;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.HashMap;
Expand Down Expand Up @@ -6905,6 +6906,12 @@ void testForBrokenLinks(String tUrl) throws Exception {
+ PORT
+ "/erddap/griddap/erdMHchla8day.timeGaps", // dataset not found
"https://linux.die.net/man/1/ncdump", // fail, works in browser
"https://sbclter.msi.ucsb.edu/external/InformationManagement/eml_2018_erddap/", // Whole
// site
// seems
// to be
// down
// (temporary?) early 2025
};
// https://unitsofmeasure.org/ucum.html fails in tests because of certificate,
// but succeeds in my browser. Others are like this, too.
Expand Down Expand Up @@ -7819,7 +7826,7 @@ void testAdvancedSearch() throws Throwable {
EDD.testVerboseOn();
String htmlUrl = EDStatic.erddapUrl + "/search/advanced.html?page=1&itemsPerPage=1000";
String csvUrl = EDStatic.erddapUrl + "/search/advanced.csv?page=1&itemsPerPage=1000";
String expected = "pmelTaoMonPos";
String expected = "nceiPH53sstd1day";
String expected2, query, results;
String2.log(
"\n*** Erddap.testAdvancedSearch\n"
Expand All @@ -7828,12 +7835,12 @@ void testAdvancedSearch() throws Throwable {
// test valid search string, values are case-insensitive
query = "";
String goodQueries[] = {
"&searchFor=pmelTao",
"&protocol=TAbleDAp",
"&searchFor=nceiPH53",
"&protocol=GrIdDaP",
"&short_name=depth",
"&minLat=-45&maxLat=45",
"&minLon=-25&maxLon=25",
"&minTime=now-3years&maxTime=now-1years"
"&minTime=now-5years&maxTime=now-2years"
};
for (int i = 0; i < goodQueries.length; i++) {
query += goodQueries[i];
Expand All @@ -7844,7 +7851,7 @@ void testAdvancedSearch() throws Throwable {
}

// valid for .html but error for .csv: protocol
query = "&searchFor=pmelTao&protocol=gibberish";
query = "&searchFor=nceiPH53&protocol=gibberish";
results = SSR.getUrlResponseStringUnchanged(htmlUrl + query);
Test.ensureTrue(results.indexOf(expected) >= 0, "results=\n" + results);
try {
Expand All @@ -7861,7 +7868,7 @@ void testAdvancedSearch() throws Throwable {
results.indexOf(expected2) >= 0, "results=\n" + String2.annotatedString(results));

// valid for .html but error for .csv: standard_name
query = "&searchFor=pmelTao&standard_name=gibberish";
query = "&searchFor=nceiPH53&standard_name=gibberish";
results = SSR.getUrlResponseStringUnchanged(htmlUrl + query);
Test.ensureTrue(results.indexOf(expected) >= 0, "results=\n" + results);
try {
Expand All @@ -7878,7 +7885,7 @@ void testAdvancedSearch() throws Throwable {
results.indexOf(expected2) >= 0, "results=\n" + String2.annotatedString(results));

// valid for .html but error for .csv: &minLat > &maxLat
query = "&searchFor=pmelTao&minLat=45&maxLat=0";
query = "&searchFor=nceiPH53&minLat=45&maxLat=0";
results = SSR.getUrlResponseStringUnchanged(htmlUrl + query);
Test.ensureTrue(results.indexOf(expected) >= 0, "results=\n" + results);
try {
Expand All @@ -7895,7 +7902,7 @@ void testAdvancedSearch() throws Throwable {
results.indexOf(expected2) >= 0, "results=\n" + String2.annotatedString(results));

// valid for .html but error for .csv: &minTime > &maxTime
query = "&searchFor=pmelTao&minTime=now-10years&maxTime=now-11years";
query = "&searchFor=nceiPH53&minTime=now-10years&maxTime=now-11years";
results = SSR.getUrlResponseStringUnchanged(htmlUrl + query);
Test.ensureTrue(results.indexOf(expected) >= 0, "results=\n" + results);
try {
Expand Down Expand Up @@ -16574,6 +16581,7 @@ void testInPortXml() throws Throwable {
String gridTable = "grid"; // grid or table
String tDatasetID = "erdSWchlamday";
String fileName = "ErddapToInPort_" + tDatasetID + ".xml";
int currentYear = Year.now().getValue();
EDD edd =
EDD.oneFromXmlFragment(
null,
Expand Down Expand Up @@ -16648,7 +16656,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Metadata Contact</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand All @@ -16662,7 +16672,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Distributor</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand All @@ -16676,7 +16688,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Author</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand All @@ -16690,7 +16704,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Data Set Credit</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand All @@ -16704,7 +16720,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Data Steward</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand All @@ -16718,7 +16736,9 @@ void testInPortXml() throws Throwable {
+ //
" <support-role-type>Point of Contact</support-role-type>\n"
+ //
" <from-date>2024</from-date>\n"
" <from-date>"
+ currentYear
+ "</from-date>\n"
+ //
" <person-email>[email protected]</person-email>\n"
+ //
Expand Down

0 comments on commit 9141fb9

Please sign in to comment.