Skip to content

Commit

Permalink
refactor skip if nc4 is not present to static utility
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyajohnson committed Sep 12, 2023
1 parent 0d0b033 commit bf3f505
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Element> xpath = XPathFactory.instance().compile("/grid/point/data[@name='Temperature_isobaric']",
* Filters.element());
* List<Element> elements = xpath.evaluate(doc);
* assertEquals(1, elements.size());
* }
*/

@Test
public void checkGridForDifferentFormats() throws Exception {
checkGrid("");
Expand Down Expand Up @@ -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";
Expand All @@ -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");
Expand Down Expand Up @@ -197,8 +172,4 @@ private void checkFileType(String acceptParameter, int expectedResponseCode, Str
}
}
}

private static void skipTestIfNetCDF4NotPresent() {
assumeTrue(NetcdfClibrary.isLibraryPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -163,8 +164,4 @@ public boolean matches(Object item) {
return value.endsWith(suffix);
}
}

private static void skipTestIfNetCDF4NotPresent() {
assumeTrue(NetcdfClibrary.isLibraryPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void setUp() throws IOException {

@Test
public void shouldGetVariablesSubset() throws Exception {
skipTestIfNetCDF4NotPresent();
TestUtils.skipTestIfNetCDF4NotPresent(format);

// gridDataController.getGridSubset(params, validationResult, response);

Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -148,10 +149,4 @@ public void shouldGetTimeRange() throws Exception {
assertEquals(lengthTimeDim, time.getLength());

}

private void skipTestIfNetCDF4NotPresent() {
if (format == SupportedFormat.NETCDF4) {
assumeTrue(NetcdfClibrary.isLibraryPresent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -151,10 +152,4 @@ public void match(MvcResult result) throws Exception {
}
});
}

private void skipTestIfNetCDF4NotPresent() {
if (format == SupportedFormat.NETCDF4) {
assumeTrue(NetcdfClibrary.isLibraryPresent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -167,9 +168,5 @@ public void noFeaturesInPointCollection() throws Exception {

this.mockMvc.perform(rb).andExpect(MockMvcResultMatchers.status().isBadRequest());
}

private static void skipTestIfNetCDF4NotPresent() {
assumeTrue(NetcdfClibrary.isLibraryPresent());
}
}

19 changes: 19 additions & 0 deletions tds/src/test/java/thredds/util/TestUtils.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit bf3f505

Please sign in to comment.