Skip to content

Commit 96c7af9

Browse files
committed
Add test to detect failing reflection for netcdf-c runtime loading
1 parent e3f6ac9 commit 96c7af9

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

netcdf4/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
testImplementation project(':cdm-test-utils')
2020

2121
testImplementation 'com.google.truth:truth'
22+
testImplementation 'org.jdom:jdom2'
2223

2324
testRuntimeOnly 'ch.qos.logback:logback-classic'
2425
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025 University Corporation for Atmospheric Research/Unidata
3+
* See LICENSE.txt for license information.
4+
*/
5+
6+
package ucar.nc2.util.xml;
7+
8+
import static com.google.common.truth.Truth.assertThat;
9+
10+
import java.io.File;
11+
import java.io.FileInputStream;
12+
import java.io.IOException;
13+
import java.nio.file.Paths;
14+
import org.junit.Test;
15+
16+
public class TestRuntimeConfigParser {
17+
@Test
18+
public void testReflection() throws IOException {
19+
// not testing that the loading actually work, but testing that the reflection
20+
// calls in the RuntimeConfigParser work
21+
File nj22config =
22+
Paths.get("src/test/resources/runtimeConfig/nj22Config.xml").toAbsolutePath().normalize().toFile();
23+
StringBuilder errlog = new StringBuilder();
24+
try (FileInputStream fis = new FileInputStream(nj22config)) {
25+
RuntimeConfigParser.read(fis, errlog);
26+
}
27+
String err = errlog.toString();
28+
assertThat(err).isNotEmpty();
29+
// since this test lives in the netcdf4 subproject, we should only see
30+
// the "is not on classpath" message if the reflection call used in the
31+
// RuntimeConfigParser code fails
32+
assertThat(err).doesNotContain("is not on classpath");
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<nj22Config>
2+
<Netcdf4Clibrary>
3+
<libraryPath>/not/a/real/path</libraryPath>
4+
<libraryName>netcdf</libraryName>
5+
<useForReading>false</useForReading>
6+
</Netcdf4Clibrary>
7+
</nj22Config>

0 commit comments

Comments
 (0)