From bf3f50523e48a474772608310779c703c5f0d2d3 Mon Sep 17 00:00:00 2001 From: haileyajohnson Date: Tue, 12 Sep 2023 13:19:54 -0600 Subject: [PATCH] refactor skip if nc4 is not present to static utility --- .../server/ncss/NcssGridIntegrationTest.java | 35 ++----------------- .../grid/GridDatasetControllerTest.java | 7 ++-- .../grid/SpatialSubsettingTest.java | 9 ++--- .../grid/TemporalSpaceSubsettingTest.java | 9 ++--- .../grid/VariableSpaceSubsettingTest.java | 9 ++--- .../point/TestStationFCController.java | 7 ++-- tds/src/test/java/thredds/util/TestUtils.java | 19 ++++++++++ 7 files changed, 32 insertions(+), 63 deletions(-) create mode 100644 tds/src/test/java/thredds/util/TestUtils.java diff --git a/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java b/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java index b52bbe9903..a9781efe9f 100644 --- a/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java +++ b/tds/src/integrationTests/java/thredds/server/ncss/NcssGridIntegrationTest.java @@ -15,6 +15,7 @@ import thredds.test.util.TestOnLocalServer; import thredds.util.Constants; import thredds.util.ContentType; +import thredds.util.TestUtils; import ucar.httpservices.HTTPException; import ucar.httpservices.HTTPFactory; import ucar.httpservices.HTTPMethod; @@ -48,32 +49,6 @@ private void openBinaryNew(byte[] content, String gridName) throws IOException { } } - private void openBinaryOld(byte[] content, String gridName) throws IOException { - try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { - GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); - assertThat(gdsDataset.findGridByName(gridName)).isNotNull(); - logger.debug("{}", nf); - } - } - - /* - * @HttpTest(method = Method.GET, path = - * "ncss/grid/gribCollection/GFS_CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1/GC?var=Temperature_isobaric&latitude=40&longitude=-102&vertCoord=225") - * public void checkGridAsPointXml() throws JDOMException, IOException { - * assertOk(response); - * String xml = response.getBody(String.class); - * logger.debug("xml={}", xml); - * Reader in = new StringReader(xml); - * SAXBuilder sb = new SAXBuilder(); - * Document doc = sb.build(in); - * - * XPathExpression xpath = XPathFactory.instance().compile("/grid/point/data[@name='Temperature_isobaric']", - * Filters.element()); - * List elements = xpath.evaluate(doc); - * assertEquals(1, elements.size()); - * } - */ - @Test public void checkGridForDifferentFormats() throws Exception { checkGrid(""); @@ -152,7 +127,7 @@ public void checkFmrcBest() throws Exception { // this fails when _ChunkSizes are left on @Test public void testNcssFailure() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(); String filename = "scanCdmUnitTests/formats/netcdf4/COMPRESS_LEV2_20140201000000-GLOBCURRENT-L4-CURekm_15m-ERAWS_EEM-v02.0-fv01.0.nc"; @@ -168,7 +143,7 @@ public void testNcssFailure() throws Exception { @Test public void shouldReturnCorrectFileTypeForAcceptParameter() throws HTTPException { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(); checkFileType("netcdf3", HttpServletResponse.SC_OK, ".nc"); checkFileType("netcdf", HttpServletResponse.SC_OK, ".nc"); @@ -197,8 +172,4 @@ private void checkFileType(String acceptParameter, int expectedResponseCode, Str } } } - - private static void skipTestIfNetCDF4NotPresent() { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } } diff --git a/tds/src/test/java/thredds/server/ncss/controller/grid/GridDatasetControllerTest.java b/tds/src/test/java/thredds/server/ncss/controller/grid/GridDatasetControllerTest.java index 0b35851c56..777fd5d544 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/grid/GridDatasetControllerTest.java +++ b/tds/src/test/java/thredds/server/ncss/controller/grid/GridDatasetControllerTest.java @@ -30,6 +30,7 @@ import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.format.SupportedFormat; import thredds.util.Constants; +import thredds.util.TestUtils; import ucar.nc2.ffi.netcdf.NetcdfClibrary; import ucar.nc2.util.cache.FileCacheIF; import ucar.unidata.io.RandomAccessFile; @@ -78,7 +79,7 @@ public void getGridSubsetOnGridDataset() throws Exception { @Test @Category(NeedsCdmUnitTest.class) public void getGridSubsetOnGridDatasetNc4() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(); RequestBuilder rb = MockMvcRequestBuilders.get("/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd") .servletPath("/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd") @@ -163,8 +164,4 @@ public boolean matches(Object item) { return value.endsWith(suffix); } } - - private static void skipTestIfNetCDF4NotPresent() { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } } 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 46b823d1ee..e5ab46188d 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 @@ -32,6 +32,7 @@ import thredds.server.ncss.controller.AbstractNcssController; import thredds.server.ncss.dataservice.DatasetHandlerAdapter; import thredds.server.ncss.format.SupportedFormat; +import thredds.util.TestUtils; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; @@ -129,7 +130,7 @@ public void setUp() throws IOException { @Test public void shouldGetVariablesSubset() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(format); // gridDataController.getGridSubset(params, validationResult, response); @@ -160,10 +161,4 @@ public static void showRequest(MockHttpServletRequest req) { } System.out.printf("%s%n%s%n", req.getRequestURI(), f); } - - private void skipTestIfNetCDF4NotPresent() { - if (format == SupportedFormat.NETCDF4) { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } - } } 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 d7867ec122..8fc6d108f4 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 @@ -26,6 +26,7 @@ import thredds.mock.params.GridPathParams; import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.format.SupportedFormat; +import thredds.util.TestUtils; import ucar.nc2.Dimension; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; @@ -123,7 +124,7 @@ public void setUp() throws IOException { @Test public void shouldGetTimeRange() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(format); MvcResult mvc = this.mockMvc.perform(requestBuilder).andReturn(); @@ -148,10 +149,4 @@ public void shouldGetTimeRange() throws Exception { assertEquals(lengthTimeDim, time.getLength()); } - - private void skipTestIfNetCDF4NotPresent() { - if (format == SupportedFormat.NETCDF4) { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } - } } 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 53114f6cf9..413643b375 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 @@ -29,6 +29,7 @@ import thredds.mock.params.GridPathParams; import thredds.mock.web.MockTdsContextLoader; import thredds.server.ncss.format.SupportedFormat; +import thredds.util.TestUtils; import ucar.nc2.NetcdfFile; import ucar.nc2.NetcdfFiles; import ucar.nc2.dataset.NetcdfDataset; @@ -127,7 +128,7 @@ public void setUp() throws IOException { @Test public void shouldGetVariablesSubset() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(format); mockMvc.perform(requestBuilder).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(new ResultMatcher() { public void match(MvcResult result) throws Exception { @@ -151,10 +152,4 @@ public void match(MvcResult result) throws Exception { } }); } - - private void skipTestIfNetCDF4NotPresent() { - if (format == SupportedFormat.NETCDF4) { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } - } } diff --git a/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFCController.java b/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFCController.java index 31e1d97ce6..64e472f586 100644 --- a/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFCController.java +++ b/tds/src/test/java/thredds/server/ncss/controller/point/TestStationFCController.java @@ -31,6 +31,7 @@ import thredds.server.ncss.exception.FeaturesNotFoundException; import thredds.server.ncss.format.SupportedFormat; import thredds.util.ContentType; +import thredds.util.TestUtils; import ucar.nc2.ffi.netcdf.NetcdfClibrary; import ucar.unidata.util.test.category.NeedsCdmUnitTest; import java.lang.invoke.MethodHandles; @@ -61,7 +62,7 @@ public void setup() { @Test public void getClosestStationData() throws Exception { - skipTestIfNetCDF4NotPresent(); + TestUtils.skipTestIfNetCDF4NotPresent(); long start = System.currentTimeMillis(); RequestBuilder rb = MockMvcRequestBuilders.get(dataset).servletPath(dataset).param("longitude", "-105.203") @@ -167,9 +168,5 @@ public void noFeaturesInPointCollection() throws Exception { this.mockMvc.perform(rb).andExpect(MockMvcResultMatchers.status().isBadRequest()); } - - private static void skipTestIfNetCDF4NotPresent() { - assumeTrue(NetcdfClibrary.isLibraryPresent()); - } } diff --git a/tds/src/test/java/thredds/util/TestUtils.java b/tds/src/test/java/thredds/util/TestUtils.java new file mode 100644 index 0000000000..1128243afc --- /dev/null +++ b/tds/src/test/java/thredds/util/TestUtils.java @@ -0,0 +1,19 @@ +package thredds.util; + +import thredds.server.ncss.format.SupportedFormat; +import ucar.nc2.ffi.netcdf.NetcdfClibrary; + +import static org.junit.Assume.assumeTrue; + +public class TestUtils { + + public static void skipTestIfNetCDF4NotPresent(SupportedFormat format) { + if (format == SupportedFormat.NETCDF4) { + skipTestIfNetCDF4NotPresent(); + } + } + + public static void skipTestIfNetCDF4NotPresent() { + assumeTrue(NetcdfClibrary.isLibraryPresent()); + } +}