Skip to content

Commit

Permalink
Update openday enhancements test and add enhance=none test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Tara Drwenski committed Jan 11, 2024
1 parent 37ae57f commit 2e00cb6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TestEnhancements {

final static String ENHANCED_FILE = "localContent/testOffset.nc";
final static String NCML_ENHANCED_FILE = "testOffsetWithNcml.nc";
final static String NCML_ENHANCE_NONE_FILE = "testOffsetWithNcmlEnhanceNone.nc";
final static String ENHANCED_VAR_NAME = "variableWithOffset";
final static String NOT_ENHANCED_VAR_NAME = "variableWithoutOffset";

Expand All @@ -31,7 +32,7 @@ public void testNCSSWithEnhancements() throws IOException {
final byte[] content = TestOnLocalServer.getContent(endpoint, HttpServletResponse.SC_OK, ContentType.netcdf);

try (NetcdfFile netcdfFile = NetcdfFiles.openInMemory("test_data.nc", content)) {
checkResultWithEnhancements(netcdfFile, 0);
checkResultWithEnhancements(netcdfFile, 0, true);
}
}

Expand All @@ -43,7 +44,7 @@ public void testNCSSWithEnhancementsNcML() throws IOException {
final byte[] content = TestOnLocalServer.getContent(endpoint, HttpServletResponse.SC_OK, ContentType.netcdf);

try (NetcdfFile netcdfFile = NetcdfFiles.openInMemory("test_data.nc", content)) {
checkResultWithEnhancements(netcdfFile, 100);
checkResultWithEnhancements(netcdfFile, 100, true);
}
}

Expand All @@ -52,7 +53,8 @@ public void testOpendapWithEnhancements() throws IOException {
final String endpoint = TestOnLocalServer.withHttpPath("/dodsC/" + ENHANCED_FILE);

try (NetcdfFile netcdfFile = NetcdfDatasets.openFile(endpoint, null)) {
checkResultWithEnhancements(netcdfFile, 0);
// Does not apply dataset attribute enhancements to data
checkResultWithEnhancements(netcdfFile, -100, true);
}
}

Expand All @@ -61,16 +63,28 @@ public void testOpendapWithEnhancementsNcML() throws IOException {
final String endpoint = TestOnLocalServer.withHttpPath("/dodsC/" + NCML_ENHANCED_FILE);

try (NetcdfFile netcdfFile = NetcdfDatasets.openFile(endpoint, null)) {
checkResultWithEnhancements(netcdfFile, 100);
// Does apply NcML enhancements to data with enhance="all"
checkResultWithEnhancements(netcdfFile, 100, true);
}
}

private void checkResultWithEnhancements(NetcdfFile netcdfFile, int expectedDiff) throws IOException {
@Test
public void testOpendapWithEnhanceNoneNcML() throws IOException {
final String endpoint = TestOnLocalServer.withHttpPath("/dodsC/" + NCML_ENHANCE_NONE_FILE);

try (NetcdfFile netcdfFile = NetcdfDatasets.openFile(endpoint, null)) {
// Does not apply NcML enhancements to data with enhance="none"
checkResultWithEnhancements(netcdfFile, -100, false);
}
}

private void checkResultWithEnhancements(NetcdfFile netcdfFile, int expectedDiff, boolean shouldRemoveOffsetAtt)
throws IOException {
final Variable enhancedVar = netcdfFile.findVariable(ENHANCED_VAR_NAME);
final Variable orgVar = netcdfFile.findVariable(NOT_ENHANCED_VAR_NAME);
assertThat(enhancedVar != null).isTrue();
assertThat(orgVar != null).isTrue();
assertThat(orgVar.findAttribute("add_offset")).isNull();
assertThat(orgVar.findAttribute("add_offset") == null).isEqualTo(shouldRemoveOffsetAtt);
final Array values1 = enhancedVar.read();
final Array values2 = orgVar.read();
for (int i = 0; i < values1.getSize(); i++) {
Expand Down
9 changes: 9 additions & 0 deletions tds/src/test/content/thredds/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
</variable>
</ncml:netcdf>
</dataset>
<dataset name="With NcML enhance=none" ID="withNcMlEnhanceNone" serviceName="all" urlPath="testOffsetWithNcmlEnhanceNone.nc">
<serviceName>all</serviceName>
<ncml:netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" enhance="none"
location="content/testdata/testOffset.nc">
<variable name="variableWithoutOffset">
<attribute name="add_offset" type="float" value="-100"/>
</variable>
</ncml:netcdf>
</dataset>
</dataset>

<dataset name="Test Dap4 Dataset" ID="testDap4Dataset" serviceName="dap4"
Expand Down

0 comments on commit 2e00cb6

Please sign in to comment.