diff --git a/dap4/d4tests/build.gradle b/dap4/d4tests/build.gradle index 21331df712..68baaaa3ab 100644 --- a/dap4/d4tests/build.gradle +++ b/dap4/d4tests/build.gradle @@ -45,6 +45,7 @@ dependencies { compile 'org.springframework:spring-webmvc' testCompile 'junit:junit' + testCompile project(':tds-test-utils') testCompile 'edu.ucar:cdm-test-utils' } diff --git a/dap4/d4tests/src/test/java/dap4/test/DapTestCommon.java b/dap4/d4tests/src/test/java/dap4/test/DapTestCommon.java index 601d096649..28875040f5 100644 --- a/dap4/d4tests/src/test/java/dap4/test/DapTestCommon.java +++ b/dap4/d4tests/src/test/java/dap4/test/DapTestCommon.java @@ -1,6 +1,6 @@ /* - * Copyright 2012, UCAR/Unidata. - * See the LICENSE file for more information. + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ package dap4.test; @@ -29,6 +29,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder; +import thredds.TdsUnitTestCommon; import thredds.core.DatasetManager; import thredds.core.TdsRequestedDataset; import thredds.server.dap4.Dap4Controller; @@ -37,12 +38,11 @@ import ucar.nc2.NetcdfFile; import ucar.nc2.jni.netcdf.Nc4prototypes; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import javax.servlet.ServletException; import java.io.File; import java.io.FileFilter; import java.io.IOException; -import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; @@ -51,7 +51,7 @@ @ContextConfiguration @WebAppConfiguration("file:src/test/data") -abstract public class DapTestCommon extends UnitTestCommon { +abstract public class DapTestCommon extends TdsUnitTestCommon { ////////////////////////////////////////////////// // Constants diff --git a/dap4/d4tests/src/test/java/dap4/test/TestCDMClient.java b/dap4/d4tests/src/test/java/dap4/test/TestCDMClient.java index 3b5a3133a8..72792cfbb6 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestCDMClient.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestCDMClient.java @@ -1,6 +1,6 @@ /* - * Copyright 2016, University Corporation for Atmospheric Research - * See the LICENSE.txt file for more information. + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ package dap4.test; @@ -12,8 +12,10 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.nc2.dataset.NetcdfDataset; import ucar.unidata.util.test.TestDir; + import java.io.File; import java.io.IOException; import java.io.StringWriter; @@ -233,7 +235,7 @@ void doOneTest(TestCase testcase) throws Exception { NetcdfDataset ncfile; try { - ncfile = openDatasetDap4Tests(testcase.getURL()); + ncfile = TdsUnitTestCommon.openDatasetDap4Tests(testcase.getURL()); } catch (Exception e) { e.printStackTrace(); throw new Exception("File open failed: " + testcase.getURL(), e); diff --git a/dap4/d4tests/src/test/java/dap4/test/TestConstraints.java b/dap4/d4tests/src/test/java/dap4/test/TestConstraints.java index a15a12a25b..d7f2d8a7bd 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestConstraints.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestConstraints.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package dap4.test; import org.junit.Assert; @@ -6,6 +11,7 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.httpservices.HTTPMethod; import ucar.nc2.dataset.NetcdfDataset; import ucar.unidata.util.test.TestDir; @@ -180,7 +186,7 @@ void doOneTest(TestCase testcase) throws Exception { String url = testcase.makeurl(); NetcdfDataset ncfile = null; try { - ncfile = openDatasetDap4Tests(url); + ncfile = TdsUnitTestCommon.openDatasetDap4Tests(url); } catch (Exception e) { throw e; } diff --git a/dap4/d4tests/src/test/java/dap4/test/TestH5Iosp.java b/dap4/d4tests/src/test/java/dap4/test/TestH5Iosp.java index d497ce0d78..ad59aa4b9b 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestH5Iosp.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestH5Iosp.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package dap4.test; import org.junit.Assert; @@ -6,8 +11,10 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.nc2.dataset.NetcdfDataset; import ucar.unidata.util.test.category.NotJenkins; + import java.io.File; import java.io.IOException; import java.io.StringWriter; @@ -147,7 +154,7 @@ boolean doOneTest(H5IospTest testcase) throws Exception { System.out.println("Testcase: " + testcase.testinputpath); - NetcdfDataset ncfile = openDatasetDap4Tests(testcase.testinputpath); + NetcdfDataset ncfile = TdsUnitTestCommon.openDatasetDap4Tests(testcase.testinputpath); String metadata = null; String data = null; diff --git a/dap4/d4tests/src/test/java/dap4/test/TestHyrax.java b/dap4/d4tests/src/test/java/dap4/test/TestHyrax.java index b5b22d0360..7f382cfa07 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestHyrax.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestHyrax.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package dap4.test; import dap4.core.util.DapUtil; @@ -7,10 +12,11 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.nc2.dataset.NetcdfDataset; -import ucar.unidata.util.test.UnitTestCommon; import ucar.unidata.util.test.category.NotJenkins; import ucar.unidata.util.test.category.NotPullRequest; + import java.io.IOException; import java.io.StringWriter; import java.lang.invoke.MethodHandles; @@ -272,13 +278,13 @@ boolean doOneTest(ClientTest testcase) throws Exception { String url = testcase.makeurl(); NetcdfDataset ncfile = null; try { - ncfile = openDatasetDap4Tests(url); + ncfile = TdsUnitTestCommon.openDatasetDap4Tests(url); } catch (Exception e) { System.err.println(testcase.xfail ? "XFail" : "Fail"); e.printStackTrace(); return testcase.xfail; } - String usethisname = UnitTestCommon.extractDatasetname(url, null); + String usethisname = TdsUnitTestCommon.extractDatasetname(url, null); String metadata = (NCDUMP ? ncdumpmetadata(ncfile, usethisname) : null); if (prop_visual) { visual(testcase.title + ".dmr", metadata); diff --git a/dap4/d4tests/src/test/java/dap4/test/TestNc4Iosp.java b/dap4/d4tests/src/test/java/dap4/test/TestNc4Iosp.java index cb565d9218..6118b2d594 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestNc4Iosp.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestNc4Iosp.java @@ -1,5 +1,20 @@ +/* + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package dap4.test; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; +import ucar.nc2.dataset.NetcdfDataset; +import ucar.unidata.util.test.category.NotPullRequest; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -9,14 +24,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import ucar.nc2.dataset.NetcdfDataset; -import ucar.unidata.util.test.category.NotPullRequest; @Category(NotPullRequest.class) public class TestNc4Iosp extends DapTestCommon { @@ -153,7 +160,7 @@ public void testNc4Iosp() throws Exception { void doOneTest(Nc4IospTest testcase) throws Exception { System.err.println("Testcase: " + testcase.testinputpath); - NetcdfDataset ncfile = openDatasetDap4Tests(testcase.testinputpath); + NetcdfDataset ncfile = TdsUnitTestCommon.openDatasetDap4Tests(testcase.testinputpath); String metadata = null; String data = null; diff --git a/dap4/d4tests/src/test/java/dap4/test/TestSerial.java b/dap4/d4tests/src/test/java/dap4/test/TestSerial.java index 0798b1e6fe..e71efaab8f 100644 --- a/dap4/d4tests/src/test/java/dap4/test/TestSerial.java +++ b/dap4/d4tests/src/test/java/dap4/test/TestSerial.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package dap4.test; import dap4.core.util.DapUtil; @@ -6,9 +11,10 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.nc2.dataset.NetcdfDataset; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import java.io.IOException; import java.io.StringWriter; import java.lang.invoke.MethodHandles; @@ -178,12 +184,12 @@ boolean doOneTest(ClientTest testcase) throws Exception { String url = testcase.makeurl(constraints[i]); NetcdfDataset ncfile = null; try { - ncfile = openDatasetDap4Tests(url); + ncfile = TdsUnitTestCommon.openDatasetDap4Tests(url); } catch (Exception e) { throw e; } - String usethisname = UnitTestCommon.extractDatasetname(url, null); + String usethisname = TdsUnitTestCommon.extractDatasetname(url, null); String metadata = (NCDUMP ? ncdumpmetadata(ncfile, usethisname) : null); String data = (NCDUMP ? ncdumpdata(ncfile, usethisname) : null); diff --git a/opendap/server/src/main/test/java/opendap/test/TestCeParser.java b/opendap/server/src/main/test/java/opendap/test/TestCeParser.java index d7d6bd9669..661d22d2e9 100644 --- a/opendap/server/src/main/test/java/opendap/test/TestCeParser.java +++ b/opendap/server/src/main/test/java/opendap/test/TestCeParser.java @@ -13,14 +13,13 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ucar.unidata.util.test.UnitTestCommon; -// import opendap.dts.*; +import thredds.TdsUnitTestCommon; import java.lang.invoke.MethodHandles; import java.util.*; import java.io.*; // Test that the Constraint parsing is correct -public class TestCeParser extends UnitTestCommon { +public class TestCeParser extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final boolean DEBUGPARSER = false; diff --git a/tds-test-utils/build.gradle b/tds-test-utils/build.gradle index 3e5f618b89..6600ba50b3 100644 --- a/tds-test-utils/build.gradle +++ b/tds-test-utils/build.gradle @@ -10,6 +10,7 @@ dependencies { implementation 'edu.ucar:cdm-core' implementation 'edu.ucar:httpservices' + implementation 'edu.ucar:cdm-test-utils' implementation project(':tdcommon') diff --git a/tds-test-utils/src/main/java/thredds/TdsTestDir.java b/tds-test-utils/src/main/java/thredds/TdsTestDir.java new file mode 100644 index 0000000000..f8f698a642 --- /dev/null +++ b/tds-test-utils/src/main/java/thredds/TdsTestDir.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + +package thredds; + +public class TdsTestDir { + public static String cdmUseBuildersPropName = "thredds.test.experimental.useNetcdfJavaBuilders"; + public static boolean cdmUseBuilders; + + // Remote Test server(s) + public static String remoteTestServer = "localhost:8081"; + + static { + String useBuilderProp = System.getProperty(cdmUseBuildersPropName, ""); + // default (prop not set) true. Otherwise, check prop. + cdmUseBuilders = useBuilderProp.equals("") ? Boolean.TRUE : Boolean.getBoolean(cdmUseBuildersPropName); + } +} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java b/tds-test-utils/src/main/java/thredds/TdsUnitTestCommon.java similarity index 60% rename from tds-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java rename to tds-test-utils/src/main/java/thredds/TdsUnitTestCommon.java index ffebf549a6..8094d8f2ec 100644 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/UnitTestCommon.java +++ b/tds-test-utils/src/main/java/thredds/TdsUnitTestCommon.java @@ -1,63 +1,58 @@ /* - * /* - * Copyright 2012, UCAR/Unidata. - * See the LICENSE file for more information. + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ -package ucar.unidata.util.test; +package thredds; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; import ucar.nc2.NetcdfFile; import ucar.nc2.dataset.DatasetUrl; import ucar.nc2.dataset.NetcdfDataset; +import ucar.nc2.write.Ncdump; +import ucar.unidata.util.test.Diff; +import ucar.unidata.util.test.SysStreamLogger; + import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; -import java.util.ArrayList; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.EnumSet; -import java.util.List; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import ucar.nc2.write.Ncdump; - -abstract public class UnitTestCommon { +public abstract class TdsUnitTestCommon { ////////////////////////////////////////////////// // Static Constants - static public boolean LOGSTDIO = System.getProperty("intellij") == null; + public static boolean LOGSTDIO = System.getProperty("intellij") == null; - static public final boolean DEBUG = false; + public static final boolean DEBUG = false; - static public final Charset UTF8 = Charset.forName("UTF-8"); + public static final Charset UTF8 = StandardCharsets.UTF_8; - static protected final int[] OKCODES = new int[] {200, 404}; - - protected static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UnitTestCommon.class); + protected static final int[] OKCODES = {200, 404}; // Look for these to verify we have found the thredds root - static final String[] DEFAULTSUBDIRS = new String[] {"tds", "opendap", "dap4"}; + static final String[] DEFAULTSUBDIRS = {"opendap", "dap4"}; // NetcdfDataset enhancement to use: need only coord systems static final Set ENHANCEMENT = EnumSet.of(NetcdfDataset.Enhance.CoordSystems); - static protected String threddsroot = null; - static protected String threddsServer = null; + protected static String threddsroot = null; + protected static String threddsServer = null; static { // Compute the root path threddsroot = locateThreddsRoot(); assert threddsroot != null : "Cannot locate /thredds parent dir"; - threddsServer = TestDir.remoteTestServer; + threddsServer = TdsTestDir.remoteTestServer; if (DEBUG) - System.err.println("UnitTestCommon: threddsServer=" + threddsServer); + System.err.println("TdsUnitTestCommon: threddsServer=" + threddsServer); } ////////////////////////////////////////////////// @@ -114,100 +109,6 @@ static String locateThreddsRoot() { return null; } - static protected String rebuildpath(String[] pieces, int last) { - StringBuilder buf = new StringBuilder(); - for (int i = 0; i <= last; i++) { - buf.append("/"); - buf.append(pieces[i]); - } - return buf.toString(); - } - - static public void clearDir(File dir, boolean clearsubdirs) { - // wipe out the dir contents - if (!dir.exists()) - return; - for (File f : dir.listFiles()) { - if (f.isDirectory()) { - if (clearsubdirs) { - clearDir(f, true); // clear subdirs - f.delete(); - } - } else - f.delete(); - } - } - - ////////////////////////////////////////////////// - // Static classes - - /** - * Provide an interface that allows for arbitrary modification - * of text before is is passed to compare(). - */ - static public interface Modifier { - public String modify(String text); - } - - /** - * Instance of Modifier specialized to delete lines matching - * a given Java regular expression - * of text before is is passed to compare(). - * A Line is defined by text.split("[\n]"). - */ - static public class ModDelete implements Modifier { - protected Pattern pattern = null; - - public ModDelete(String regexp) { - this.pattern = Pattern.compile(regexp); - - } - - public String modify(String text) { - String[] lines = text.split("[\n]"); - StringBuilder result = new StringBuilder(); - for (int i = 0; i < lines.length; i++) { - String line = lines[i]; - Matcher m = this.pattern.matcher(line); - if (m.matches()) { - result.append(line); - result.append("\n"); - } - } - return result.toString(); - } - } - - /** - * Instance of Modifier specialized to delete named attributes. - */ - static public class ModSuppress implements Modifier { - protected List patterns = new ArrayList<>(); - - public ModSuppress() {} - - public void suppress(String attributename) { - String re = String.format("[^\n]\n", attributename); - Pattern pattern = Pattern.compile(re); - patterns.add(pattern); - } - - public String modify(String text) { - StringBuilder result = new StringBuilder(text); - for (Pattern p : patterns) { - for (;;) { - Matcher m = p.matcher(result.toString()); - if (!m.matches()) - break; - int pos0 = m.start(); - int pos1 = m.end(); - result.delete(pos0, pos1); - } - } - return result.toString(); - } - } - ////////////////////////////////////////////////// // Instance variables @@ -227,11 +128,11 @@ public String modify(String text) { ////////////////////////////////////////////////// // Constructor(s) - public UnitTestCommon() { + public TdsUnitTestCommon() { this("Testing"); } - public UnitTestCommon(String name) { + public TdsUnitTestCommon(String name) { this.title = name; setSystemProperties(); } @@ -308,7 +209,7 @@ public void visual(String header, String captured, char marker) { System.err.println("==============="); } - static public String compare(String tag, String baseline, String testresult) { + public static String compare(String tag, String baseline, String testresult) { // Check for empty testresult if (testresult.trim().length() == 0) return ">>>> EMPTY TEST RESULT"; @@ -324,7 +225,7 @@ static public String compare(String tag, String baseline, String testresult) { } } - static public boolean same(String tag, String baseline, String testresult) { + public static boolean same(String tag, String baseline, String testresult) { String result = compare(tag, baseline, testresult); if (result == null) { System.err.println("Files are Identical"); @@ -335,19 +236,6 @@ static public boolean same(String tag, String baseline, String testresult) { } } - static public boolean similar(String tag, String baseline, String testresult, Modifier mbaseline, Modifier mtest) { - String baselinemod = mbaseline.modify(baseline); - String testresultmod = mtest.modify(testresult); - String result = compare(tag, baselinemod, testresultmod); - if (result == null) { - System.err.println("Files are Similar"); - return true; - } else { - System.err.println(result); - return false; - } - } - protected boolean checkServer(String candidate) { if (candidate == null) return false; @@ -356,7 +244,6 @@ protected boolean checkServer(String candidate) { try { try (HTTPMethod method = HTTPFactory.Get(candidate)) { method.execute(); - String s = method.getResponseAsString(); System.err.println(" ; found"); return true; } @@ -380,7 +267,7 @@ protected void unbindstd() { // Static utilities // Copy result into the a specified dir - static public void writefile(String path, String content) throws IOException { + public static void writefile(String path, String content) throws IOException { File f = new File(path); if (f.exists()) f.delete(); @@ -390,7 +277,7 @@ static public void writefile(String path, String content) throws IOException { } // Copy result into the a specified dir - static public void writefile(String path, byte[] content) throws IOException { + public static void writefile(String path, byte[] content) throws IOException { File f = new File(path); if (f.exists()) f.delete(); @@ -399,7 +286,7 @@ static public void writefile(String path, byte[] content) throws IOException { out.close(); } - static public String readfile(String filename) throws IOException { + public static String readfile(String filename) throws IOException { StringBuilder buf = new StringBuilder(); Path file = Paths.get(filename); try (BufferedReader rdr = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { @@ -413,14 +300,14 @@ static public String readfile(String filename) throws IOException { } } - static public byte[] readbinaryfile(String filename) throws IOException { + public static byte[] readbinaryfile(String filename) throws IOException { FileInputStream stream = new FileInputStream(filename); byte[] result = readbinaryfile(stream); stream.close(); return result; } - static public byte[] readbinaryfile(InputStream stream) throws IOException { + public static byte[] readbinaryfile(InputStream stream) throws IOException { // Extract the stream into a bytebuffer ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] tmp = new byte[1 << 16]; @@ -441,7 +328,7 @@ static public NetcdfDataset openDatasetDap4Tests(String url) throws IOException } // Fix up a filename reference in a string - static public String shortenFileName(String text, String filename) { + public static String shortenFileName(String text, String filename) { // In order to achieve diff consistentcy, we need to // modify the output to change "netcdf .../file.nc {...}" // to "netcdf file.nc {...}" @@ -453,24 +340,7 @@ static public String shortenFileName(String text, String filename) { return text; } - static public void tag(String t) { - System.err.println(t); - System.err.flush(); - } - - static public String canonjoin2(String prefix, String suffix) { - if (prefix == null) - prefix = ""; - if (suffix == null) - suffix = ""; - StringBuilder result = new StringBuilder(prefix); - if (!prefix.endsWith("/")) - result.append("/"); - result.append(suffix.startsWith("/") ? suffix.substring(1) : suffix); - return result.toString(); - } - - static public String canonjoin(String... pieces) { + public static String canonjoin(String... pieces) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < pieces.length; i++) { // invariant buf does not end with ('/') @@ -498,7 +368,7 @@ static public String canonjoin(String... pieces) { * @param path convert this path * @return canonicalized version */ - static public String canonicalpath(String path) { + public static String canonicalpath(String path) { if (path == null) return null; path = path.trim(); @@ -515,20 +385,20 @@ static public String canonicalpath(String path) { * return true if this path appears to start with a windows drive letter * * @param path - * @return true, if path appears to start with a drive letter + * @return true, if path has drive letter */ - static public boolean hasDriveLetter(String path) { + public static boolean hasDriveLetter(String path) { if (path != null && path.length() >= 2) { return (DRIVELETTERS.indexOf(path.charAt(0)) >= 0 && path.charAt(1) == ':'); } return false; } - static final public String DRIVELETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase(); + public static final String DRIVELETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase(); - static public String extractDatasetname(String urlorpath, String suffix) { + public static String extractDatasetname(String urlorpath, String suffix) { try { URI x = new URI(urlorpath); StringBuilder path = new StringBuilder(x.getPath()); @@ -548,7 +418,7 @@ static public String extractDatasetname(String urlorpath, String suffix) { return null; } - static protected String ncdumpmetadata(NetcdfFile ncfile, String datasetname) throws Exception { + protected static String ncdumpmetadata(NetcdfFile ncfile, String datasetname) throws Exception { StringWriter sw = new StringWriter(); StringBuilder args = new StringBuilder("-strict"); if (datasetname != null) { @@ -565,7 +435,7 @@ static protected String ncdumpmetadata(NetcdfFile ncfile, String datasetname) th return sw.toString(); } - static protected String ncdumpdata(NetcdfFile ncfile, String datasetname) throws Exception { + protected static String ncdumpdata(NetcdfFile ncfile, String datasetname) throws Exception { StringBuilder args = new StringBuilder("-strict -vall"); if (datasetname != null) { args.append(" -datasetname "); @@ -583,111 +453,15 @@ static protected String ncdumpdata(NetcdfFile ncfile, String datasetname) throws return sw.toString(); } - /** - * @param prefix - string to prefix all command line options: typically "--" - * @param options - list of option names of interest - * @return specified properties converted to command line form - */ - static public String[] propertiesToArgs(String prefix, String... options) { - if (options == null || options.length == 0) - throw new IllegalArgumentException("No options specified"); - if (prefix == null) - prefix = "--"; - List args = new ArrayList<>(); - Set defined = System.getProperties().stringPropertyNames(); - for (String key : options) { - if (!defined.contains(key)) - continue; // not defined - String value = System.getProperty(key); - args.add(prefix + key); - if (value != null) - args.add(value); - } - return args.toArray(new String[args.size()]); - } - - static protected boolean check(int code) { + protected static boolean check(int code) { return check(code, OKCODES); } - static protected boolean check(int code, int[] ok) { + protected static boolean check(int code, int[] ok) { for (int okcode : ok) { if (okcode == code) return true; } return false; } - - /* - * // Replacement for stderr & stdout - * static public class STDIO - * { - * public STDIO(String name) - * { - * } - * - * public void - * printf(String format, Object... args) - * { - * System.err.println(String.format(format, args)); - * } - * - * public void - * println(String msg) - * { - * printf("%s%n", msg); - * } - * - * public void - * print(String msg) - * { - * printf("%s", msg); - * } - * - * public void - * flush() - * { - * } - * } - * - * static public STDIO stderr = new STDIO("test"); - * static public STDIO stdout = new STDIO("test"); - * - * static TemporaryFolder temporaryfolder = null; - * - * static public File - * makeTemporaryDir(String name) - * throws IOException - * { - * if(temporaryfolder == null) - * temporaryfolder = new TemporaryFolder(); - * return temporaryfolder.newFolder(name); - * } - * - * static public File - * makeTemporaryFile(String name) - * throws IOException - * { - * if(temporaryfolder == null) - * temporaryfolder = new TemporaryFolder(); - * return temporaryfolder.newFile(name); - * } - * static public void - * logify(String s) - * { - * StringReader rs = new StringReader(s); - * BufferedReader r = new BufferedReader(rs); - * String line = null; - * for(; ; ) { - * try { - * line = r.readLine(); - * } catch (IOException ioe) { - * break; - * } - * if(line == null) break; - * System.err.println(line); - * } - * } - */ } - diff --git a/tds-test-utils/src/main/java/thredds/client/catalog/ClientCatalogUtil.java b/tds-test-utils/src/main/java/thredds/client/catalog/ClientCatalogUtil.java deleted file mode 100644 index 6dc21101ea..0000000000 --- a/tds-test-utils/src/main/java/thredds/client/catalog/ClientCatalogUtil.java +++ /dev/null @@ -1,52 +0,0 @@ -package thredds.client.catalog; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import thredds.client.catalog.builder.CatalogBuilder; -import ucar.unidata.util.StringUtil2; -import ucar.unidata.util.test.TestDir; -import java.io.IOException; -import java.lang.invoke.MethodHandles; - -/** - * @author cwardgar - * @since 2017-12-23 - */ -public class ClientCatalogUtil { - private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - static public String makeUrlFromFragment(String catFrag) { - return "file:" + TestDir.cdmLocalTestDataDir + "thredds/catalog/" + catFrag; - } - - static public Catalog open(String urlString) throws IOException { - if (!urlString.startsWith("http:") && !urlString.startsWith("file:")) { - urlString = makeUrlFromFragment(urlString); - } else { - urlString = StringUtil2.replace(urlString, "\\", "/"); - } - logger.debug("Open {}", urlString); - CatalogBuilder builder = new CatalogBuilder(); - Catalog cat = builder.buildFromLocation(urlString, null); - if (builder.hasFatalError()) { - logger.error(builder.getErrorMessage()); - assert false; - return null; - } else { - String mess = builder.getErrorMessage(); - if (mess.length() > 0) - logger.debug("Parse messages: {}", builder.getErrorMessage()); - } - return cat; - } - - public static String makeFilepath(String catalogName) { - return makeFilepath() + catalogName; - } - - public static String makeFilepath() { - return "file:" + dataDir; - } - - public static String dataDir = TestDir.cdmLocalTestDataDir + "thredds/catalog/"; -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/Assert2.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/Assert2.java deleted file mode 100644 index a1b02a813f..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/Assert2.java +++ /dev/null @@ -1,140 +0,0 @@ -package ucar.unidata.util.test; - -import org.junit.Assert; -import org.junit.internal.ComparisonCriteria; -import ucar.nc2.util.Misc; - -/** - * Custom JUnit 4 assertions. - * - * @author cwardgar - * @since 2018-05-13 - */ -// TODO: Create "assertNearlyEquals(Array, Array)". -public class Assert2 { - /** - * Returns the result of {@link #assertNearlyEquals(float, float, float)}, with - * {@link Misc#defaultMaxRelativeDiffFloat}. - */ - public static void assertNearlyEquals(float expected, float actual) { - assertNearlyEquals(expected, actual, Misc.defaultMaxRelativeDiffFloat); - } - - /** - * Asserts that two floats are {@link Misc#nearlyEquals(float, float, float) nearly equal}. If they are not, - * an {@link AssertionError} is thrown. - * - * @param expected expected value - * @param actual the value to check against {@code expected} - * @param maxRelDiff the maximum relative difference the two numbers may have and still be considered equal. - */ - public static void assertNearlyEquals(float expected, float actual, float maxRelDiff) { - if (!Misc.nearlyEquals(expected, actual, maxRelDiff)) { - failNotEquals(null, Float.valueOf(expected), Float.valueOf(actual)); - } - } - - /** - * Returns the result of {@link #assertNearlyEquals(double, double, double)}, with - * {@link Misc#defaultMaxRelativeDiffDouble}. - */ - public static void assertNearlyEquals(double expected, double actual) { - assertNearlyEquals(expected, actual, Misc.defaultMaxRelativeDiffDouble); - } - - /** Same as {@link #assertNearlyEquals(float, float, float)}, but for doubles. */ - public static void assertNearlyEquals(double expected, double actual, double maxRelDiff) { - if (!Misc.nearlyEquals(expected, actual, maxRelDiff)) { - failNotEquals(null, Double.valueOf(expected), Double.valueOf(actual)); - } - } - - - /** - * Returns the result of {@link #assertArrayNearlyEquals(float[], float[], float)}, with - * {@link Misc#defaultMaxRelativeDiffFloat}. - */ - public static void assertArrayNearlyEquals(float[] expecteds, float[] actuals) { - assertArrayNearlyEquals(expecteds, actuals, Misc.defaultMaxRelativeDiffFloat); - } - - /** - * Asserts that two float arrays are nearly equal by comparing analogous elements in the two arrays with - * {@link Misc#nearlyEquals(float, float, float)}. If they are not, an {@link AssertionError} is thrown. - * - * @param expecteds float array with expected values. - * @param actuals float array with actual values - * @param maxRelDiff the maximum relative difference that analogous array elements may have and still be - * considered equal. - */ - public static void assertArrayNearlyEquals(float[] expecteds, float[] actuals, float maxRelDiff) { - new NearlyEqualsComparisonCriteria(maxRelDiff).arrayEquals(null, expecteds, actuals); - } - - /** - * Returns the result of {@link #assertArrayNearlyEquals(double[], double[], double)}, with - * {@link Misc#defaultMaxRelativeDiffDouble}. - */ - public static void assertArrayNearlyEquals(double[] expecteds, double[] actuals) { - assertArrayNearlyEquals(expecteds, actuals, Misc.defaultMaxRelativeDiffDouble); - } - - /** Same as {@link #assertArrayNearlyEquals(float[], float[], float)}, but for doubles. */ - public static void assertArrayNearlyEquals(double[] expecteds, double[] actuals, double maxRelDiff) { - new NearlyEqualsComparisonCriteria(maxRelDiff).arrayEquals(null, expecteds, actuals); - } - - - private static class NearlyEqualsComparisonCriteria extends ComparisonCriteria { - public Object maxRelDiff; - - public NearlyEqualsComparisonCriteria(double maxRelDiff) { - this.maxRelDiff = maxRelDiff; - } - - public NearlyEqualsComparisonCriteria(float maxRelDiff) { - this.maxRelDiff = maxRelDiff; - } - - @Override - protected void assertElementsEqual(Object expected, Object actual) { - if (expected instanceof Double) { - assertNearlyEquals((Double) expected, (Double) actual, (Double) maxRelDiff); - } else { - assertNearlyEquals((Float) expected, (Float) actual, (Float) maxRelDiff); - } - } - } - - // The following methods come from the JUnit project, specifically the org.junit.Assert class. - // JUnit is licensed under Eclipse Public License 1.0. A copy of the license can be found at - // docs/src/private/licenses/third-party/junit/LICENSE-junit.txt - - static private void failNotEquals(String message, Object expected, Object actual) { - Assert.fail(format(message, expected, actual)); - } - - static String format(String message, Object expected, Object actual) { - String formatted = ""; - if (message != null && !message.equals("")) { - formatted = message + " "; - } - String expectedString = String.valueOf(expected); - String actualString = String.valueOf(actual); - if (expectedString.equals(actualString)) { - return formatted + "expected: " + formatClassAndValue(expected, expectedString) + " but was: " - + formatClassAndValue(actual, actualString); - } else { - return formatted + "expected:<" + expectedString + "> but was:<" + actualString + ">"; - } - } - - private static String formatClassAndValue(Object value, String valueString) { - String className = value == null ? "null" : value.getClass().getName(); - return className + "<" + valueString + ">"; - } - - - /** Private constructor to ensure non-instantiability. */ - private Assert2() {} -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/CompareNetcdf.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/CompareNetcdf.java deleted file mode 100644 index b4c51b7a0d..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/CompareNetcdf.java +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -// $Id: TestCompare.java 51 2006-07-12 17:13:13Z caron $ - -package ucar.unidata.util.test; - -import org.junit.Assert; -import ucar.nc2.dataset.VariableEnhanced; -import ucar.nc2.*; -import ucar.ma2.*; -import ucar.nc2.util.Misc; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Formatter; -import java.util.List; - -/** - * Compare two NetcdfFile. Uses assert. - * Test classes only. - * - * @author john - */ -public class CompareNetcdf { - - static public boolean compareFiles(NetcdfFile org, NetcdfFile copy) { - return compareFiles(org, copy, false, false, false); - } - - static public boolean compareFiles(NetcdfFile org, NetcdfFile copy, boolean _compareData, boolean _showCompare, - boolean _showEach) { - CompareNetcdf tc = new CompareNetcdf(_showCompare, _showEach, _compareData); - return tc.compare(org, copy, new Formatter(System.out)); - } - - ///////// - - private boolean showCompare = false; - private boolean showEach = false; - private boolean compareData = false; - - public CompareNetcdf(boolean showCompare, boolean showEach, boolean compareData) { - this.compareData = compareData; - this.showCompare = showCompare; - this.showEach = showEach; - } - - public boolean compare(NetcdfFile org, NetcdfFile copy, Formatter f) { - f.format("First file = %s%n", org.getLocation()); - f.format("Second file= %s%n", copy.getLocation()); - - long start = System.currentTimeMillis(); - - boolean ok = compareGroups(org.getRootGroup(), copy.getRootGroup(), f); - f.format("Files are the same = %s%n", ok); - - long took = System.currentTimeMillis() - start; - f.format("Time to compare = %d msecs%n", took); - - return ok; - } - - public boolean compareVariables(NetcdfFile org, NetcdfFile copy, Formatter f) { - f.format("Original = %s%n", org.getLocation()); - f.format("CompareTo= %s%n", copy.getLocation()); - boolean ok = true; - - for (Variable orgV : org.getVariables()) { - if (orgV.isCoordinateVariable()) - continue; - Variable copyVar = copy.findVariable(orgV.getShortName()); - if (copyVar == null) { - f.format(" MISSING '%s' in 2nd file%n", orgV.getFullName()); - ok = false; - } else { - List dims1 = orgV.getDimensions(); - List dims2 = copyVar.getDimensions(); - if (!compare(dims1, dims2)) { - f.format(" %s != %s%n", orgV.getNameAndDimensions(), copyVar.getNameAndDimensions()); - } else { - // f.format(" ok %s%n", orgV.getName()); - } - } - } - - f.format("%n"); - for (Variable orgV : copy.getVariables()) { - if (orgV.isCoordinateVariable()) - continue; - Variable copyVar = org.findVariable(orgV.getShortName()); - if (copyVar == null) { - f.format(" MISSING '%s' in 1st file%n", orgV.getFullName()); - ok = false; - } - } - - - - return ok; - } - - private boolean compare(List dims1, List dims2) { - if (dims1.size() != dims2.size()) - return false; - for (int i = 0; i < dims1.size(); i++) { - Dimension dim1 = dims1.get(i); - Dimension dim2 = dims2.get(i); - // if (!dim1.getName().equals(dim2.getName())) return false; - if (dim1.getLength() != dim2.getLength()) - return false; - } - return true; - } - - private boolean compareGroups(Group org, Group copy, Formatter f) { - if (showCompare) - f.format("compare Group %s to %s %n", org.getFullName(), copy.getFullName()); - boolean ok = true; - - if (!org.getFullName().equals(copy.getFullName())) { - f.format(" ** names are different %s != %s %n", org.getShortName(), copy.getShortName()); - ok = false; - } - - // dimensions - ok &= checkAll(org.getDimensions(), copy.getDimensions(), null, f); - - // attributes - ok &= checkAll(org.getAttributes(), copy.getAttributes(), null, f); - - // variables - // cant use object equality, just match on short name - for (Variable orgV : org.getVariables()) { - Variable copyVar = copy.findVariable(orgV.getShortName()); - if (copyVar == null) { - f.format(" ** cant find variable %s in 2nd file%n", orgV.getFullName()); - ok = false; - } else { - ok &= compareVariables(orgV, copyVar, compareData, f); - } - } - - for (Variable copyV : copy.getVariables()) { - Variable orgV = org.findVariable(copyV.getShortName()); - if (orgV == null) { - f.format(" ** cant find variable %s in 1st file%n", copyV.getFullName()); - ok = false; - } - } - - // nested groups - List groups = new ArrayList(); - ok &= checkAll(org.getGroups(), copy.getGroups(), groups, f); - for (int i = 0; i < groups.size(); i += 2) { - Group orgGroup = (Group) groups.get(i); - Group ncmlGroup = (Group) groups.get(i + 1); - ok &= compareGroups(orgGroup, ncmlGroup, f); - } - - return ok; - } - - - public boolean compareVariable(Variable org, Variable copy, Formatter f) { - return compareVariables(org, copy, compareData, f); - } - - private boolean compareVariables(Variable org, Variable copy, boolean compareData, Formatter f) { - boolean ok = true; - - if (showCompare) - f.format("compare Variable %s to %s %n", org.getFullName(), copy.getFullName()); - if (!org.getFullName().equals(copy.getFullName())) { - f.format(" ** names are different %s != %s %n", org.getFullName(), copy.getFullName()); - ok = false; - } - - // dimensions - ok &= checkAll(org.getDimensions(), copy.getDimensions(), null, f); - - // attributes - ok &= checkAll(org.getAttributes(), copy.getAttributes(), null, f); - - // coord sys - if ((org instanceof VariableEnhanced) && (copy instanceof VariableEnhanced)) { - VariableEnhanced orge = (VariableEnhanced) org; - VariableEnhanced copye = (VariableEnhanced) copy; - ok &= checkAll(orge.getCoordinateSystems(), copye.getCoordinateSystems(), null, f); - } - - // data !! - if (compareData) { - try { - compareVariableData(org, copy, showCompare, f); - - } catch (IOException e) { - ByteArrayOutputStream bos = new ByteArrayOutputStream(10000); - e.printStackTrace(new PrintStream(bos)); - f.format("%s", bos.toString()); - } - } - - // nested variables - if (org instanceof Structure) { - assert (copy instanceof Structure); - Structure orgS = (Structure) org; - Structure ncmlS = (Structure) copy; - - List vars = new ArrayList(); - ok &= checkAll(orgS.getVariables(), ncmlS.getVariables(), vars, f); - for (int i = 0; i < vars.size(); i += 2) { - Variable orgV = (Variable) vars.get(i); - Variable ncmlV = (Variable) vars.get(i + 1); - ok &= compareVariables(orgV, ncmlV, false, f); - } - } - - return ok; - } - - // make sure each object in wantList is contained in container, using equals(). - static public boolean checkContains(List container, List wantList, Formatter f) { - boolean ok = true; - - for (Object want1 : wantList) { - int index2 = container.indexOf(want1); - if (index2 < 0) { - f.format(" ** %s %s missing %n", want1.getClass().getName(), want1); - ok = false; - } - } - - return ok; - } - - - // make sure each object in each list are in the other list, using equals(). - // return an arrayList of paired objects. - private boolean checkAll(List list1, List list2, List result, Formatter f) { - boolean ok = true; - - for (Object aList1 : list1) { - ok &= checkEach(aList1, "file1", list1, "file2", list2, result, f); - } - - for (Object aList2 : list2) { - ok &= checkEach(aList2, "file2", list2, "file1", list1, result, f); - } - - return ok; - } - - // check that want is in both list1 and list2, using object.equals() - private boolean checkEach(Object want1, String name1, List list1, String name2, List list2, List result, - Formatter f) { - boolean ok = true; - try { - int index2 = list2.indexOf(want1); - if (index2 < 0) { - f.format(" ** %s %s (%s) not in %s %n", want1.getClass().getName(), want1, name1, name2); - ok = false; - } else { // found it in second list - Object want2 = list2.get(index2); - int index1 = list1.indexOf(want2); - if (index1 < 0) { // can this happen ?? - f.format(" ** %s %s (%s) not in %s %n", want2.getClass().getName(), want2, name2, name1); - ok = false; - - } else { // found it in both lists - Object want = list1.get(index1); - if (want != want1) { - f.format(" ** %s %s (%s) not equal to %s (%s) %n", want1.getClass().getName(), want1, name1, want2, name2); - ok = false; - } else { - if (showEach) - f.format(" OK <%s> equals <%s>%n", want1, want2); - if (result != null) { - result.add(want1); - result.add(want2); - } - } - } - } - - } catch (Throwable t) { - f.format(" *** Throwable= %s %n", t.getMessage()); - } - - return ok; - } - - static private void compareVariableData(Variable var1, Variable var2, boolean showCompare, Formatter f) - throws IOException { - Array data1 = var1.read(); - Array data2 = var2.read(); - - if (showCompare) - f.format(" compareArrays %s unlimited=%s size=%d%n", var1.getNameAndDimensions(), var1.isUnlimited(), - data1.getSize()); - compareData(data1, data2); - if (showCompare) - f.format(" ok%n"); - } - - static public void compareData(Array data1, Array data2) { - compareData(data1, data2, true); - } - - static public void compareData(Array data1, double[] data2) { - Array data2a = Array.factory(DataType.DOUBLE, new int[] {data2.length}, data2); - compareData(data1, data2a, false); - } - - static private void compareData(Array data1, Array data2, boolean checkType) { - Assert.assertEquals("data size", data1.getSize(), data2.getSize()); - Assert.assertEquals("data unsigned", data1.isUnsigned(), data2.isUnsigned()); - if (checkType) - assert data1.getElementType() == data2.getElementType() : data1.getElementType() + "!=" + data2.getElementType(); - DataType dt = DataType.getType(data1); - - IndexIterator iter1 = data1.getIndexIterator(); - IndexIterator iter2 = data2.getIndexIterator(); - - if (dt == DataType.DOUBLE) { - while (iter1.hasNext() && iter2.hasNext()) { - double v1 = iter1.getDoubleNext(); - double v2 = iter2.getDoubleNext(); - assert Misc.nearlyEquals(v1, v2) : String.format("%f != %f; count = %s, absDiff = %f, relDiff = %f", v1, v2, - iter1, Misc.absoluteDifference(v1, v2), Misc.relativeDifference(v1, v2)); - } - } else if (dt == DataType.FLOAT) { - while (iter1.hasNext() && iter2.hasNext()) { - float v1 = iter1.getFloatNext(); - float v2 = iter2.getFloatNext(); - assert Misc.nearlyEquals(v1, v2) : String.format("%f != %f; count = %s, absDiff = %f, relDiff = %f", v1, v2, - iter1, Misc.absoluteDifference(v1, v2), Misc.relativeDifference(v1, v2)); - } - } else if (dt.getPrimitiveClassType() == int.class) { - while (iter1.hasNext() && iter2.hasNext()) { - int v1 = iter1.getIntNext(); - int v2 = iter2.getIntNext(); - assert v1 == v2 : v1 + " != " + v2 + " count=" + iter1; - } - } else if (dt.getPrimitiveClassType() == short.class) { - while (iter1.hasNext() && iter2.hasNext()) { - short v1 = iter1.getShortNext(); - short v2 = iter2.getShortNext(); - assert v1 == v2 : v1 + " != " + v2 + " count=" + iter1; - } - } else if (dt.getPrimitiveClassType() == byte.class) { - while (iter1.hasNext() && iter2.hasNext()) { - byte v1 = iter1.getByteNext(); - byte v2 = iter2.getByteNext(); - assert v1 == v2 : v1 + " != " + v2 + " count=" + iter1; - } - } else if (dt.getPrimitiveClassType() == long.class) { - while (iter1.hasNext() && iter2.hasNext()) { - long v1 = iter1.getLongNext(); - long v2 = iter2.getLongNext(); - assert v1 == v2 : v1 + " != " + v2 + " count=" + iter1; - } - } else if (dt == DataType.STRUCTURE) { - while (iter1.hasNext() && iter2.hasNext()) { - compareStructureData((StructureData) iter1.next(), (StructureData) iter2.next()); - } - } - } - - static public void compareStructureData(StructureData sdata1, StructureData sdata2) { - StructureMembers sm1 = sdata1.getStructureMembers(); - StructureMembers sm2 = sdata2.getStructureMembers(); - assert sm1.getMembers().size() == sm2.getMembers().size(); - - for (StructureMembers.Member m1 : sm1.getMembers()) { - if (m1.getName().equals("time")) - continue; - StructureMembers.Member m2 = sm2.findMember(m1.getName()); - Array data1 = sdata1.getArray(m1); - Array data2 = sdata2.getArray(m2); - compareData(data1, data2, true); - } - } -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/Diff.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/Diff.java deleted file mode 100644 index 5339261a69..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/Diff.java +++ /dev/null @@ -1,841 +0,0 @@ -package ucar.unidata.util.test; - - -// Diff -- text file difference utility. -// See full docu-comment at beginning of Diff class. - -/* - * Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002. - * All rights reserved. Software written by Ian F. Darwin and others. - * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $ - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Java, the Duke mascot, and all variants of Sun's Java 'steaming coffee cup' - * logo are trademarks of Sun Microsystems. Sun's, and James Gosling's, - * pioneering role in inventing and promulgating (and standardizing) the Java - * language and environment is gratefully acknowledged. - * - * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&T, for - * inventing predecessor languages C and C+is also gratefully acknowledged. - */ - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - - -/** - * This is the info kept per-file. - */ -class fileInfo { - - static final int MAXLINECOUNT = 20000; - - BufferedReader file; /* File handle that is open for read. */ - public int maxLine; /* After input done, # lines in file. */ - node symbol[]; /* The symtab handle of each line. */ - int other[]; /* Map of line# to line# in other file */ - /* ( -1 means don't-know ). */ - /* Allocated AFTER the lines are read. */ - - /** - * Normal constructor with one filename; file is opened and saved. - */ - public fileInfo(String filename) throws Exception { - symbol = new node[MAXLINECOUNT + 2]; - other = null; // allocated later! - Path filepath = Paths.get(filename); - file = Files.newBufferedReader(filepath, StandardCharsets.UTF_8); - } - - public fileInfo(Reader rdr) throws Exception { - symbol = new node[MAXLINECOUNT + 2]; - other = null; // allocated later! - file = new BufferedReader(rdr); - } - - // This is done late, to be same size as # lines in input file. - - void alloc() { - other = new int[symbol.length + 2]; - } -}; - - -/** - * diff Text file difference utility. - * ---- Copyright 1987, 1989 by Donald C. Lindsay, - * School of Computer Science, Carnegie Mellon University. - * Copyright 1982 by Symbionics. - * Use without fee is permitted when not for direct commercial - * advantage, and when credit to the source is given. Other uses - * require specific permission. - *

- *

- * Converted from C to Java by Ian F. Darwin, http://www.darwinsys.com/, January, 1997. - * Copyright 1997, Ian F. Darwin. - *

- *

- * Conversion is NOT FULLY TESTED. - *

- *

- * USAGE: diff oldfile newfile - *

- *

- * This program assumes that "oldfile" and "newfile" are text files. - * The program writes to stdout a description of the changes which would - * transform "oldfile" into "newfile". - *

- *

- * The printout is in the form of commands, each followed by a block of - * text. The text is delimited by the commands, which are: - *

- *

- * DELETE AT n - * ..deleted lines - *

- *

- * INSERT BEFORE n - * ..inserted lines - *

- *

- * n MOVED TO BEFORE n - * ..moved lines - *

- *

- * n CHANGED FROM - * ..old lines - * CHANGED TO - * ..newer lines - *

- *

- * The line numbers all refer to the lines of the oldfile, as they are - * numbered before any commands are applied. - * The text lines are printed as-is, without indentation or prefixing. The - * commands are printed in upper case, with a prefix of {@code ">>>>"}, so that - * they will stand out. Other schemes may be preferred. - * Files which contain more than MAXLINECOUNT lines cannot be processed. - * This can be fixed by changing "symbol" to a Vector. - * The algorithm is taken from Communications of the ACM, Apr78 (21, 4, 264-), - * "A Technique for Isolating Differences Between Files." - * Ignoring I/O, and ignoring the symbol table, it should take O(N) time. - * This implementation takes fixed space, plus O(U) space for the symbol - * table (where U is the number of unique lines). Methods exist to change - * the fixed space to O(N) space. - * Note that this is not the only interesting file-difference algorithm. In - * general, different algorithms draw different conclusions about the - * changes that have been made to the oldfile. This algorithm is sometimes - * "more right", particularly since it does not consider a block move to be - * an insertion and a (separate) deletion. However, on some files it will be - * "less right". This is a consequence of the fact that files may contain - * many identical lines (particularly if they are program source). Each - * algorithm resolves the ambiguity in its own way, and the resolution - * is never guaranteed to be "right". However, it is often excellent. - * This program is intended to be pedagogic. Specifically, this program was - * the basis of the Literate Programming column which appeared in the - * Communications of the ACM (CACM), in the June 1989 issue (32, 6, - * 740-755). - * By "pedagogic", I do not mean that the program is gracefully worded, or - * that it showcases language features or its algorithm. I also do not mean - * that it is highly accessible to beginners, or that it is intended to be - * read in full, or in a particular order. Rather, this program is an - * example of one professional's style of keeping things organized and - * maintainable. - * The program would be better if the "print" variables were wrapped into - * a struct. In general, grouping related variables in this way improves - * documentation, and adds the ability to pass the group in argument lists. - * This program is a de-engineered version of a program which uses less - * memory and less time. The article points out that the "symbol" arrays - * can be implemented as arrays of pointers to arrays, with dynamic - * allocation of the subarrays. (In C, macros are very useful for hiding - * the two-level accesses.) In Java, a Vector would be used. This allows an - * extremely large value for MAXLINECOUNT, without dedicating fixed arrays. - * (The "other" array can be allocated after the input phase, when the exact - * sizes are known.) The only slow piece of code is the "strcmp" in the tree - * descent: it can be speeded up by keeping a hash in the tree node, and - * only using "strcmp" when two hashes happen to be equal. - *

- *

- * Change Log - * ---------- - * 1Jan97 Ian F. Darwin: first working rewrite in Java, based entirely on - * D.C.Lindsay's reasonable C version. - * Changed comments from /***************** to /**, shortened, added - * whitespace, used tabs more, etc. - * 6jul89 D.C.Lindsay, CMU: fixed portability bug. Thanks, Gregg Wonderly. - * Just changed "char ch" to "int ch". - * Also added comment about way to improve code. - * 10jun89 D.C.Lindsay, CMU: posted version created. - * Copyright notice changed to ACM style, and Dept. is now School. - * ACM article referenced in docn. - * 26sep87 D.C.Lindsay, CMU: publication version created. - * Condensed all 1982/83 change log entries. - * Removed all command line options, and supporting code. This - * simplified the input code (no case reduction etc). It also - * simplified the symbol table, which was capable of remembering - * offsets into files (instead of strings), and trusting (!) hash - * values to be unique. - * Removed dynamic allocation of arrays: now fixed static arrays. - * Removed speed optimizations in symtab package. - * Removed string compression/decompression code. - * Recoded to Unix standards from old Lattice/MSDOS standards. - * (This affected only the #include's and the IO.) - * Some renaming of variables, and rewording of comments. - * 1982/83 D.C.Lindsay, Symbionics: created. - * - * @author Ian F. Darwin, Java version - * @author D. C. Lindsay, C version (1982-1987) - * @version Java version 0.9, 1997 - */ - -public class Diff { - - /** - * block len > any possible real block len - */ - final int UNREAL = Integer.MAX_VALUE; - - /** - * Keeps track of information about file1 and file2 - */ - fileInfo oldinfo, newinfo; - - PrintWriter printer = null; - - String identifier = ""; - - - /** - * blocklen is the info about found blocks. It will be set to 0, except - * at the line#s where blocks start in the old file. At these places it - * will be set to the # of lines in the block. During printout , - * this # will be reset to -1 if the block is printed as a MOVE block - * (because the printout phase will encounter the block twice, but - * must only print it once.) - * The array declarations are to MAXLINECOUNT+2 so that we can have two - * extra lines (pseudolines) at line# 0 and line# MAXLINECOUNT+1 - * (or less). - */ - int blocklen[]; - - /** - * main - entry point when used standalone. - * NOTE: no routines return error codes or throw any local - * exceptions. Instead, any routine may complain - * to stderr and then exit with error to the system. - */ - public static void main(String argstrings[]) throws Exception { - if (argstrings.length != 2) { - System.err.println("Usage: diff oldfile newfile"); - System.exit(1); - } - Diff d = new Diff("Diff"); - d.doDiff(argstrings[0], argstrings[1]); - return; - } - - /** - * Construct a Diff object. - */ - public Diff(String id) { - identifier = id; - } - - - /* Do comparison against two Reader streams */ - - public boolean doDiff(Reader oldFile, Reader newFile, Writer out) throws Exception { - this.printer = new PrintWriter(out); - oldinfo = new fileInfo(oldFile); - newinfo = new fileInfo(newFile); - return process(); - } - - public boolean doDiff(Reader oldFile, Reader newFile) throws Exception { - Writer w = new OutputStreamWriter(System.out); - return doDiff(oldFile, newFile, w); - } - - /* Do comparison against two string streams */ - - public boolean doDiff(String data1, String data2, Writer out) throws Exception { - if (data1 == null || data2 == null) - return false; - return doDiff(new StringReader(data1), new StringReader(data2), out); - } - - public boolean doDiff(String data1, String data2) throws Exception { - return doDiff(data1, data2, new OutputStreamWriter(System.out)); - } - - boolean process() throws Exception { - /* we don't process until we know both files really do exist. */ - inputscan(oldinfo); - inputscan(newinfo); - - /* - * Now that we've read all the lines, allocate some arrays. - */ - blocklen = new int[(oldinfo.maxLine > newinfo.maxLine ? oldinfo.maxLine : newinfo.maxLine) + 2]; - oldinfo.alloc(); - newinfo.alloc(); - - /* Now do the work, and print the results. */ - transform(); - return printout(); - } - - static boolean isBlankLine(String s) { - int index = 0; - int len = s.length(); - for (index = len - 1; index >= 0; index--) { - if (" \t\r".indexOf(s.charAt(index)) < 0) - return false; - } - return true; - } - - /** - * inputscan Reads the file specified by pinfo.file. - * --------- Places the lines of that file in the symbol table. - * Sets pinfo.maxLine to the number of lines found. - */ - void inputscan(fileInfo pinfo) throws IOException { - String linebuffer; - pinfo.maxLine = 0; - while ((linebuffer = pinfo.file.readLine()) != null) { - if (!isBlankLine(linebuffer)) - storeline(linebuffer, pinfo); - } - } - - /** - * storeline Places line into symbol table. - * --------- Expects pinfo.maxLine initted: increments. - * Places symbol table handle in pinfo.ymbol. - * Expects pinfo is either oldinfo or newinfo. - */ - void storeline(String linebuffer, fileInfo pinfo) { - int linenum = ++pinfo.maxLine; /* note, no line zero */ - if (linenum > fileInfo.MAXLINECOUNT) { - System.err.println("MAXLINECOUNT exceeded, must stop."); - System.exit(1); - } - pinfo.symbol[linenum] = node.addSymbol(this, linebuffer, pinfo == oldinfo, linenum); - } - - /* - * transform - * Analyzes the file differences and leaves its findings in - * the global arrays oldinfo.other, newinfo.other, and blocklen. - * Expects both files in symtab. - * Expects valid "maxLine" and "symbol" in oldinfo and newinfo. - */ - - void transform() { - int oldline, newline; - int oldmax = oldinfo.maxLine + 2; /* Count pseudolines at */ - int newmax = newinfo.maxLine + 2; /* ..front and rear of file */ - - for (oldline = 0; oldline < oldmax; oldline++) - oldinfo.other[oldline] = -1; - for (newline = 0; newline < newmax; newline++) - newinfo.other[newline] = -1; - - scanunique(); /* scan for lines used once in both files */ - scanafter(); /* scan past sure-matches for non-unique blocks */ - scanbefore(); /* scan backwards from sure-matches */ - scanblocks(); /* find the fronts and lengths of blocks */ - } - - /* - * scanunique - * Scans for lines which are used exactly once in each file. - * Expects both files in symtab, and oldinfo and newinfo valid. - * The appropriate "other" array entries are set to the line# in - * the other file. - * Claims pseudo-lines at 0 and XXXinfo.maxLine+1 are unique. - */ - - void scanunique() { - int oldline, newline; - node psymbol; - - for (newline = 1; newline <= newinfo.maxLine; newline++) { - psymbol = newinfo.symbol[newline]; - if (psymbol.symbolIsUnique()) { // 1 use in each file - oldline = psymbol.linenum; - newinfo.other[newline] = oldline; // record 1-1 map - oldinfo.other[oldline] = newline; - } - } - newinfo.other[0] = 0; - oldinfo.other[0] = 0; - newinfo.other[newinfo.maxLine + 1] = oldinfo.maxLine + 1; - oldinfo.other[oldinfo.maxLine + 1] = newinfo.maxLine + 1; - } - - /* - * scanafter - * Expects both files in symtab, and oldinfo and newinfo valid. - * Expects the "other" arrays contain positive #s to indicate - * lines that are unique in both files. - * For each such pair of places, scans past in each file. - * Contiguous groups of lines that match non-uniquely are - * taken to be good-enough matches, and so marked in "other". - * Assumes each other[0] is 0. - */ - - void scanafter() { - int oldline, newline; - - for (newline = 0; newline <= newinfo.maxLine; newline++) { - oldline = newinfo.other[newline]; - if (oldline >= 0) { /* is unique in old & new */ - for (;;) { /* scan after there in both files */ - if (++oldline > oldinfo.maxLine) - break; - if (oldinfo.other[oldline] >= 0) - break; - if (++newline > newinfo.maxLine) - break; - if (newinfo.other[newline] >= 0) - break; - - /* - * oldline & newline exist, and - * aren't already matched - */ - - if (newinfo.symbol[newline] != oldinfo.symbol[oldline]) - break; // not same - - newinfo.other[newline] = oldline; // record a match - oldinfo.other[oldline] = newline; - } - } - } - } - - /** - * scanbefore - * As scanafter, except scans towards file fronts. - * Assumes the off-end lines have been marked as a match. - */ - void scanbefore() { - int oldline, newline; - - for (newline = newinfo.maxLine + 1; newline > 0; newline--) { - oldline = newinfo.other[newline]; - if (oldline >= 0) { /* unique in each */ - for (;;) { - if (--oldline <= 0) - break; - if (oldinfo.other[oldline] >= 0) - break; - if (--newline <= 0) - break; - if (newinfo.other[newline] >= 0) - break; - - /* - * oldline and newline exist, - * and aren't marked yet - */ - - if (newinfo.symbol[newline] != oldinfo.symbol[oldline]) - break; // not same - - newinfo.other[newline] = oldline; // record a match - oldinfo.other[oldline] = newline; - } - } - } - } - - /** - * scanblocks - Finds the beginnings and lengths of blocks of matches. - * Sets the blocklen array (see definition). - * Expects oldinfo valid. - */ - void scanblocks() { - int oldline, newline; - int oldfront = 0; // line# of front of a block in old, or 0 - int newlast = -1; // newline's value during prev. iteration - - for (oldline = 1; oldline <= oldinfo.maxLine; oldline++) - blocklen[oldline] = 0; - blocklen[oldinfo.maxLine + 1] = UNREAL; // starts a mythical blk - - for (oldline = 1; oldline <= oldinfo.maxLine; oldline++) { - newline = oldinfo.other[oldline]; - if (newline < 0) - oldfront = 0; /* no match: not in block */ - else { /* match. */ - if (oldfront == 0) - oldfront = oldline; - if (newline != (newlast + 1)) - oldfront = oldline; - ++blocklen[oldfront]; - } - newlast = newline; - } - } - - /* The following are global to printout's subsidiary routines */ - // enum{ idle, delete, insert, movenew, moveold, - // same, change } printstatus; - public static final int idle = 0, delete = 1, insert = 2, movenew = 3, moveold = 4, same = 5, change = 6; - int printstatus; - boolean anyprinted; - int printoldline, printnewline; // line numbers in old & new file - - /** - * printout - Prints summary to stdout. - * Expects all data structures have been filled out. - * - * @return true if differences detected - */ - boolean printout() { - printstatus = idle; - anyprinted = false; - for (printoldline = printnewline = 1;;) { - if (printoldline > oldinfo.maxLine) { - newconsume(); - break; - } - if (printnewline > newinfo.maxLine) { - oldconsume(); - break; - } - if (newinfo.other[printnewline] < 0) { - if (oldinfo.other[printoldline] < 0) - showchange(); - else - showinsert(); - } else if (oldinfo.other[printoldline] < 0) - showdelete(); - else if (blocklen[printoldline] < 0) - skipold(); - else if (oldinfo.other[printoldline] == printnewline) - showsame(); - else - showmove(); - } - if (anyprinted == true) - println(">>>> " + identifier + ": End of differences."); - else - println(">>>> " + identifier + ": Files are identical."); - return anyprinted; - } - - /* - * newconsume Part of printout. Have run out of old file. - * Print the rest of the new file, as inserts and/or moves. - */ - - void newconsume() { - for (;;) { - if (printnewline > newinfo.maxLine) - break; /* end of file */ - if (newinfo.other[printnewline] < 0) - showinsert(); - else - showmove(); - } - } - - /** - * oldconsume Part of printout. Have run out of new file. - * Process the rest of the old file, printing any - * parts which were deletes or moves. - */ - void oldconsume() { - for (;;) { - if (printoldline > oldinfo.maxLine) - break; /* end of file */ - printnewline = oldinfo.other[printoldline]; - if (printnewline < 0) - showdelete(); - else if (blocklen[printoldline] < 0) - skipold(); - else - showmove(); - } - } - - /** - * showdelete Part of printout. - * Expects printoldline is at a deletion. - */ - void showdelete() { - if (printstatus != delete) - println(">>>> DELETE AT " + printoldline); - printstatus = delete; - oldinfo.symbol[printoldline].showSymbol(); - anyprinted = true; - printoldline++; - } - - /* - * showinsert Part of printout. - * Expects printnewline is at an insertion. - */ - - void showinsert() { - if (printstatus == change) - println(">>>> CHANGED TO"); - else if (printstatus != insert) - println(">>>> INSERT BEFORE " + printoldline); - printstatus = insert; - newinfo.symbol[printnewline].showSymbol(); - anyprinted = true; - printnewline++; - } - - /** - * showchange Part of printout. - * Expects printnewline is an insertion. - * Expects printoldline is a deletion. - */ - void showchange() { - if (printstatus != change) - println(">>>> " + printoldline + " CHANGED FROM"); - printstatus = change; - oldinfo.symbol[printoldline].showSymbol(); - anyprinted = true; - printoldline++; - } - - /** - * skipold Part of printout. - * Expects printoldline at start of an old block that has - * already been announced as a move. - * Skips over the old block. - */ - void skipold() { - printstatus = idle; - for (;;) { - if (++printoldline > oldinfo.maxLine) - break; /* end of file */ - if (oldinfo.other[printoldline] < 0) - break; /* end of block */ - if (blocklen[printoldline] != 0) - break; /* start of another */ - } - } - - /** - * skipnew Part of printout. - * Expects printnewline is at start of a new block that has - * already been announced as a move. - * Skips over the new block. - */ - void skipnew() { - int oldline; - printstatus = idle; - for (;;) { - if (++printnewline > newinfo.maxLine) - break; /* end of file */ - oldline = newinfo.other[printnewline]; - if (oldline < 0) - break; /* end of block */ - if (blocklen[oldline] != 0) - break; /* start of another */ - } - } - - /** - * showsame Part of printout. - * Expects printnewline and printoldline at start of - * two blocks that aren't to be displayed. - */ - void showsame() { - int count; - printstatus = idle; - if (newinfo.other[printnewline] != printoldline) { - System.err.println("BUG IN LINE REFERENCING"); - System.exit(1); - } - count = blocklen[printoldline]; - printoldline += count; - printnewline += count; - } - - /** - * showmove Part of printout. - * Expects printoldline, printnewline at start of - * two different blocks ( a move was done). - */ - void showmove() { - int oldblock = blocklen[printoldline]; - int newother = newinfo.other[printnewline]; - int newblock = blocklen[newother]; - - if (newblock < 0) - skipnew(); // already printed. - else if (oldblock >= newblock) { // assume new's blk moved. - blocklen[newother] = -1; // stamp block as "printed". - println(">>>> " + newother + " THRU " + (newother + newblock - 1) + " MOVED TO BEFORE " + printoldline); - for (; newblock > 0; newblock--, printnewline++) - newinfo.symbol[printnewline].showSymbol(); - anyprinted = true; - printstatus = idle; - - } else /* assume old's block moved */ - skipold(); /* target line# not known, display later */ - } - - /** - * Convenience wrapper for println - */ - public void println(String s) { - printer.println(s); - printer.flush(); - } - -}; // end of main class! - - -/** - * Class "node". The symbol table routines in this class all - * understand the symbol table format, which is a binary tree. - * The methods are: addSymbol, symbolIsUnique, showSymbol. - */ -class node { /* the tree is made up of these nodes */ - - static Diff diff = null; - static node panchor = null; /* symtab is a tree hung from this */ - static final int freshnode = 0, oldonce = 1, newonce = 2, bothonce = 3, other = 4; - - node pleft, pright; - int linenum; - int /* enum linestates */ linestate; - String line; - - /** - * Construct a new symbol table node and fill in its fields. - * - * @param pline string A line of the text file - */ - public node(String pline) { - pleft = pright = null; - linestate = freshnode; - /* linenum field is not always valid */ - line = pline; - } - - /** - * matchsymbol Searches tree for a match to the line. - * - * @param pline String pline, a line of text - * If node's linestate == freshnode, then created the node. - */ - static node matchsymbol(String pline) { - int comparison; - node pnode = panchor; - if (panchor == null) - return panchor = new node(pline); - for (;;) { - comparison = linecompare(pnode.line, pline); - if (comparison == 0) - return pnode; /* found */ - - if (comparison < 0) { - if (pnode.pleft == null) { - pnode.pleft = new node(pline); - return pnode.pleft; - } - pnode = pnode.pleft; - } - if (comparison > 0) { - if (pnode.pright == null) { - pnode.pright = new node(pline); - return pnode.pright; - } - pnode = pnode.pright; - } - } - /* NOTE: There are return stmts, so control does not get here. */ - } - - /** - * addSymbol(String pline) - Saves line into the symbol table. - * Returns a handle to the symtab entry for that unique line. - * If inoldfile nonzero, then linenum is remembered. - */ - static node addSymbol(Diff diff, String pline, boolean inoldfile, int linenum) { - node.diff = diff; - node pnode; - pnode = matchsymbol(pline); /* find the node in the tree */ - if (pnode.linestate == freshnode) { - pnode.linestate = inoldfile ? oldonce : newonce; - } else { - if ((pnode.linestate == oldonce && !inoldfile) || (pnode.linestate == newonce && inoldfile)) - pnode.linestate = bothonce; - else - pnode.linestate = other; - } - if (inoldfile) - pnode.linenum = linenum; - return pnode; - } - - /** - * symbolIsUnique Arg is a ptr previously returned by addSymbol. - * -------------- Returns true if the line was added to the - * symbol table exactly once with inoldfile true, - * and exactly once with inoldfile false. - */ - boolean symbolIsUnique() { - return (linestate == bothonce); - } - - /** - * showSymbol Prints the line to stdout. - */ - void showSymbol() { - diff.printer.println(line); - } - - static String compact(String line) { - // trim and remove return characters - String[] pieces = line.trim().split("\r"); - line = ""; - for (String s : pieces) - line = line + s; - // Break line on whitespace and compact - pieces = line.split("[ \t\n][ \t\n]*"); - line = ""; - for (String s : pieces) - line = line + s; - return line; - } - - static int linecompare(String line1, String line2) { - return compact(line1).compareToIgnoreCase(compact(line2)); - } - -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/SysStreamLogger.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/SysStreamLogger.java deleted file mode 100644 index 14140388c1..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/SysStreamLogger.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * - * Now it's possible to redirect Sytem.out/err by calling - * SysStreamsLogger.bindSystemStreams() at the begining of your - * application. - * - * Logging Output looks like this (from OpenEJB startup) - * - * 2012-06-27 13:44:12,792 INFO [main:] SYSOUT:181 - Apache OpenEJB 3.1.4 build: 20101112-03:32 - * 2012-06-27 13:44:12,793 INFO [main:] SYSOUT:181 - http://openejb.apache.org/ - */ - -package ucar.unidata.util.test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.io.PrintStream; - -public class SysStreamLogger { - protected static Logger sysOutLogger = LoggerFactory.getLogger("SYSOUT"); - protected static Logger sysErrLogger = LoggerFactory.getLogger("SYSERR"); - - public static final PrintStream sysout = System.out; - public static final PrintStream syserr = System.err; - - protected static final String LINE_SEPERATOR = System.getProperty("line.separator"); - - public static void bindSystemStreams() { - // Enable autoflush - System.setOut(new PrintStream(new LoggingOutputStream(sysOutLogger, false), true)); - System.setErr(new PrintStream(new LoggingOutputStream(sysErrLogger, true), true)); - } - - public static void unbindSystemStreams() { - System.setOut(sysout); - System.setErr(syserr); - } - - protected static class LoggingOutputStream extends java.io.OutputStream { - protected Logger log; - protected boolean isError; - - /** - * Used to maintain the contract of {@link #close()}. - */ - protected boolean hasBeenClosed = false; - - /** - * The internal buffer where data is stored. - */ - protected byte[] buf; - - /** - * The number of valid bytes in the buffer. This value is always in the - * range 0 through buf.length; elements - * buf[0] through buf[count-1] contain valid byte - * data. - */ - protected int count; - - /** - * Remembers the size of the buffer for speed. - */ - protected int bufLength; - - /** - * The default number of bytes in the buffer. =2048 - */ - public static final int DEFAULT_BUFFER_LENGTH = 2048; - - protected LoggingOutputStream() { - // illegal - } - - /** - * Creates the LoggingOutputStream to flush to the given Category. - * - * @param log the Logger to write to - * @param isError the if true write to error, else info - * @throws IllegalArgumentException if cat == null or priority == null - */ - public LoggingOutputStream(Logger log, boolean isError) throws IllegalArgumentException { - if (log == null) { - throw new IllegalArgumentException("log == null"); - } - - this.isError = isError; - this.log = log; - bufLength = DEFAULT_BUFFER_LENGTH; - buf = new byte[DEFAULT_BUFFER_LENGTH]; - count = 0; - } - - /** - * Closes this output stream and releases any system resources - * associated with this stream. The general contract of - * close is that it closes the output stream. A closed - * stream cannot perform output operations and cannot be reopened. - */ - @Override - public void close() { - flush(); - hasBeenClosed = true; - } - - /** - * Writes the specified byte to this output stream. The general contract - * for write is that one byte is written to the output - * stream. The byte to be written is the eight low-order bits of the - * argument b. The 24 high-order bits of b are - * ignored. - * - * @param b the byte to write - */ - @Override - public void write(final int b) throws IOException { - if (hasBeenClosed) { - throw new IOException("The stream has been closed."); - } - - // don't log nulls - if (b == 0) { - return; - } - - // would this be writing past the buffer? - if (count == bufLength) { - // grow the buffer - final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH; - final byte[] newBuf = new byte[newBufLength]; - - System.arraycopy(buf, 0, newBuf, 0, bufLength); - - buf = newBuf; - bufLength = newBufLength; - } - - buf[count] = (byte) b; - count++; - } - - /** - * Flushes this output stream and forces any buffered output bytes to be - * written out. The general contract of flush is that - * calling it is an indication that, if any bytes previously written - * have been buffered by the implementation of the output stream, such - * bytes should immediately be written to their intended destination. - */ - @Override - public void flush() { - - if (count == 0) { - return; - } - - // don't print out blank lines; flushing from PrintStream puts out - // these - if (count == LINE_SEPERATOR.length()) { - if (((char) buf[0]) == LINE_SEPERATOR.charAt(0) && ((count == 1) || // <- - // Unix - // & - // Mac, - // -> - // Windows - ((count == 2) && ((char) buf[1]) == LINE_SEPERATOR.charAt(1)))) { - reset(); - return; - } - } - - final byte[] theBytes = new byte[count]; - - System.arraycopy(buf, 0, theBytes, 0, count); - - if (isError) { - log.error(new String(theBytes)); - } else { - log.info(new String(theBytes)); - } - - reset(); - } - - protected void reset() { - // not resetting the buffer -- assuming that if it grew that it - // will likely grow similarly again - count = 0; - } - } -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/TestDir.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/TestDir.java deleted file mode 100644 index 485c6f1051..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/TestDir.java +++ /dev/null @@ -1,376 +0,0 @@ -package ucar.unidata.util.test; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import ucar.ma2.InvalidRangeException; -import ucar.ma2.Section; -import ucar.nc2.NetcdfFile; -import ucar.nc2.NetcdfFiles; -import ucar.nc2.Variable; -import ucar.nc2.util.AliasTranslator; -import ucar.unidata.io.RandomAccessFile; -import ucar.unidata.util.StringUtil2; -import java.io.*; -import java.lang.invoke.MethodHandles; -import java.util.*; - -/** - * Manage the test data directories and servers. - * - * @author caron - * @since 3/23/12 - * - *

- * - * - * - * - * - * - *
Java System Property Names
-D Property Names - *
Static Variable - * Property Name(s) - * Description - *
testdataDirPropName - * unidata.testdata.path - * Property name for the path to the Unidata test data directory, - * e.g unidata.testdata.path=/share/testdata - *
remoteTestServerPropName - * remotetest - * Property name for the hostname of the C-library remote test server. - *
- *

- * - * - * - * - * - * - * - *
Computed Paths
Computed Paths - *
Static Variable - * Property Name(s) (-d) - * Default Value - * Description - *
cdmUnitTestDir - * NA - * NA - * New test data directory. Do not put temporary files in here. - * Migrate all test data here eventually. - *
cdmLocalTestDataDir - * NA - * ../cdm/src/test/data - * Level 1 test data directory (distributed with code and MAY be used in Unidata nightly testing). - *
remoteTestServer - * remotetestserver - * remotetest.unidata.ucar.edu - * The hostname of the test server for doing C library remote tests. - *
- * - */ -public class TestDir { - private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - /** - * Property name for the path to the Unidata test data directory, e.g "unidata.testdata.path=/share/testdata". - */ - private static String testdataDirPropName = "unidata.testdata.path"; - - /** - * Path to the Unidata test data directory. - */ - public static String testdataDir = null; - - /** - * New test data directory. do not put temporary files in here. migrate all test data here eventually - * Unidata "//fileserver/data/testdata2/cdmUnitTest" directory. - */ - public static String cdmUnitTestDir = null; - - /** - * Level 1 test data directory (distributed with code and MAY be used in Unidata nightly testing). - */ - public static String cdmLocalTestDataDir = "../tds/src/integrationTests/data/"; - - /** - * cdm-test data directory (distributed with code but depends on data not in github) - */ - public static String cdmTestDataDir = "../cdm-test/src/test/data/"; - - public static String cdmUseBuildersPropName = "thredds.test.experimental.useNetcdfJavaBuilders"; - public static boolean cdmUseBuilders; - - ////////////////////////////////////////////////////////////////////// - // Various Test Server machines - ////////////////////////////////////////////////////////////////////// - - // Remote Test server(s) - - private static String remoteTestServerPropName = "remotetestserver"; - - static public String remoteTestServer = "localhost:8081"; - - // DAP 2 Test server (for testing) - - static public String dap2TestServerPropName = "dts"; - - static public String dap2TestServer = "localhost:8082"; - - // DAP4 Test server (for testing) - - static public String dap4TestServerPropName = "d4ts"; - - static public String dap4TestServer = "localhost:8083"; - - ////////////////////////////////////////////////// - - static { - testdataDir = System.getProperty(testdataDirPropName); // Check the system property. - - // Use default paths if needed. - if (testdataDir == null) { - testdataDir = "/share/testdata/"; - logger.warn("No '{}' property found; using default value '{}'.", testdataDirPropName, testdataDir); - } - - // Make sure paths ends with a slash. - testdataDir = testdataDir.replace('\\', '/'); // canonical - if (!testdataDir.endsWith("/")) - testdataDir += "/"; - - cdmUnitTestDir = testdataDir + "cdmUnitTest/"; - - File file = new File(cdmUnitTestDir); - if (!file.exists() || !file.isDirectory()) { - logger.warn("cdmUnitTest directory does not exist: {}", file.getAbsolutePath()); - } - - // Initialize various server values - - String rts = System.getProperty(remoteTestServerPropName); - if (rts != null && rts.length() > 0) - remoteTestServer = rts; - - String dts = System.getProperty(dap2TestServerPropName); - if (dts != null && dts.length() > 0) - dap2TestServer = dts; - - String d4ts = System.getProperty(dap4TestServerPropName); - if (d4ts != null && d4ts.length() > 0) - dap4TestServer = d4ts; - - AliasTranslator.addAlias("${cdmUnitTest}", cdmUnitTestDir); - - String useBuilderProp = System.getProperty(cdmUseBuildersPropName, ""); - // default (prop not set) true. Otherwise, check prop. - cdmUseBuilders = useBuilderProp.equals("") ? Boolean.TRUE : Boolean.getBoolean(cdmUseBuildersPropName); - } - - private static boolean isLocationObjectStore(String location) { - return location != null ? (location.startsWith("cdms3:") || location.startsWith("s3:")) : false; - } - - public static NetcdfFile open(String filename) throws IOException { - logger.debug("**** Open {}", filename); - NetcdfFile ncfile; - if (cdmUseBuilders || isLocationObjectStore(filename)) { - ncfile = NetcdfFiles.open(filename, null); - } else { - ncfile = NetcdfFile.open(filename, null); - } - logger.debug("open {}", ncfile); - - return ncfile; - } - - public static NetcdfFile openFileLocal(String filename) throws IOException { - return open(TestDir.cdmLocalTestDataDir + filename); - } - - static public long checkLeaks() { - if (RandomAccessFile.getOpenFiles().size() > 0) { - logger.debug("RandomAccessFile still open:"); - for (String filename : RandomAccessFile.getOpenFiles()) { - logger.debug(" open= {}", filename); - } - } else { - logger.debug("RandomAccessFile: no leaks"); - } - - logger.debug("RandomAccessFile: count open={}, max={}", RandomAccessFile.getOpenFileCount(), - RandomAccessFile.getMaxOpenFileCount()); - return RandomAccessFile.getOpenFiles().size(); - } - - //////////////////////////////////////////////// - - public interface Act { - /** - * @param filename file to act on - * @return count - * @throws IOException on IO error - */ - int doAct(String filename) throws IOException; - } - - public static class FileFilterFromSuffixes implements FileFilter { - String[] suffixes; - - public FileFilterFromSuffixes(String suffixes) { - this.suffixes = suffixes.split(" "); - } - - @Override - public boolean accept(File file) { - for (String s : suffixes) - if (file.getPath().endsWith(s)) - return true; - return false; - } - } - - public static class FileFilterNoWant implements FileFilter { - String[] suffixes; - - public FileFilterNoWant(String suffixes) { - this.suffixes = suffixes.split(" "); - } - - @Override - public boolean accept(File file) { - for (String s : suffixes) - if (file.getPath().endsWith(s)) - return false; - return true; - } - } - - /** - * Call act.doAct() of each file in dirName passing - * - * @param dirName - * @param ff - * @param act - * @return count - * @throws IOException - */ - public static int actOnAll(String dirName, FileFilter ff, Act act) throws IOException { - return actOnAll(dirName, ff, act, true); - } - - public static int actOnAllParameterized(String dirName, FileFilter ff, Collection filenames) - throws IOException { - return actOnAll(dirName, ff, new ListAction(filenames), true); - } - - static class ListAction implements Act { - Collection filenames; - - ListAction(Collection filenames) { - this.filenames = filenames; - } - - @Override - public int doAct(String filename) throws IOException { - filenames.add(new Object[] {filename}); - return 0; - } - } - - /** - * @param dirName recurse into this directory - * @param ff for files that pass this filter, may be null - * @param act perform this acction - * @param recurse recurse into subdirectories - * @return count - * @throws IOException on IO error - */ - public static int actOnAll(String dirName, FileFilter ff, Act act, boolean recurse) throws IOException { - int count = 0; - - logger.debug("---------------Reading directory {}", dirName); - File allDir = new File(dirName); - File[] allFiles = allDir.listFiles(); - if (null == allFiles) { - logger.debug("---------------INVALID {}", dirName); - throw new FileNotFoundException("Cant open " + dirName); - } - - List flist = Arrays.asList(allFiles); - Collections.sort(flist); - - for (File f : flist) { - String name = f.getAbsolutePath(); - if (f.isDirectory()) - continue; - if (((ff == null) || ff.accept(f)) && !name.endsWith(".exclude")) { - name = name.replace("\\", "/"); - logger.debug("----acting on file {}", name); - count += act.doAct(name); - } - } - - if (!recurse) - return count; - - for (File f : allFiles) { - if (f.isDirectory() && !f.getName().equals("exclude") && !f.getName().equals("problem")) - count += actOnAll(f.getAbsolutePath(), ff, act); - } - - return count; - } - - //////////////////////////////////////////////////////////////////////////// - - public static void readAll(String filename) throws IOException { - ReadAllVariables act = new ReadAllVariables(); - act.doAct(filename); - } - - private static class ReadAllVariables implements Act { - @Override - public int doAct(String filename) throws IOException { - if (cdmUseBuilders || isLocationObjectStore(filename)) { - try (NetcdfFile ncfile = NetcdfFiles.open(filename)) { - return readAllData(ncfile); - } - } else { - try (NetcdfFile ncfile = NetcdfFile.open(filename)) { - return readAllData(ncfile); - } - } - } - } - - static int max_size = 1000 * 1000 * 10; - - static Section makeSubset(Variable v) throws InvalidRangeException { - int[] shape = v.getShape(); - shape[0] = 1; - Section s = new Section(shape); - long size = s.computeSize(); - shape[0] = (int) Math.max(1, max_size / size); - return new Section(shape); - } - - static public int readAllData(NetcdfFile ncfile) throws IOException { - logger.debug("------Reading ncfile {}", ncfile.getLocation()); - try { - for (Variable v : ncfile.getVariables()) { - if (v.getSize() > max_size) { - Section s = makeSubset(v); - logger.debug(" Try to read variable {} size={} section={}", v.getNameAndDimensions(), v.getSize(), s); - v.read(s); - } else { - logger.debug(" Try to read variable {} size={}", v.getNameAndDimensions(), v.getSize()); - v.read(); - } - } - - return 1; - } catch (InvalidRangeException e) { - throw new RuntimeException(e); - } - } -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/TestFileDirUtils.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/TestFileDirUtils.java deleted file mode 100644 index d1e9912de0..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/TestFileDirUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ -package ucar.unidata.util.test; - -import org.junit.Assert; -import java.io.File; -import java.io.IOException; -import java.util.Random; - -/** - * Static utilities for testing - * - * @author edavis - * @since Apr 19, 2007 10:11:24 PM - */ -public class TestFileDirUtils { - private TestFileDirUtils() {} - - /** - * In the given parent directory, add a subdirectory. Fail if the parent - * directory doesn't exist or isn't a directory or the new directory - * already exists. - * - * @param parentDir the already existing parent directory. - * @param dirName the directory path to create - * @return the java.io.File that represents the created directory. - */ - public static File addDirectory(File parentDir, String dirName) { - return addDirectory(parentDir, dirName, -1); - } - - public static File addDirectory(File parentDir, String dirName, long lastModTime) { - // Check that the parent directory already exists and is a directory. - Assert.assertTrue("Parent file does not exist <" + parentDir.getPath() + ">.", parentDir.exists()); - Assert.assertTrue("Parent file not a directory <" + parentDir.getPath() + ">.", parentDir.isDirectory()); - - File newDir = new File(parentDir, dirName); - - Assert.assertFalse("New directory already exists [" + newDir.getPath() + "].", newDir.exists()); - - // Create the new directory (including any necessary but nonexistent parent directories). - Assert.assertTrue("Failed to create the new directory [" + newDir.getAbsolutePath() + "].", newDir.mkdirs()); - - if (lastModTime > 0) - Assert.assertTrue("Failed to set lastModified time on directory [" + newDir.getPath() + "].", - newDir.setLastModified(lastModTime)); - - return newDir; - } - - /** - * Add a file directly in the given parent directory. Fail if the parent - * directory doesn't exist or isn't a directory or if the new file - * already exists. - * - * @param parentDir the already existing parent directory. - * @param fileName the name of the file to create (may not contain multiple path segments). - * @return the java.io.File that represents the created file. - */ - public static File addFile(File parentDir, String fileName) { - return addFile(parentDir, fileName, -1); - } - - public static File addFile(File parentDir, String fileName, long lastModTime) { - // Check that the parent directory already exists and is a directory. - Assert.assertTrue("Parent file does not exist <" + parentDir.getPath() + ">.", parentDir.exists()); - Assert.assertTrue("Parent file not a directory <" + parentDir.getPath() + ">.", parentDir.isDirectory()); - - File newFile = new File(parentDir, fileName); - - Assert.assertFalse("New file [" + newFile.getAbsolutePath() + "] already exists.", newFile.exists()); - - // Make sure the new file is directly contained in the parent directory, not a subdirectory. - Assert.assertTrue("Multiple levels not allowed in file name <" + fileName + ">.", - newFile.getParentFile().equals(parentDir)); - - try { - Assert.assertTrue("Failed to create new file [" + newFile.getAbsolutePath() + "].", newFile.createNewFile()); - } catch (IOException e) { - Assert.fail("Failed to create new file <" + newFile.getAbsolutePath() + ">: " + e.getMessage()); - } - if (lastModTime > 0) - Assert.assertTrue("Failed to set lastModified time on file [" + newFile.getPath() + "].", - newFile.setLastModified(lastModTime)); - - return newFile; - } -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsMa2Test.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsMa2Test.java deleted file mode 100644 index 6d8f110b30..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsMa2Test.java +++ /dev/null @@ -1,37 +0,0 @@ -package ucar.unidata.util.test; - -import ucar.ma2.Array; - -/** - * ma2 testing utilities - * - * @author caron - * @since 3/23/12 - */ -public class UtilsMa2Test { - - static public void testEquals(Array array1, Array array2) { - assert array1.getElementType() == array2.getElementType(); - assert array1.getSize() == array2.getSize(); - - testShape(array1.getShape(), array2.getShape()); - - // see if backing store is identical content - Object jarray1 = array1.getStorage(); - Object jarray2 = array1.getStorage(); - int n = (int) array1.getSize(); - for (int i = 0; i < n; i++) - assert (java.lang.reflect.Array.get(jarray1, i).equals(java.lang.reflect.Array.get(jarray2, i))); - } - - static private void testShape(int[] shape1, int shape2[]) { - assert shape1.length == shape2.length; - for (int i = 0; i < shape1.length; i++) - assert shape1[i] == shape2[i]; - } - - static public void testJarrayEquals(Object jarray1, Object jarray2, int n) { - for (int i = 0; i < n; i++) - assert (java.lang.reflect.Array.get(jarray1, i).equals(java.lang.reflect.Array.get(jarray2, i))); - } -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsTestStructureArray.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsTestStructureArray.java deleted file mode 100644 index 8d35a0f261..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/UtilsTestStructureArray.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ -package ucar.unidata.util.test; - -import ucar.ma2.*; -import java.util.List; -import java.io.IOException; - -/** - * @author caron - * @since Apr 14, 2008 - */ -public class UtilsTestStructureArray { - - public void testArrayStructure(ArrayStructure as) { - try { - testArrayStructureByRecno(as); - testArrayStructureByIterator(as); - testArrayStructureByMemberArray(as); - - } catch (IOException e) { - assert false; - } - } - - private double testArrayStructureByMemberArray(ArrayStructure as) throws IOException { - List members = as.getMembers(); - - for (StructureMembers.Member m : members) { - Array memberArray = as.extractMemberArray(m); - assert (memberArray.getElementType() == m.getDataType().getPrimitiveClassType()); - - // random tests - if (m.getDataType().isNumeric()) { - double sum = 0.0; - while (memberArray.hasNext()) - sum += memberArray.nextDouble(); - return sum; - } else if (m.getDataType().isString()) { - while (memberArray.hasNext()) - System.out.println(" " + memberArray.next()); - } - } - return 0.0; - } - - private void testArrayStructureByIterator(ArrayStructure as) throws IOException { - try (StructureDataIterator si = as.getStructureDataIterator()) { - while (si.hasNext()) { - StructureData sdata = si.next(); - - // run through each member on the StructureData - List members = sdata.getMembers(); - for (StructureMembers.Member m : members) { - Array sdataArray = sdata.getArray(m); - assert (sdataArray.getElementType() == m.getDataType().getPrimitiveClassType()); - } - - testStructureData(sdata); - } - } - } - - private void testArrayStructureByRecno(ArrayStructure as) { - // run through each StructureData - for (int recno = 0; recno < as.getSize(); recno++) { - Object o = as.getObject(recno); - assert (o instanceof StructureData); - StructureData sdata = as.getStructureData(recno); - assert (o == sdata); - - // run through each member on the StructureData - List members = sdata.getMembers(); - for (StructureMembers.Member m : members) { - Array sdataArray = sdata.getArray(m); - assert (sdataArray.getElementType() == m.getDataType().getPrimitiveClassType()) : sdataArray.getElementType() - + " != " + m.getDataType().getPrimitiveClassType(); - - Array sdataArray2 = sdata.getArray(m.getName()); - UtilsMa2Test.testEquals(sdataArray, sdataArray2); - - Array a = as.getArray(recno, m); - assert (a.getElementType() == m.getDataType().getPrimitiveClassType()); - UtilsMa2Test.testEquals(sdataArray, a); - - testGetArrayByType(as, recno, m, a); - } - - testStructureData(sdata); - } - } - - private void testGetArrayByType(ArrayStructure as, int recno, StructureMembers.Member m, Array a) { - DataType dtype = m.getDataType(); - Object data = null; - if (dtype == DataType.DOUBLE) { - assert a.getElementType() == double.class; - data = as.getJavaArrayDouble(recno, m); - - } else if (dtype == DataType.FLOAT) { - assert a.getElementType() == float.class; - data = as.getJavaArrayFloat(recno, m); - - } else if (dtype.getPrimitiveClassType() == long.class) { - assert a.getElementType() == long.class; - data = as.getJavaArrayLong(recno, m); - - } else if (dtype.getPrimitiveClassType() == int.class) { - assert a.getElementType() == int.class; - data = as.getJavaArrayInt(recno, m); - - } else if (dtype.getPrimitiveClassType() == short.class) { - assert a.getElementType() == short.class; - data = as.getJavaArrayShort(recno, m); - - } else if (dtype.getPrimitiveClassType() == byte.class) { - assert a.getElementType() == byte.class; - data = as.getJavaArrayByte(recno, m); - - } else if (dtype == DataType.CHAR) { - assert a.getElementType() == char.class; - data = as.getJavaArrayChar(recno, m); - - } else if (dtype == DataType.STRING) { - assert a.getElementType() == String.class; - data = as.getJavaArrayString(recno, m); - - } else if (dtype == DataType.STRUCTURE) { - assert a.getElementType() == StructureData.class; - ArrayStructure nested = as.getArrayStructure(recno, m); - testArrayStructure(nested); - } - - if (data != null) - UtilsMa2Test.testJarrayEquals(data, a.getStorage(), m.getSize()); - } - - private void testStructureData(StructureData sdata) { - - List members = sdata.getMembers(); - for (StructureMembers.Member m : members) { - Array sdataArray = sdata.getArray(m); - assert (sdataArray.getElementType() == m.getDataType().getPrimitiveClassType()); - - Array sdataArray2 = sdata.getArray(m.getName()); - UtilsMa2Test.testEquals(sdataArray, sdataArray2); - - // NCdump.printArray(sdataArray, m.getName(), System.out, null); - - testGetArrayByType(sdata, m, sdataArray); - } - } - - private void testGetArrayByType(StructureData sdata, StructureMembers.Member m, Array a) { - DataType dtype = m.getDataType(); - Object data = null; - if (dtype == DataType.DOUBLE) { - assert a.getElementType() == double.class; - data = sdata.getJavaArrayDouble(m); - - } else if (dtype == DataType.FLOAT) { - assert a.getElementType() == float.class; - data = sdata.getJavaArrayFloat(m); - - } else if (dtype.getPrimitiveClassType() == long.class) { - assert a.getElementType() == long.class; - data = sdata.getJavaArrayLong(m); - - } else if (dtype.getPrimitiveClassType() == int.class) { - assert a.getElementType() == int.class; - data = sdata.getJavaArrayInt(m); - - } else if (dtype.getPrimitiveClassType() == short.class) { - assert a.getElementType() == short.class; - data = sdata.getJavaArrayShort(m); - - } else if (dtype.getPrimitiveClassType() == byte.class) { - assert a.getElementType() == byte.class; - data = sdata.getJavaArrayByte(m); - - } else if (dtype == DataType.CHAR) { - assert a.getElementType() == char.class; - data = sdata.getJavaArrayChar(m); - - } else if (dtype == DataType.STRING) { - assert a.getElementType() == String.class; - data = sdata.getJavaArrayString(m); - - } else if (dtype == DataType.STRUCTURE) { - assert a.getElementType() == StructureData.class; - ArrayStructure nested = sdata.getArrayStructure(m); - testArrayStructure(nested); - } - - if (data != null) - UtilsMa2Test.testJarrayEquals(data, a.getStorage(), m.getSize()); - } - -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsCdmUnitTest.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsCdmUnitTest.java deleted file mode 100644 index 3e030f1773..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsCdmUnitTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class requires access to the - * cdmUnitTest shared directory in order to complete successfully. - * - * @author cwardgar - * @since 2015/03/06 - */ -public interface NeedsCdmUnitTest { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsContentRoot.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsContentRoot.java deleted file mode 100644 index f8d7471cc1..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsContentRoot.java +++ /dev/null @@ -1,12 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class requires that a TDS - * content root be defined via the "tds.content.root.path" property. That property can be specified on the command line - * with the "-D" switch or in gradle.properties. - * - * @author cwardgar - * @since 2015/04/15 - */ -public interface NeedsContentRoot { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsExternalResource.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsExternalResource.java deleted file mode 100644 index 2ebcf83c72..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsExternalResource.java +++ /dev/null @@ -1,11 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class requires access to an - * external resource in order to complete successfully. Most commonly, these are remote THREDDS servers. - * - * @author cwardgar - * @since 2015-10-12 - */ -public interface NeedsExternalResource { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsRdaData.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsRdaData.java deleted file mode 100644 index a5aeb22904..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NeedsRdaData.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ -package ucar.unidata.util.test.category; - -/** - * Describe - * - * @author caron - * @since 2/29/2016. - */ -public interface NeedsRdaData { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotJenkins.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotJenkins.java deleted file mode 100644 index 60508d3b05..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotJenkins.java +++ /dev/null @@ -1,11 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class cannot succeed when run - * within the Jenkins environment. - * - * @author cwardgar - * @since 2015/03/19 - */ -public interface NotJenkins { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotPullRequest.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotPullRequest.java deleted file mode 100644 index 377020be81..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/NotPullRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class cannot succeed when run - * within the GitHub Actions CI environment. - * - * @author cwardgar - * @since 2015/03/19 - */ -public interface NotPullRequest { -} diff --git a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/Slow.java b/tds-test-utils/src/main/java/ucar/unidata/util/test/category/Slow.java deleted file mode 100644 index af993f98de..0000000000 --- a/tds-test-utils/src/main/java/ucar/unidata/util/test/category/Slow.java +++ /dev/null @@ -1,11 +0,0 @@ -package ucar.unidata.util.test.category; - -/** - * A marker to be used with JUnit categories to indicate that a test method or test class takes a long time to run. - * We'll want to avoid running such tests after every commit; instead just run them once-a-night or so. - * - * @author cwardgar - * @since 2015/09/22 - */ -public interface Slow { -} diff --git a/tds/build.gradle b/tds/build.gradle index aba3cf858a..1f5e0138e5 100644 --- a/tds/build.gradle +++ b/tds/build.gradle @@ -104,6 +104,7 @@ dependencies { testCompile 'pl.pragmatists:JUnitParams' testCompile 'com.google.truth:truth' testCompile 'junit:junit' + testCompile project(':tds-test-utils'); testCompile 'edu.ucar:cdm-test-utils' // Contains stuff like the JUnit @Category classes. // Logging diff --git a/tds/src/integrationTests/java/opendap/test/TestGrid1.java b/tds/src/integrationTests/java/opendap/test/TestGrid1.java index 80d88c5dc3..ff6eec8510 100644 --- a/tds/src/integrationTests/java/opendap/test/TestGrid1.java +++ b/tds/src/integrationTests/java/opendap/test/TestGrid1.java @@ -2,17 +2,19 @@ * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ + package opendap.test; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import java.lang.invoke.MethodHandles; /** @@ -32,7 +34,7 @@ * } testgrid1 */ -public class TestGrid1 extends UnitTestCommon { +public class TestGrid1 extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final protected String URLPATH = "/thredds/dodsC/scanLocal/testgrid1.nc"; diff --git a/tds/src/integrationTests/java/opendap/test/TestGrid2.java b/tds/src/integrationTests/java/opendap/test/TestGrid2.java index 22e4669e81..6d42526cae 100644 --- a/tds/src/integrationTests/java/opendap/test/TestGrid2.java +++ b/tds/src/integrationTests/java/opendap/test/TestGrid2.java @@ -2,18 +2,20 @@ * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ + package opendap.test; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import thredds.TestOnLocalServer; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.write.Ncdump; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import java.io.IOException; import java.io.StringWriter; import java.lang.invoke.MethodHandles; @@ -33,7 +35,7 @@ * } testgrid2; */ -public class TestGrid2 extends UnitTestCommon { +public class TestGrid2 extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final protected String URLPATH = "/thredds/dodsC/scanLocal/testgrid2.nc"; diff --git a/tds/src/integrationTests/java/thredds/server/cdmr/TestCdmRemoteCompareHeadersP.java b/tds/src/integrationTests/java/thredds/server/cdmr/TestCdmRemoteCompareHeadersP.java index 44945b616b..a8efb184a6 100644 --- a/tds/src/integrationTests/java/thredds/server/cdmr/TestCdmRemoteCompareHeadersP.java +++ b/tds/src/integrationTests/java/thredds/server/cdmr/TestCdmRemoteCompareHeadersP.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.cdmr; import org.apache.commons.io.filefilter.SuffixFileFilter; @@ -9,6 +14,7 @@ import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsTestDir; import thredds.TestOnLocalServer; import ucar.nc2.Attribute; import ucar.nc2.NetcdfFile; @@ -18,9 +24,9 @@ import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.stream.CdmRemote; import ucar.nc2.util.CompareNetcdf2; -import ucar.unidata.util.test.category.NeedsCdmUnitTest; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.StringUtil2; +import ucar.unidata.util.test.category.NeedsCdmUnitTest; + import java.io.File; import java.io.FileFilter; import java.io.IOException; @@ -110,7 +116,7 @@ public void doOne() throws IOException { } static int compareDatasets(String local, String remote, boolean readData) throws IOException { - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { return compareDatasetsNew(local, remote, readData); } else { return compareDatasetsOld(local, remote, readData); diff --git a/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java b/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java index f78546746b..39b5758429 100644 --- a/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java +++ b/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java @@ -1,10 +1,15 @@ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.ncss; -import java.io.IOException; import org.junit.Test; import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsTestDir; import thredds.TestOnLocalServer; import thredds.util.ContentType; import ucar.nc2.NetcdfFile; @@ -12,9 +17,11 @@ import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.dt.grid.GridDataset; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + +import java.io.IOException; import java.lang.invoke.MethodHandles; + import static org.junit.Assert.assertNotNull; @Category(NeedsCdmUnitTest.class) @@ -61,7 +68,7 @@ public void checkGrid() throws Exception { "/ncss/grid/gribCollection/GFS_CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1?var=Temperature_isobaric"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { openBinaryNew(content, "Temperature_isobaric"); } else { openBinaryOld(content, "Temperature_isobaric"); @@ -82,7 +89,7 @@ public void checkFmrcBest() throws Exception { byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { openBinaryNew(content, "Relative_humidity_height_above_ground"); } else { openBinaryOld(content, "Relative_humidity_height_above_ground"); @@ -101,7 +108,7 @@ public void testNcssFailure() throws Exception { byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { openBinaryNew(content, "eastward_ekman_current_velocity"); } else { openBinaryOld(content, "eastward_ekman_current_velocity"); diff --git a/tds/src/integrationTests/java/thredds/server/ncss/TestGridAsPointP.java b/tds/src/integrationTests/java/thredds/server/ncss/TestGridAsPointP.java index 9d19d6ba5a..704ea8b9de 100644 --- a/tds/src/integrationTests/java/thredds/server/ncss/TestGridAsPointP.java +++ b/tds/src/integrationTests/java/thredds/server/ncss/TestGridAsPointP.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ + package thredds.server.ncss; -import java.nio.charset.StandardCharsets; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; @@ -21,6 +21,7 @@ import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsTestDir; import thredds.TestOnLocalServer; import thredds.util.ContentType; import ucar.httpservices.HTTPFactory; @@ -37,16 +38,18 @@ import ucar.nc2.time.CalendarDate; import ucar.nc2.util.IO; import ucar.unidata.util.test.Assert2; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.lang.invoke.MethodHandles; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Formatter; import java.util.List; + import static org.junit.Assert.assertNotNull; /** @@ -169,7 +172,7 @@ public void checkGridAsPointNetcdf() throws JDOMException, IOException { byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); Assert.assertNotNull(content); logger.debug("return size = {}", content.length); - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { checkGridAsPointNetcdfNew(content, varName); } else { checkGridAsPointNetcdfOld(content, varName); diff --git a/tds/src/integrationTests/java/thredds/server/opendap/TestTdsDodsServer.java b/tds/src/integrationTests/java/thredds/server/opendap/TestTdsDodsServer.java index 6be6dd374d..e2c9b16384 100644 --- a/tds/src/integrationTests/java/thredds/server/opendap/TestTdsDodsServer.java +++ b/tds/src/integrationTests/java/thredds/server/opendap/TestTdsDodsServer.java @@ -1,14 +1,10 @@ /* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ + package thredds.server.opendap; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.nio.charset.StandardCharsets; -import java.util.Formatter; -import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -43,6 +39,12 @@ import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.nio.charset.StandardCharsets; +import java.util.Formatter; +import java.util.List; + @Category(NeedsCdmUnitTest.class) public class TestTdsDodsServer { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -186,7 +188,7 @@ public void testCompareWithFile() throws IOException { final String urlPrefix = TestOnLocalServer.withHttpPath("/dodsC/scanCdmUnitTests/tds/opendap/"); final String dirName = TestDir.cdmUnitTestDir + "tds/opendap/"; // read all files from this dir - TestDir.actOnAll(dirName, new TestDir.FileFilterNoWant(".gbx8 .gbx9 .ncx .ncx2 .ncx3"), new TestDir.Act() { + TestDir.actOnAll(dirName, TestDir.FileFilterSkipSuffix(".gbx8 .gbx9 .ncx .ncx2 .ncx3"), new TestDir.Act() { public int doAct(String filename) throws IOException { filename = StringUtil2.replace(filename, '\\', "/"); filename = StringUtil2.remove(filename, dirName); diff --git a/tds/src/integrationTests/java/thredds/server/reify/TestReify.java b/tds/src/integrationTests/java/thredds/server/reify/TestReify.java index cedd2c53a9..ec681cff52 100644 --- a/tds/src/integrationTests/java/thredds/server/reify/TestReify.java +++ b/tds/src/integrationTests/java/thredds/server/reify/TestReify.java @@ -1,5 +1,5 @@ /* - * Copyright 2016, University Corporation for Atmospheric Research + * Copyright 2016-2021, University Corporation for Atmospheric Research * See the LICENSE.txt file for more information. */ @@ -16,10 +16,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.validation.Errors; +import thredds.TdsUnitTestCommon; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; import ucar.httpservices.HTTPUtil; -import ucar.unidata.util.test.UnitTestCommon; + import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -28,7 +29,7 @@ import java.net.URLEncoder; import java.util.*; -abstract public class TestReify extends UnitTestCommon { +abstract public class TestReify extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static protected final boolean DEBUG = false; diff --git a/tds/src/integrationTests/java/thredds/server/services/ConsistentDatesTest.java b/tds/src/integrationTests/java/thredds/server/services/ConsistentDatesTest.java index 49ebd249f0..8981d746e8 100644 --- a/tds/src/integrationTests/java/thredds/server/services/ConsistentDatesTest.java +++ b/tds/src/integrationTests/java/thredds/server/services/ConsistentDatesTest.java @@ -1,6 +1,10 @@ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.services; -import java.nio.charset.StandardCharsets; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; @@ -20,6 +24,7 @@ import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsTestDir; import thredds.TestOnLocalServer; import thredds.util.ContentType; import ucar.nc2.Attribute; @@ -35,14 +40,16 @@ import ucar.nc2.time.CalendarDate; import ucar.nc2.time.CalendarDateUnit; import ucar.nc2.util.IO; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + import java.io.*; import java.lang.invoke.MethodHandles; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; + import static org.junit.Assert.assertEquals; /** @@ -156,7 +163,7 @@ public void checkNCSSDatesInNetcdf() throws JDOMException, IOException { NetcdfFile nf; NetcdfDataset ds; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", result); ds = NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null); } else { @@ -227,7 +234,7 @@ public void checkNCSSDatesInNetcdfWithCalendars() throws JDOMException, IOExcept NetcdfFile nf; NetcdfDataset ds; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", result); ds = NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null); } else { diff --git a/tds/src/integrationTests/java/thredds/server/wcs/TestWcsServer.java b/tds/src/integrationTests/java/thredds/server/wcs/TestWcsServer.java index 428f8dfb3d..0aa00bb8f7 100644 --- a/tds/src/integrationTests/java/thredds/server/wcs/TestWcsServer.java +++ b/tds/src/integrationTests/java/thredds/server/wcs/TestWcsServer.java @@ -1,9 +1,10 @@ /* - * (c) 1998-2018 University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.wcs; -import java.nio.charset.StandardCharsets; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; @@ -19,14 +20,7 @@ import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.Formatter; -import java.util.List; +import thredds.TdsTestDir; import thredds.TestOnLocalServer; import thredds.util.ContentType; import ucar.nc2.NetcdfFile; @@ -34,20 +28,25 @@ import ucar.nc2.constants.AxisType; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; -import ucar.nc2.ft2.coverage.Coverage; -import ucar.nc2.ft2.coverage.CoverageCollection; -import ucar.nc2.ft2.coverage.CoverageCoordAxis1D; -import ucar.nc2.ft2.coverage.CoverageCoordSys; -import ucar.nc2.ft2.coverage.FeatureDatasetCoverage; -import ucar.nc2.ft2.coverage.HorizCoordSys; +import ucar.nc2.ft2.coverage.*; import ucar.nc2.ft2.coverage.adapter.DtCoverageAdapter; import ucar.nc2.ft2.coverage.adapter.DtCoverageDataset; import ucar.nc2.time.Calendar; import ucar.nc2.time.CalendarDate; import ucar.nc2.util.IO; import ucar.unidata.util.test.Assert2; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.lang.invoke.MethodHandles; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Formatter; +import java.util.List; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -137,7 +136,7 @@ public void testGetCoverage() throws IOException { private DtCoverageDataset getDtCoverageDataset(NetcdfFile ncf) throws IOException { DtCoverageDataset dtc; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { dtc = new DtCoverageDataset(NetcdfDatasets.enhance(ncf, NetcdfDataset.getDefaultEnhanceMode(), null)); } else { dtc = new DtCoverageDataset(new NetcdfDataset(ncf), null); diff --git a/tds/src/integrationTests/java/ucar/nc2/TestByteRange.java b/tds/src/integrationTests/java/ucar/nc2/TestByteRange.java index e5ffca8e68..b9920b9d4d 100644 --- a/tds/src/integrationTests/java/ucar/nc2/TestByteRange.java +++ b/tds/src/integrationTests/java/ucar/nc2/TestByteRange.java @@ -1,53 +1,27 @@ /* - * Copyright (c) 1998 - 2011. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ package ucar.nc2; -import java.util.Formatter; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import thredds.TestOnLocalServer; import ucar.nc2.write.CDLWriter; -import ucar.unidata.util.test.UnitTestCommon; + import java.lang.invoke.MethodHandles; import java.util.ArrayList; +import java.util.Formatter; import java.util.List; /** * Test that client side and server side byte range access works. */ -public class TestByteRange extends UnitTestCommon { +public class TestByteRange extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Collect testcases locally diff --git a/tds/src/integrationTests/java/ucar/nc2/util/net/TestFormBuilder.java b/tds/src/integrationTests/java/ucar/nc2/util/net/TestFormBuilder.java index ee224d2637..56c1b0066a 100644 --- a/tds/src/integrationTests/java/ucar/nc2/util/net/TestFormBuilder.java +++ b/tds/src/integrationTests/java/ucar/nc2/util/net/TestFormBuilder.java @@ -1,33 +1,6 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ package ucar.nc2.util.net; @@ -38,9 +11,10 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.httpservices.*; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import java.io.*; import java.lang.invoke.MethodHandles; import java.util.HashMap; @@ -52,7 +26,7 @@ /** * Test HttpFormBuilder */ -public class TestFormBuilder extends UnitTestCommon { +public class TestFormBuilder extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); ////////////////////////////////////////////////// @@ -131,7 +105,7 @@ public void testSimple() throws Exception { body = genericize(body, OSTEXT, null, null); if (DEBUG) visual("TestFormBuilder.testsimple.LOCALIZED", body); - String diffs = UnitTestCommon.compare("TestFormBuilder.testSimpl", simplebaseline, body); + String diffs = TdsUnitTestCommon.compare("TestFormBuilder.testSimpl", simplebaseline, body); if (diffs != null) { System.err.println("TestFormBuilder.testsimple.diffs:\n" + diffs); Assert.assertTrue("TestFormBuilder.testSimple: ***FAIL", false); @@ -181,7 +155,7 @@ public void testMultiPart() throws Exception { body = genericize(body, OSTEXT, boundary, attach3); if (DEBUG) visual("TestFormBuilder.testmultipart.LOCALIZED", body); - String diffs = UnitTestCommon.compare("TestFormBuilder.testMultiPart", multipartbaseline, body); + String diffs = TdsUnitTestCommon.compare("TestFormBuilder.testMultiPart", multipartbaseline, body); if (diffs != null) { System.err.println("TestFormBuilder.testmultipart.diffs:\n" + diffs); Assert.assertTrue("TestFormBuilder.testmultipart: ***FAIL", false); diff --git a/tds/src/integrationTests/java/ucar/nc2/util/net/TestMisc.java b/tds/src/integrationTests/java/ucar/nc2/util/net/TestMisc.java index 3d8643482f..0e0a68bb47 100644 --- a/tds/src/integrationTests/java/ucar/nc2/util/net/TestMisc.java +++ b/tds/src/integrationTests/java/ucar/nc2/util/net/TestMisc.java @@ -1,33 +1,6 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ package ucar.nc2.util.net; @@ -38,6 +11,7 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.httpservices.HTTPException; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; @@ -45,11 +19,11 @@ import ucar.nc2.dataset.DatasetUrl; import ucar.nc2.util.EscapeStrings; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; + import java.lang.invoke.MethodHandles; import java.util.List; -public class TestMisc extends UnitTestCommon { +public class TestMisc extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static { diff --git a/tds/src/integrationTests/java/ucar/nc2/util/net/TestSSH.java b/tds/src/integrationTests/java/ucar/nc2/util/net/TestSSH.java index 508ecfa4f8..d855dc17e6 100644 --- a/tds/src/integrationTests/java/ucar/nc2/util/net/TestSSH.java +++ b/tds/src/integrationTests/java/ucar/nc2/util/net/TestSSH.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ @@ -15,14 +15,15 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; import ucar.httpservices.HTTPSession; -import ucar.unidata.util.test.UnitTestCommon; +import ucar.unidata.util.test.category.NotPullRequest; + import java.io.IOException; import java.io.Serializable; import java.lang.invoke.MethodHandles; -import ucar.unidata.util.test.category.NotPullRequest; /** * This test is to check ssh authorization. @@ -30,7 +31,7 @@ * using a pure tomcat server. */ @Category(NotPullRequest.class) -public class TestSSH extends UnitTestCommon { +public class TestSSH extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static protected final boolean IGNORE = true; diff --git a/tds/src/integrationTests/java/ucar/nc2/util/net/TestTomcatAuth.java b/tds/src/integrationTests/java/ucar/nc2/util/net/TestTomcatAuth.java index bddf572b68..6a4dbe0fea 100644 --- a/tds/src/integrationTests/java/ucar/nc2/util/net/TestTomcatAuth.java +++ b/tds/src/integrationTests/java/ucar/nc2/util/net/TestTomcatAuth.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ @@ -16,17 +16,18 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsUnitTestCommon; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; import ucar.httpservices.HTTPSession; import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; +import ucar.unidata.util.test.category.NotPullRequest; + import java.io.IOException; import java.io.Serializable; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.List; -import ucar.unidata.util.test.category.NotPullRequest; /** * This test is to check non-ssh related authorization: Basic primarily. @@ -72,7 +73,7 @@ * */ @Category(NotPullRequest.class) -public class TestTomcatAuth extends UnitTestCommon { +public class TestTomcatAuth extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static final String BADPASSWORD = "bad"; diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/AllVariablesSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/AllVariablesSubsettingTest.java index 03f106eb99..a8ab8806de 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/AllVariablesSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/AllVariablesSubsettingTest.java @@ -1,40 +1,10 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.ncss.controller.grid; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.lang.invoke.MethodHandles; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -51,7 +21,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import thredds.core.TdsRequestedDataset; +import thredds.TdsTestDir; import thredds.mock.params.GridPathParams; import thredds.mock.web.MockTdsContextLoader; import ucar.nc2.NetcdfFile; @@ -59,9 +29,14 @@ import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.dt.grid.GridDataset; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; +import java.io.IOException; +import java.lang.invoke.MethodHandles; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author mhermida * @@ -96,7 +71,7 @@ public void shouldGetAllVariables() throws Exception { // NetcdfFile nf = NetcdfFile.openInMemory("test_data.ncs", response.getContentAsByteArray() ); NetcdfFile nf; GridDataset gdsDataset; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", mvc.getResponse().getContentAsByteArray()); gdsDataset = new ucar.nc2.dt.grid.GridDataset(NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null)); diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/FmrcHorizSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/FmrcHorizSubsettingTest.java index 5d53bd4797..7104525926 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/FmrcHorizSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/FmrcHorizSubsettingTest.java @@ -1,4 +1,8 @@ -/* Copyright */ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.ncss.controller.grid; import com.beust.jcommander.internal.Lists; @@ -17,6 +21,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; import thredds.junit4.SpringJUnit4ParameterizedClassRunner; import thredds.mock.web.MockTdsContextLoader; import ucar.nc2.NetcdfFile; @@ -25,17 +30,16 @@ import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.dt.grid.GeoGrid; import ucar.unidata.geoloc.ProjectionRect; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; + +import static org.junit.Assert.*; @RunWith(SpringJUnit4ParameterizedClassRunner.class) @WebAppConfiguration @@ -128,7 +132,7 @@ public void shouldSubsetGrid() throws Exception { assertEquals(200, mvc.getResponse().getStatus()); // Open the binary response in memory - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { try (NetcdfFile nf = NetcdfFiles.openInMemory("test_data.ncs", mvc.getResponse().getContentAsByteArray())) { check( new ucar.nc2.dt.grid.GridDataset(NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null))); diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/SpatialSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/SpatialSubsettingTest.java index c86e26b092..b5f077931d 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/SpatialSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/SpatialSubsettingTest.java @@ -1,40 +1,10 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.ncss.controller.grid; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.*; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -53,14 +23,15 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; +import thredds.junit4.SpringJUnit4ParameterizedClassRunner; +import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import thredds.mock.params.GridDataParameters; import thredds.mock.params.GridPathParams; import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.controller.AbstractNcssController; -import thredds.server.ncss.format.SupportedFormat; import thredds.server.ncss.dataservice.DatasetHandlerAdapter; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; +import thredds.server.ncss.format.SupportedFormat; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; @@ -68,9 +39,14 @@ import ucar.nc2.dt.GridDataset; import ucar.unidata.geoloc.LatLonPoint; import ucar.unidata.geoloc.LatLonRect; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.*; + +import static org.junit.Assert.assertTrue; + /** * @author marcos * @@ -158,7 +134,7 @@ public void match(MvcResult result) throws Exception { NetcdfFile nf = NetcdfFile.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray()); ucar.nc2.dt.grid.GridDataset gdsDataset = new ucar.nc2.dt.grid.GridDataset(new NetcdfDataset(nf)); // Open the binary response in memory - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray()); gdsDataset = new ucar.nc2.dt.grid.GridDataset( NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null)); diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/TemporalSpaceSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/TemporalSpaceSubsettingTest.java index 974bbd9f32..b120d112d0 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/TemporalSpaceSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/TemporalSpaceSubsettingTest.java @@ -1,34 +1,8 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.ncss.controller.grid; import org.junit.Before; @@ -38,7 +12,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; @@ -47,6 +20,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; import thredds.junit4.SpringJUnit4ParameterizedClassRunner; import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import thredds.mock.params.GridPathParams; @@ -57,14 +31,13 @@ import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; + import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.Arrays; import java.util.Collection; -import java.util.Enumeration; -import java.util.Formatter; + import static org.junit.Assert.assertEquals; /** @@ -163,7 +136,7 @@ public void shouldGetTimeRange() throws Exception { // Open the binary response in memory NetcdfFile nf; NetcdfDataset ds; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", mvc.getResponse().getContentAsByteArray()); ds = NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null); } else { diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/VariableSpaceSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/VariableSpaceSubsettingTest.java index a3ec5e557a..74b44d9c45 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/VariableSpaceSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/VariableSpaceSubsettingTest.java @@ -1,45 +1,10 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.ncss.controller.grid; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -57,20 +22,30 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; +import thredds.junit4.SpringJUnit4ParameterizedClassRunner; +import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import thredds.mock.params.GridDataParameters; import thredds.mock.params.GridPathParams; import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.format.SupportedFormat; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.dt.grid.GeoGrid; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; + /** * @author marcos * @@ -154,7 +129,7 @@ public void match(MvcResult result) throws Exception { // Open the binary response in memory NetcdfFile nf; ucar.nc2.dt.grid.GridDataset gdsDataset; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray()); gdsDataset = new ucar.nc2.dt.grid.GridDataset(NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null)); diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/VerticalStrideSubsettingTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/VerticalStrideSubsettingTest.java index c5c556b0b3..f88f6e257d 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/VerticalStrideSubsettingTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/VerticalStrideSubsettingTest.java @@ -1,54 +1,14 @@ /* - * Copyright (c) 1998 - 2012. University Corporation for Atmospheric Research/Unidata - * Portions of this software were developed by the Unidata Program at the - * University Corporation for Atmospheric Research. - * - * Access and use of this software shall impose the following obligations - * and understandings on the user. The user is granted the right, without - * any fee or cost, to use, copy, modify, alter, enhance and distribute - * this software, and any derivative works thereof, and its supporting - * documentation for any purpose whatsoever, provided that this entire - * notice appears in all copies of the software, derivative works and - * supporting documentation. Further, UCAR requests that the user credit - * UCAR/Unidata in any publications that result from the use of this - * software or in any product that includes this software. The names UCAR - * and/or Unidata, however, may not be used in any advertising or publicity - * to endorse or promote any products or commercial entity unless specific - * written permission is obtained from UCAR/Unidata. The user also - * understands that UCAR/Unidata is not obligated to provide the user with - * any support, consulting, training or assistance of any kind with regard - * to the use, operation and performance of this software nor to provide - * the user with any updates, revisions, new versions or "bug fixes." - * - * THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. */ + package thredds.server.ncss.controller.grid; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.RequestBuilder; @@ -57,19 +17,26 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; +import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import thredds.mock.params.GridDataParameters; import thredds.mock.params.GridPathParams; -import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.format.SupportedFormat; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner; -import thredds.junit4.SpringJUnit4ParameterizedClassRunner.Parameters; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; import ucar.nc2.VariableSimpleIF; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; -import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.category.NeedsCdmUnitTest; + +import java.io.IOException; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; /** @@ -168,7 +135,7 @@ public void match(MvcResult result) throws Exception { // Open the binary response in memory NetcdfFile nf; ucar.nc2.dt.grid.GridDataset gdsDataset; - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { nf = NetcdfFiles.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray()); gdsDataset = new ucar.nc2.dt.grid.GridDataset(NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null)); diff --git a/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFcOpenFiles.java b/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFcOpenFiles.java index 6ba3f64cd2..1276cc3df4 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFcOpenFiles.java +++ b/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFcOpenFiles.java @@ -1,8 +1,10 @@ +/* + * Copyright (c) 1998-2021 John Caron and University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.ncss.controller.point; -import static com.google.common.truth.Truth.assertThat; -import java.lang.invoke.MethodHandles; -import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -22,14 +24,19 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import thredds.TdsTestDir; import thredds.mock.web.MockTdsContextLoader; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.util.cache.FileCache; import ucar.unidata.io.RandomAccessFile; -import ucar.unidata.util.test.TestDir; import ucar.unidata.util.test.category.NeedsCdmUnitTest; +import java.lang.invoke.MethodHandles; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; + @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = {"/WEB-INF/applicationContext.xml"}, loader = MockTdsContextLoader.class) @@ -48,7 +55,7 @@ public void setup() { mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); rafCache = (FileCache) RandomAccessFile.getGlobalFileCache(); rafCache.clearCache(true); - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { NetcdfDatasets.getNetcdfFileCache().clearCache(true); } else { NetcdfDataset.getNetcdfFileCache().clearCache(true); diff --git a/tds/src/test/java/thredds/server/ncss/view/dsg/DsgSubsetWriterTest.java b/tds/src/test/java/thredds/server/ncss/view/dsg/DsgSubsetWriterTest.java index 25abcfd041..0b7113d2b5 100644 --- a/tds/src/test/java/thredds/server/ncss/view/dsg/DsgSubsetWriterTest.java +++ b/tds/src/test/java/thredds/server/ncss/view/dsg/DsgSubsetWriterTest.java @@ -1,3 +1,8 @@ +/* + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata + * See LICENSE for license information. + */ + package thredds.server.ncss.view.dsg; import org.apache.commons.io.FilenameUtils; @@ -8,6 +13,7 @@ import org.junit.runners.Parameterized; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import thredds.TdsTestDir; import thredds.server.ncss.controller.NcssDiskCache; import thredds.server.ncss.format.SupportedFormat; import ucar.nc2.Attribute; @@ -30,13 +36,13 @@ import ucar.nc2.util.DiskCache2; import ucar.unidata.geoloc.LatLonPoint; import ucar.unidata.geoloc.LatLonRect; + import java.io.*; import java.lang.invoke.MethodHandles; import java.net.URISyntaxException; import java.util.Arrays; import java.util.Formatter; import java.util.List; -import ucar.unidata.util.test.TestDir; /** * Created by cwardgar on 2014/05/27. @@ -211,7 +217,7 @@ public void testWrite() throws Exception { } public static boolean compareNetCDF(File expectedResultFile, File actualResultFile) throws IOException { - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { return compareNetCDFNew(expectedResultFile, actualResultFile); } else { return compareNetCDFOld(expectedResultFile, actualResultFile); diff --git a/tds/src/test/java/thredds/server/opendap/TestCEEvaluator.java b/tds/src/test/java/thredds/server/opendap/TestCEEvaluator.java index ab8feeaf6c..ec3432c73f 100644 --- a/tds/src/test/java/thredds/server/opendap/TestCEEvaluator.java +++ b/tds/src/test/java/thredds/server/opendap/TestCEEvaluator.java @@ -1,31 +1,33 @@ /* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata + * Copyright (c) 1998-2021 University Corporation for Atmospheric Research/Unidata * See LICENSE for license information. */ package thredds.server.opendap; import opendap.dap.BaseType; -import opendap.servers.*; +import opendap.servers.CEEvaluator; +import opendap.servers.ServerDDS; +import opendap.servers.ServerMethods; import opendap.servlet.AsciiWriter; import opendap.servlet.GuardedDataset; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ucar.nc2.dataset.NetcdfDatasets; -import ucar.unidata.util.test.TestDir; -import ucar.unidata.util.test.UnitTestCommon; -import ucar.unidata.util.test.Diff; +import thredds.TdsTestDir; +import thredds.TdsUnitTestCommon; import ucar.nc2.NetcdfFile; import ucar.nc2.dataset.NetcdfDataset; +import ucar.nc2.dataset.NetcdfDatasets; +import ucar.unidata.util.test.Diff; + import java.io.*; -import java.io.FileWriter; import java.lang.invoke.MethodHandles; import java.util.Enumeration; // Test that the Constraint parsing is correct -public class TestCEEvaluator extends UnitTestCommon { +public class TestCEEvaluator extends TdsUnitTestCommon { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); static boolean DEBUG = false; @@ -112,7 +114,7 @@ void dotests() throws Exception { try { file = new File(path); - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { ncfile = NetcdfDatasets.openFile(file.getPath(), null); } else { ncfile = NetcdfDataset.openFile(file.getPath(), null); @@ -120,7 +122,7 @@ void dotests() throws Exception { if (ncfile == null) throw new FileNotFoundException(path); if (DEBUG) - visual("cdm file", ncdumpmetadata(ncfile, UnitTestCommon.extractDatasetname(path, null))); + visual("cdm file", ncdumpmetadata(ncfile, TdsUnitTestCommon.extractDatasetname(path, null))); ds = new GuardedDatasetCacheAndClone(path, ncfile, false); dds = ds.getDDS(); // force the name @@ -215,7 +217,7 @@ void dogenerate() throws Exception { // generate the complete unconstrained data set file = new File(path); - if (TestDir.cdmUseBuilders) { + if (TdsTestDir.cdmUseBuilders) { ncfile = NetcdfDatasets.openFile(file.getPath(), null); } else { ncfile = NetcdfDataset.openFile(file.getPath(), null);