Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Migrate tests to JUnit #142

Merged
merged 50 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e7023d4
Add WEB-INF/temp to gitignore
ChrisJohnNOAA Jan 19, 2024
1183a41
Set up a way to run tests dependent on WEB-INF directory structure
ChrisJohnNOAA Jan 19, 2024
70e0730
Migrate SgtMap tests to JUnit
ChrisJohnNOAA Jan 19, 2024
492a0a5
Migrate some more tests to JUnit
ChrisJohnNOAA Jan 23, 2024
309f3c9
migrate more tests, add support for skipping setup.xml validation
ChrisJohnNOAA Jan 25, 2024
162a643
Remove lastmodified column from the file visitor tests
ChrisJohnNOAA Feb 2, 2024
3a51299
New load datasets using xml fragments approach and helper class for t…
ChrisJohnNOAA Feb 14, 2024
17967b0
Add support for generating test code coverage (based on JUnit tests)
ChrisJohnNOAA Feb 14, 2024
9fb95c4
Migrate tests for cohort/array, cohort/util
ChrisJohnNOAA Feb 14, 2024
61530e8
Migrate TestUtil and DataStream to JUnit
ChrisJohnNOAA Feb 14, 2024
4e3c309
Migrate a large collection of tests to junit
ChrisJohnNOAA Feb 20, 2024
c823f34
Merge remote-tracking branch 'upstream/main' into test_migrations
ChrisJohnNOAA Mar 1, 2024
a971f4f
Move resources to not included in git
ChrisJohnNOAA Mar 2, 2024
7215e90
Migrate more code to junit, update test resources for a plan to handl…
ChrisJohnNOAA Mar 4, 2024
10aafc9
Merge remote-tracking branch 'upstream/main' into test_migrations
ChrisJohnNOAA Mar 4, 2024
30d9723
Another set of tests migrated to junit
ChrisJohnNOAA Mar 11, 2024
0836c21
More test migrations
ChrisJohnNOAA Mar 29, 2024
f44f476
Split up test resource files, Mark Flaky tests, split off very large …
ChrisJohnNOAA Apr 1, 2024
da8adf9
New approach for maven downloading files (using the maven-download-pl…
ChrisJohnNOAA Apr 2, 2024
7994f49
Update EDDGridFromDapTests.java
ChrisJohnNOAA Apr 3, 2024
3e7f126
Merge remote-tracking branch 'upstream/main' into test_migrations
ChrisJohnNOAA Apr 3, 2024
31af9a5
Change when test resources are downloaded
ChrisJohnNOAA Apr 3, 2024
5efffad
Improve netcdf loading for a fresh install, one more flaky tag
ChrisJohnNOAA Apr 3, 2024
2210e24
More changes to eliminate reliance on specific hardcoded paths
ChrisJohnNOAA Apr 4, 2024
c680ae0
Centralize code for test initialization. Also set tests to use SansSe…
ChrisJohnNOAA Apr 5, 2024
78beb90
For setups without fonts installed, any use of EDStatic also needs th…
ChrisJohnNOAA Apr 8, 2024
872a888
Add 2024 to the FileVisitorDNLS gpcp test
ChrisJohnNOAA Apr 9, 2024
6b00461
Merge remote-tracking branch 'upstream/main' into test_migrations
ChrisJohnNOAA Apr 11, 2024
21bab20
Re-add download of content
ChrisJohnNOAA Apr 11, 2024
0643ad6
Set file separators to forward slash
srstsavage Apr 12, 2024
849e75a
Merge pull request #5 from srstsavage/test_migrations_linux_file_sepa…
ChrisJohnNOAA Apr 12, 2024
ff74ccd
Update FileVisitorSubdirTests for path slash changes
ChrisJohnNOAA Apr 12, 2024
540c170
Update warsourceExcludes for new folders
ChrisJohnNOAA Apr 12, 2024
19a1a5e
fix HashDigestTests path
ChrisJohnNOAA Apr 12, 2024
97509f7
Fix some jUnit tests on Linux (#7)
srstsavage Apr 17, 2024
19d3f27
Clean up no longer used unitTestDataDir (and big version)
ChrisJohnNOAA Apr 17, 2024
56efbee
Add a tag for imageComparison tests.
ChrisJohnNOAA Apr 17, 2024
36a6a97
Merge branch 'test_migrations' of https://github.com/ChrisJohnNOAA/er…
ChrisJohnNOAA Apr 17, 2024
a8289fb
Mark a few tests as flaky due to differences on different OS. Also re…
ChrisJohnNOAA Apr 18, 2024
816c057
Don't start the email thread if we're testing
ChrisJohnNOAA Apr 18, 2024
102f528
Merge remote-tracking branch 'upstream/main' into test_migrations
ChrisJohnNOAA Apr 18, 2024
3784784
Fix the regexfilename tests that look for java files
ChrisJohnNOAA Apr 19, 2024
fcd3d69
Fix the EDDTests to use the values in the Jetty setup.xml
ChrisJohnNOAA Apr 19, 2024
3599dfc
Simplify the changes when running in a test environment
ChrisJohnNOAA Apr 19, 2024
422c587
Re-add the ability for tests to skip defered loading
ChrisJohnNOAA Apr 19, 2024
ae23b28
Remove Flaky tag from several file visitor tests
ChrisJohnNOAA Apr 19, 2024
88e0bba
Have directory_strlen work cross platform
ChrisJohnNOAA Apr 19, 2024
11a6bad
Because file selection for attributes is based on OS lastModified and…
ChrisJohnNOAA Apr 22, 2024
d1a878b
Merge branch 'test_migrations' of https://github.com/ChrisJohnNOAA/er…
ChrisJohnNOAA Apr 22, 2024
8e6bbdd
re-add maven-antrun-plugin data dir creation and comment out more non…
srstsavage Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
WEB-INF/docs
WEB-INF/lib/
WEB-INF/ref/
WEB-INF/temp/
images/erddapTalk
images/gadgets
images/post
Expand All @@ -14,4 +15,5 @@ Thumbs.db
.settings
.classpath
.project
src/test/resources/
.idea
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ Below you will find relevant links for asking questions and how to contribute.

# Running JUnit tests

Simply run `mvn test` in a terminal to run the JUnit tests.
Simply run `mvn test` in a terminal to run the JUnit tests.

Note that by default tests that do an image comparison are enabled. To disable those tests add `ImageComparison` to the `excludedGroups` section of the surefire `configuration`. It is recommended you run the image tests before making changes to ERDDAP so you can generate a baseline set of images that will be later used for comparison.

# Building a war

`mvn package` will create a war file.

If you'd like to skip the tests while building use `mvn package -DskipTests`. You can use the skipTests flags with other maven commands.
585 changes: 0 additions & 585 deletions WEB-INF/classes/com/cohort/array/Attributes.java

Large diffs are not rendered by default.

442 changes: 0 additions & 442 deletions WEB-INF/classes/com/cohort/array/CharArray.java

Large diffs are not rendered by default.

522 changes: 0 additions & 522 deletions WEB-INF/classes/com/cohort/array/DoubleArray.java

Large diffs are not rendered by default.

468 changes: 0 additions & 468 deletions WEB-INF/classes/com/cohort/array/FloatArray.java

Large diffs are not rendered by default.

509 changes: 0 additions & 509 deletions WEB-INF/classes/com/cohort/array/IntArray.java

Large diffs are not rendered by default.

446 changes: 0 additions & 446 deletions WEB-INF/classes/com/cohort/array/LongArray.java

Large diffs are not rendered by default.

286 changes: 0 additions & 286 deletions WEB-INF/classes/com/cohort/array/NDimensionalIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
package com.cohort.array;

import com.cohort.util.MustBe;
import com.cohort.util.String2;
import com.cohort.util.Test;

import java.util.Arrays;

Expand Down Expand Up @@ -396,288 +394,4 @@ public boolean incrementSubsetIndex(int subsetIndex[], IntArray tConstraints) {
}
return false;
}

/**
* This tests the subsetIndex system.
*/
public static void testSubsetIndex() {
String2.log("\n*** NDimensionalIndex.testSubsetIndex");

//test get all
NDimensionalIndex index = new NDimensionalIndex(new int[]{4,5});
int current[] = index.getCurrent();
IntArray tConstraints = IntArray.fromCSV("0, 1, 3, 0, 1, 4"); //get all
int subsetIndex[] = index.makeSubsetIndex("myVarName", tConstraints);
Test.ensureEqual(index.willGetAllValues(tConstraints), true, "");
for (int i = 0; i < 20; i++) {
Test.ensureEqual(index.increment(), true, "i=" + i);
Test.ensureEqual(current, subsetIndex, "i=" + i);

Test.ensureEqual(index.incrementSubsetIndex(subsetIndex, tConstraints), i < 19, "i=" + i);
}
Test.ensureEqual(index.increment(), false, "at the end");

//test get subset
index.reset();
tConstraints = IntArray.fromCSV("1, 2, 3, 0, 3, 4"); //not that 2nd stop is beyond last matching value
subsetIndex = index.makeSubsetIndex("myVarName", tConstraints);
Test.ensureEqual(index.willGetAllValues(tConstraints), false, "");
StringBuilder results = new StringBuilder();
for (int i = 0; i < 20; i++) {
Test.ensureEqual(index.increment(), true, "i=" + i);

if (Test.testEqual(String2.toCSSVString(current), String2.toCSSVString(subsetIndex), "msg").equals("")) {
results.append("equal at i=" + i + " current=" + String2.toCSSVString(current) + "\n");
if (!index.incrementSubsetIndex(subsetIndex, tConstraints)) {
results.append("done at i=" + i + "\n");
break;
}
}
}
String expected =
"equal at i=5 current=1, 0\n" +
"equal at i=8 current=1, 3\n" +
"equal at i=15 current=3, 0\n" +
"equal at i=18 current=3, 3\n" +
"done at i=18\n";
Test.ensureEqual(results.toString(), expected, "results=\n" + results.toString());

//test get subset
index.reset();
tConstraints = IntArray.fromCSV("0, 3, 3, 1, 2, 4");
subsetIndex = index.makeSubsetIndex("myVarName", tConstraints);
Test.ensureEqual(index.willGetAllValues(tConstraints), false, "");
results = new StringBuilder();
for (int i = 0; i < 20; i++) {
Test.ensureEqual(index.increment(), true, "i=" + i);

if (Test.testEqual(String2.toCSSVString(current), String2.toCSSVString(subsetIndex), "msg").equals("")) {
results.append("equal at i=" + i + " current=" + String2.toCSSVString(current) + "\n");
if (!index.incrementSubsetIndex(subsetIndex, tConstraints)) {
results.append("done at i=" + i + "\n");
break;
}
}
}
expected =
"equal at i=1 current=0, 1\n" +
"equal at i=3 current=0, 3\n" +
"equal at i=16 current=3, 1\n" +
"equal at i=18 current=3, 3\n" +
"done at i=18\n";
Test.ensureEqual(results.toString(), expected, "results=\n" + results.toString());

}



/**
* This tests this class.
* @throws Exception if trouble
*/
public static void basicTest() throws Exception {
String2.log("*** NDimensionalIndex.basicTest");

//test increment
NDimensionalIndex a = new NDimensionalIndex(new int[]{2,2,3});
Test.ensureEqual(a.size, 12, "");

Test.ensureTrue(a.increment(), "0");
Test.ensureEqual(a.getIndex(), 0, "0");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,0}, "0");

Test.ensureTrue(a.increment(), "1");
Test.ensureEqual(a.getIndex(), 1, "1");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,1}, "1");

Test.ensureTrue(a.increment(), "2");
Test.ensureEqual(a.getIndex(), 2, "2");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,2}, "2");

Test.ensureTrue(a.increment(), "3");
Test.ensureEqual(a.getIndex(), 3, "3");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,0}, "3");

Test.ensureTrue(a.increment(), "4");
Test.ensureEqual(a.getIndex(), 4, "4");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,1}, "4");

Test.ensureTrue(a.increment(), "5");
Test.ensureEqual(a.getIndex(), 5, "5");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,2}, "5");

Test.ensureTrue(a.increment(), "6");
Test.ensureEqual(a.getIndex(), 6, "6");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,0}, "6");

Test.ensureTrue(a.increment(), "7");
Test.ensureEqual(a.getIndex(), 7, "7");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,1}, "7");

Test.ensureTrue(a.increment(), "8");
Test.ensureEqual(a.getIndex(), 8, "8");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,2}, "8");

Test.ensureTrue(a.increment(), "9");
Test.ensureEqual(a.getIndex(), 9, "9");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,0}, "9");

Test.ensureTrue(a.increment(), "10");
Test.ensureEqual(a.getIndex(), 10, "10");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,1}, "10");

Test.ensureTrue(a.increment(), "11");
Test.ensureEqual(a.getIndex(), 11, "11");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,2}, "11");

Test.ensureTrue(!a.increment(), "12");
Test.ensureEqual(a.getIndex(), 12, "12");

a.reset();
Test.ensureTrue(a.increment(), "0");
Test.ensureEqual(a.getIndex(), 0, "0");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,0}, "0");

//test incrementCM //shape = 2,2,3 factors 6,3,1
a.reset();
Test.ensureTrue(a.incrementCM(), "0");
Test.ensureEqual(a.getIndex(), 0, "0");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,0}, "0");

Test.ensureTrue(a.incrementCM(), "1");
Test.ensureEqual(a.getIndex(), 6, "1");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,0}, "1");

Test.ensureTrue(a.incrementCM(), "2");
Test.ensureEqual(a.getIndex(), 3, "2");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,0}, "2");

Test.ensureTrue(a.incrementCM(), "3");
Test.ensureEqual(a.getIndex(), 9, "3");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,0}, "3");

Test.ensureTrue(a.incrementCM(), "4");
Test.ensureEqual(a.getIndex(), 1, "4");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,1}, "4");

Test.ensureTrue(a.incrementCM(), "5");
Test.ensureEqual(a.getIndex(), 7, "5");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,1}, "5");

Test.ensureTrue(a.incrementCM(), "6");
Test.ensureEqual(a.getIndex(), 4, "6");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,1}, "6");

Test.ensureTrue(a.incrementCM(), "7");
Test.ensureEqual(a.getIndex(), 10, "7");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,1}, "7");

Test.ensureTrue(a.incrementCM(), "8");
Test.ensureEqual(a.getIndex(), 2, "8");
Test.ensureEqual(a.getCurrent(), new int[]{0,0,2}, "8");

Test.ensureTrue(a.incrementCM(), "9");
Test.ensureEqual(a.getIndex(), 8, "9");
Test.ensureEqual(a.getCurrent(), new int[]{1,0,2}, "9");

Test.ensureTrue(a.incrementCM(), "10");
Test.ensureEqual(a.getIndex(), 5, "10");
Test.ensureEqual(a.getCurrent(), new int[]{0,1,2}, "10");

Test.ensureTrue(a.incrementCM(), "11");
Test.ensureEqual(a.getIndex(), 11, "11");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,2}, "11");

Test.ensureTrue(!a.incrementCM(), "12");
Test.ensureEqual(a.getIndex(), 12, "12");

//test some invalid requests
try {
NDimensionalIndex b = new NDimensionalIndex(new int[0]);
throw new Exception("");
} catch (Exception e) {
if (e.toString().indexOf("nDimensions=0") < 0)
throw e;
}
try {
NDimensionalIndex b = new NDimensionalIndex(new int[]{2,0});
throw new Exception("");
} catch (Exception e) {
if (e.toString().indexOf("value less than 1") < 0)
throw e;
}

try {
a.setIndex(-1);
throw new Exception("");
} catch (Exception e) {
if (e.toString().indexOf("less than 0") < 0)
throw e;
}
try {
a.setCurrent(new int[]{1,1});
throw new Exception("");
} catch (Exception e) {
if (e.toString().indexOf("isn't 3") < 0)
throw e;
}

try {
a.setCurrent(new int[]{1,-1,1});
throw new Exception("");
} catch (Exception e) {
if (e.toString().indexOf("is invalid") < 0)
throw e;
}

//test get/set index/current
Test.ensureEqual(a.setCurrent(new int[]{1,1,2}), 11, "");
Test.ensureEqual(a.getIndex(), 11, "");
Test.ensureEqual(a.setIndex(9), new int[]{1,1,0}, "");
Test.ensureEqual(a.getCurrent(), new int[]{1,1,0}, "");

}

/**
* This runs all of the interactive or not interactive tests for this class.
*
* @param errorSB all caught exceptions are logged to this.
* @param interactive If true, this runs all of the interactive tests;
* otherwise, this runs all of the non-interactive tests.
* @param doSlowTestsToo If true, this runs the slow tests, too.
* @param firstTest The first test to be run (0...). Test numbers may change.
* @param lastTest The last test to be run, inclusive (0..., or -1 for the last test).
* Test numbers may change.
*/
public static void test(StringBuilder errorSB, boolean interactive,
boolean doSlowTestsToo, int firstTest, int lastTest) {
if (lastTest < 0)
lastTest = interactive? -1 : 1;
String msg = "\n^^^ NDimensionalIndex.test(" + interactive + ") test=";

for (int test = firstTest; test <= lastTest; test++) {
try {
long time = System.currentTimeMillis();
String2.log(msg + test);

if (interactive) {
//if (test == 0) ...;

} else {
if (test == 0) basicTest();
if (test == 1) testSubsetIndex();
}

String2.log(msg + test + " finished successfully in " + (System.currentTimeMillis() - time) + " ms.");
} catch (Throwable testThrowable) {
String eMsg = msg + test + " caught throwable:\n" +
MustBe.throwableToString(testThrowable);
errorSB.append(eMsg);
String2.log(eMsg);
if (interactive)
String2.pressEnterToContinue("");
}
}
}

}
Loading