Skip to content

Commit

Permalink
Merge pull request #1326 from tdrwenski/test-cleanups
Browse files Browse the repository at this point in the history
Test cleanups
  • Loading branch information
tdrwenski authored Apr 2, 2024
2 parents e4ce852 + 0e933a4 commit d7cc4fb
Show file tree
Hide file tree
Showing 34 changed files with 46 additions and 1,052 deletions.
35 changes: 0 additions & 35 deletions dap4/src/test/java/dap4/test/Dap4Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
package dap4.test;

import dap4.core.util.DapConstants;
import dap4.core.util.DapException;
import ucar.httpservices.HTTPFactory;
import ucar.httpservices.HTTPMethod;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -40,14 +37,6 @@ static void register(boolean front, Dap4Server svc) {
registry.add(svc);
}

static Dap4Server getServer(String id) {
for (Dap4Server ds : registry) {
if (ds.id.equals(id))
return ds;
}
return null;
}

//////////////////////////////////////////////////
// Instance variables
public String id;
Expand Down Expand Up @@ -81,30 +70,6 @@ public String getURL(String scheme) {
buf.append(this.servletpath);
return buf.toString();
}

public boolean ping() {
boolean ok = false;
String url = getURL();
try {
try (HTTPMethod method = HTTPFactory.Get(url)) {
int code = method.execute();
if (code == 200)
ok = true;
}
} catch (Exception e) {
ok = false;
}
return ok;
}

public static Dap4Server findServer() throws DapException {
// Find the server to use
for (Dap4Server svc : registry) {
if (svc.ping())
return svc;
}
return null;
}
}


136 changes: 0 additions & 136 deletions dap4/src/test/java/dap4/test/DapTestCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

package dap4.test;

import dap4.core.util.DapConstants;
import dap4.core.util.DapException;
import dap4.core.util.DapUtil;
import dap4.dap4lib.HttpDSP;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.write.Ncdump;
import ucar.unidata.util.test.TestDir;
import ucar.unidata.util.test.UnitTestCommon;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -30,64 +26,13 @@ abstract public class DapTestCommon extends UnitTestCommon {

static final String DEFAULTTREEROOT = "dap4";

public static final String FILESERVER = "file://localhost:8080";

public static final String ORDERTAG = "ucar.littleendian";
public static final String TRANSLATETAG = "ucar.translate";
public static final String TESTTAG = "ucar.testing";

static final String D4TESTDIRNAME = "";

// Equivalent to the path to the webapp/d4ts for testing purposes
protected static final String DFALTRESOURCEPATH = "/src/test/data/resources";

protected static final String[] LEGALEXTENSIONS = {".dap", ".dmr", ".nc", "dmp", ".ncdump", ".dds", ".das", ".dods"};

//////////////////////////////////////////////////

static class TestFilter implements FileFilter {
boolean debug;
boolean strip;
String[] extensions;

public TestFilter(boolean debug, String[] extensions) {
this.debug = debug;
this.strip = strip;
this.extensions = extensions;
}

public boolean accept(File file) {
boolean ok = false;
if (file.isFile() && file.canRead()) {
// Check for proper extension
String name = file.getName();
if (name != null) {
for (String ext : extensions) {
if (name.endsWith(ext))
ok = true;
}
}
if (!ok && debug)
System.err.println("Ignoring: " + file.toString());
}
return ok;
}

static void filterfiles(String path, List<String> matches, String... extensions) {
File testdirf = new File(path);
assert (testdirf.canRead());
TestFilter tf = new TestFilter(DEBUG, extensions);
File[] filelist = testdirf.listFiles(tf);
for (int i = 0; i < filelist.length; i++) {
File file = filelist[i];
if (file.isDirectory())
continue;
String fname = DapUtil.canonicalpath(file.getAbsolutePath());
matches.add(fname);
}
}
}

// Test properties
static class TestProperties {
boolean prop_diff; // Do comparison with baseline files
Expand Down Expand Up @@ -138,10 +83,6 @@ public TestCaseCommon(String name) {
//////////////////////////////////////////////////
// Static methods

protected static String getD4TestsRoot() {
return dap4testroot;
}

protected static String getResourceRoot() {
return dap4resourcedir;
}
Expand Down Expand Up @@ -221,40 +162,13 @@ public void visual(String header, String captured) {
System.err.flush();
}

protected void findServer(String path) throws DapException {
String svc = DapConstants.HTTPSCHEME + "//" + this.d4tsserver + "/d4ts";
if (!checkServer(svc))
System.err.println("D4TS Server not reachable: " + svc);
// Since we will be accessing it thru NetcdfDataset, we need to change the schema.
d4tsserver = "dap4://" + d4tsserver + "/d4ts";
}

//////////////////////////////////////////////////

public String getDAP4Root() {
return this.dap4root;
}

@Override
public String getResourceDir() {
return this.dap4resourcedir;
}

static void printDir(String path) {
File testdirf = new File(path);
assert (testdirf.canRead());
File[] filelist = testdirf.listFiles();
System.err.println("\n*******************");
System.err.printf("Contents of %s:%n", path);
for (int i = 0; i < filelist.length; i++) {
File file = filelist[i];
String fname = file.getName();
System.err.printf("\t%s%s%n", fname, (file.isDirectory() ? "/" : ""));
}
System.err.println("*******************");
System.err.flush();
}

//////////////////////////////////////////////////
// Filename processing utilities

Expand Down Expand Up @@ -330,56 +244,6 @@ public static boolean regexpFilterLine(StringBuilder document, String regexp, bo
return changed;
}


/**
* Choose a test case based on its name and return its index
*
* @param name to search for
* @param testcases set of testcases to search
*/
static void singleTest(String name, List<TestCaseCommon> testcases) {
for (int i = 0; i < testcases.size(); i++) {
TestCaseCommon tc = testcases.get(i);
if (tc.name.equalsIgnoreCase(name)) {
testcases.clear();
testcases.add(tc);
}
}
return;
}

/**
* Choose a test case based on its name and return its index
*
* @param index to search for
* @param testcases set of testcases to search
*/
static void singleTest(int index, List<TestCaseCommon> testcases) {
TestCaseCommon tc = testcases.get(index);
testcases.clear();
testcases.add(tc);
return;
}

protected String dumpmetadata(NetcdfDataset ncfile, String datasetname) throws Exception {
StringWriter sw = new StringWriter();
StringBuilder args = new StringBuilder("-strict");
if (datasetname != null) {
args.append(" -datasetname ");
args.append(datasetname);
}
// Print the meta-databuffer using these args to NcdumpW
try {
Ncdump.ncdump(ncfile, args.toString(), sw, null);
// if (!ucar.nc2.NCdumpW.print(ncfile, args.toString(), sw, null))
// throw new Exception("NcdumpW failed");
} catch (IOException ioe) {
throw new Exception("Ncdump failed", ioe);
}
sw.close();
return sw.toString();
}

protected String dumpdata(NetcdfDataset ncfile, String datasetname) throws Exception {
StringBuilder args = new StringBuilder("-strict -vall");
if (datasetname != null) {
Expand Down
Loading

0 comments on commit d7cc4fb

Please sign in to comment.