Skip to content

Commit

Permalink
sentinel cross IDL unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed Apr 17, 2024
1 parent f02f5d1 commit add4d79
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testCreateJson()
JSONObject granule = mfte.createJson();
System.out.println(granule.toJSONString());
assertEquals("20170408033000-JPL-L2P_GHRSST-SSTskin-MODIS_T-N-v02.0-fv01.0", granule.get("GranuleUR"));
compareFileWithGranuleJson("ummgResults/from_mp_file/20170408033000-JPL-L2P_GHRSST-SSTskin-MODIS_T-N-v02.0-fv01.0.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/from_mp_file/20170408033000-JPL-L2P_GHRSST-SSTskin-MODIS_T-N-v02.0-fv01.0.json", granuleJson));
}

@Test
Expand Down Expand Up @@ -177,7 +177,7 @@ public void testCreateJsonWithOrbitNumber()
JSONArray orbitArray = (JSONArray) granule.get("OrbitCalculatedSpatialDomains");
Integer orbitNumber = (Integer) ((JSONObject) orbitArray.get(0)).get("OrbitNumber");
assertEquals(orbitNumber, new Integer(870));
compareFileWithGranuleJson("ummgResults/from_mp_file/RSS_SMAP_SSS_L2C_r00870_20150401T004312_2015091_FNL_V04.0.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/from_mp_file/RSS_SMAP_SSS_L2C_r00870_20150401T004312_2015091_FNL_V04.0.json", granuleJson));
}

@Test
Expand All @@ -199,7 +199,7 @@ public void testCreateJsonWithStartEndOrbitNumber()
Integer endOrbit = (Integer) ((JSONObject) orbitArray.get(0)).get("EndOrbitNumber");
assertEquals(beginOrbit, new Integer("870"));
assertEquals(endOrbit, new Integer("1308"));
compareFileWithGranuleJson("ummgResults/from_mp_file/RSS_smap_SSS_L3_monthly_2015_04_FNL_v04.0_OrbitStartEnd.json", granule);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/from_mp_file/RSS_smap_SSS_L3_monthly_2015_04_FNL_v04.0_OrbitStartEnd.json", granule));
}

@Test
Expand Down Expand Up @@ -230,7 +230,7 @@ public void testCreateJsonWithCyclePass()
JSONObject track = (JSONObject) ((JSONObject) ((JSONObject) granule.get("SpatialExtent")).get("HorizontalSpatialDomain")).get("Track");
assertEquals(new Long(374), track.get("Cycle"));
assertEquals(new Long(172), ((JSONObject) ((JSONArray) track.get("Passes")).get(0)).get("Pass"));
compareFileWithGranuleJson("ummgResults/from_mp_file/JA1_GPN_2PeP374_172_20120303_112035_20120303_121638_withcyclepass.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/from_mp_file/JA1_GPN_2PeP374_172_20120303_112035_20120303_121638_withcyclepass.json", granuleJson));
}

@Test
Expand All @@ -252,7 +252,7 @@ public void testSwotArchive()
JSONObject track = (JSONObject) ((JSONObject) ((JSONObject) granule.get("SpatialExtent")).get("HorizontalSpatialDomain")).get("Track");
assertEquals(new Long(22), track.get("Cycle"));
assertEquals(new Long(33), ((JSONObject) ((JSONArray) track.get("Passes")).get(0)).get("Pass"));
compareFileWithGranuleJson("ummgResults/swotArchiveXml/SWOT_IVK_20210612T081400_20210612T072103_20210612T080137_O_APID1402.PTM_1.archive.json", granule);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotArchiveXml/SWOT_IVK_20210612T081400_20210612T072103_20210612T080137_O_APID1402.PTM_1.archive.json", granule));
}

@Test
Expand Down Expand Up @@ -546,7 +546,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAll() throws Par
Arrays.toString(keys.toArray()) + "\n" +
Arrays.toString(checkForKey.toArray())));
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAll.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAll.json", granuleJson));
}

/**
Expand Down Expand Up @@ -652,7 +652,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON() thr
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.json", granule);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0.json", granule));
}

@Test
Expand Down Expand Up @@ -701,7 +701,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishSpecific() throw
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishSpecific.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishSpecific.json", granuleJson));
}

@Test
Expand Down Expand Up @@ -759,7 +759,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllWithSpecific(
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllWithSpecific.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllWithSpecific.json", granuleJson));
}

@Test
Expand Down Expand Up @@ -848,7 +848,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_publishAllEmptyCatchErr
} catch (Exception e){
fail("Issue when generating JSON");
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllEmptyCatchError_3.json", granule);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_publishAllEmptyCatchError_3.json", granule));
}

@Test
Expand Down Expand Up @@ -923,7 +923,7 @@ public void testReadIsoMendsMetadataFileAdditionalFields_appendFieldToJSON_Strin
e.printStackTrace();
fail();
}
compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_appendFieldToJSON_String.json", granuleJson);
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/additionalAttributes/OPERA_L3_DSWx_HLS_T14RNV_20210906T170251Z_20221026T184342Z_L8_30_v0.0_appendFieldToJSON_String.json", granuleJson));
}

@Test
Expand Down Expand Up @@ -973,23 +973,7 @@ public void testCreateJsonSwotCalVal() throws IOException, ParseException, XPath
// load pre-saved file and compare with generated granule JSONObject
// SWOTCalVal_WM_ADCP_L0_RiverRay1_20220727T191701_20220727T192858_20220920T142800_swotCalVal_ummg.json
// load pre-saved file and perform json comparison
assertTrue(compareFileWithGranuleJson("ummgResults/swotCalVal/SWOTCalVal_WM_ADCP_L0_RiverRay1_20220727T191701_20220727T192858_20220920T142800_swotCalVal_ummg.json", granule));
}

public boolean compareFileWithGranuleJson(String filePath, JSONObject granuleJson) throws
IOException, ParseException{
ClassLoader classLoader = getClass().getClassLoader();
File preSavedJsonFile = new File(classLoader.getResource(filePath).getFile());
String readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
JSONParser parser = new JSONParser();
ObjectMapper mapper = new ObjectMapper();
JSONObject readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// remove ProviderDates structure because it always has most current datetime
// the ProviderDates saved in file is different than the provider dates generated on the fly
granuleJson.remove("ProviderDates");
readInJsonObj.remove("ProviderDates");
assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granuleJson.toJSONString()));
return true; // if reached this point, return true
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotCalVal/SWOTCalVal_WM_ADCP_L0_RiverRay1_20220727T191701_20220727T192858_20220920T142800_swotCalVal_ummg.json", granule));
}
@Test
public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseException, XPathExpressionException, ParserConfigurationException, SAXException, URISyntaxException {
Expand Down Expand Up @@ -1074,7 +1058,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE


// verify the pre-saved ummg.json file is equal to the granule json just built
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json", granule));
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json", granule));
/**
* Test isoXMLSpatial:[footprint]
*/
Expand Down Expand Up @@ -1124,7 +1108,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
.get("BoundingRectangles"));
assert bbox == null;
// load pre-saved file and perform json comparison
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json", granule));
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json", granule));
/**
* Test isoXMLSpatial:[bbox]
*/
Expand Down Expand Up @@ -1164,7 +1148,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
assert ((BigDecimal)bbox.get("EastBoundingCoordinate")).compareTo(new BigDecimal("45.675058000000035463017411530017852783203125"))==0;
assert ((BigDecimal)bbox.get("NorthBoundingCoordinate")).compareTo(new BigDecimal("78.272067999999990206561051309108734130859375"))==0;
// load pre-saved file and perform json comparison
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json", granule));
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json", granule));
/**
* Test isoXMLSpatial:[orbit]
*/
Expand Down Expand Up @@ -1203,7 +1187,7 @@ public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseE
.get("Geometry")));
assert bbox == null;
// load pre-saved file and perform json comparison
assertTrue(compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_orbit.json", granule));
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_orbit.json", granule));
}

private void clearVariables4IsoXMLSpatialTest(JSONArray isoXMLSpatialArray, HashSet isoXMLSpatialHashSet, JSONObject granule) {
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/gov/nasa/cumulus/metadata/test/UMMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ public void testSentinelManifestOverIDL()
String granuleId ="S6A_P4_2__LR_STD__ST_022_132_20210619T002429_20210619T012042_F02";

JSONObject umm = parseXfduManifest(testFile, testConfigFile, granuleId);

//SpatialExtent
JSONObject hsd = (JSONObject) ((JSONObject) umm.get("SpatialExtent" )).get("HorizontalSpatialDomain" );

Expand Down Expand Up @@ -487,6 +486,8 @@ public void testSentinelManifestOverIDL()
lastPoint = (JSONObject) pnts.get(29);
assertEquals(Double.valueOf(56.013938), ((Double) lastPoint.get("Latitude" )));
assertEquals(Double.valueOf(-171.655155), ((Double) lastPoint.get("Longitude" )));

assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/sentinel6/S6A_P4_2__LR_STD__ST_022_132_20210619T002429_20210619T012042_F02_overIde.json",umm));
}

@Test
Expand All @@ -499,7 +500,6 @@ public void testSentinelManifestL0TooFewCoordinates()
String granuleId ="S6A_P4_2__LR_STD__ST_022_132_20210619T002429_20210619T012042_F02";

JSONObject umm = parseXfduManifest(testFile, testConfigFile, granuleId);

//SpatialExtent
JSONObject hsd = (JSONObject) ((JSONObject) umm.get("SpatialExtent" )).get("HorizontalSpatialDomain" );
JSONArray boundingCoordinates = (JSONArray) ((JSONObject)hsd.get("Geometry")).get("BoundingRectangles");
Expand All @@ -524,6 +524,10 @@ public void testSentinelManifestNotOverIDL()

JSONObject umm = parseXfduManifest(testFile, testConfigFile, granuleId);

MetadataFilesToEcho mfte = new MetadataFilesToEcho(true);
mfte.writeJson("/tmp/notOverIDL.json", umm.toJSONString());


//SpatialExtent
JSONObject hsd = (JSONObject) ((JSONObject) umm.get("SpatialExtent" )).get("HorizontalSpatialDomain" );

Expand All @@ -545,6 +549,7 @@ public void testSentinelManifestNotOverIDL()
JSONObject lastPoint = (JSONObject) pnts.get(31);
assertEquals(Double.valueOf(-62.663981), ((Double) lastPoint.get("Latitude" )));
assertEquals(Double.valueOf(2.525361), ((Double) lastPoint.get("Longitude" )));
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/sentinel6/S6A_P4_2__LR_STD__ST_022_131_20210618T232816_20210619T002429_F02_notOverIDL.json", umm));
}

@Test
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/gov/nasa/cumulus/metadata/test/UnitTestUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gov.nasa.cumulus.metadata.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;

public class UnitTestUtil {
public static boolean compareFileWithGranuleJson(String filePath, JSONObject granuleJson) throws
IOException, ParseException {
ClassLoader classLoader = UnitTestUtil.class.getClassLoader();
File preSavedJsonFile = new File(classLoader.getResource(filePath).getFile());
String readInJsonStr = FileUtils.readFileToString(preSavedJsonFile, StandardCharsets.UTF_8);
JSONParser parser = new JSONParser();
ObjectMapper mapper = new ObjectMapper();
JSONObject readInJsonObj = (JSONObject) parser.parse(readInJsonStr);
// remove ProviderDates structure because it always has most current datetime
// the ProviderDates saved in file is different than the provider dates generated on the fly
granuleJson.remove("ProviderDates");
readInJsonObj.remove("ProviderDates");
assertEquals(mapper.readTree(readInJsonObj.toJSONString()), mapper.readTree(granuleJson.toJSONString()));
return true; // if reached this point, return true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"TemporalExtent":{"RangeDateTime":{"EndingDateTime":"2021-06-19T00:24:29.471Z","BeginningDateTime":"2021-06-18T23:28:16.542Z"}},"MetadataSpecification":{"Version":"1.6.5","URL":"https:\/\/cdn.earthdata.nasa.gov\/umm\/granule\/v1.6.5","Name":"UMM-G"},"GranuleUR":"S6A_P4_2__LR_STD__ST_022_131_20210618T232816_20210619T002429_F02","ProviderDates":[{"Type":"Insert","Date":"2024-04-17T22:56:28.512Z"},{"Type":"Update","Date":"2024-04-17T22:56:28.514Z"}],"SpatialExtent":{"HorizontalSpatialDomain":{"Geometry":{"GPolygons":[{"Boundary":{"Points":[{"Latitude":-65.649768,"Longitude":-25.561001},{"Latitude":-66.644101,"Longitude":-25.454693},{"Latitude":-63.597255,"Longitude":2.884525},{"Latitude":-56.022254,"Longitude":22.501876},{"Latitude":-46.176484,"Longitude":34.738356},{"Latitude":-35.287184,"Longitude":42.821997},{"Latitude":-23.891329,"Longitude":48.714422},{"Latitude":-12.243013,"Longitude":53.479583},{"Latitude":-0.492119,"Longitude":57.755247},{"Latitude":11.245057,"Longitude":62.012329},{"Latitude":22.847334,"Longitude":66.712901},{"Latitude":34.159401,"Longitude":72.465261},{"Latitude":44.931266,"Longitude":80.267339},{"Latitude":54.690314,"Longitude":91.997549},{"Latitude":62.326143,"Longitude":110.882612},{"Latitude":65.638561,"Longitude":138.707184},{"Latitude":65.64749,"Longitude":140.321732},{"Latitude":66.647475,"Longitude":140.316202},{"Latitude":66.638546,"Longitude":138.701654},{"Latitude":63.319145,"Longitude":110.764513},{"Latitude":55.61772,"Longitude":91.623494},{"Latitude":45.700998,"Longitude":79.628972},{"Latitude":34.746947,"Longitude":71.65607},{"Latitude":23.301042,"Longitude":65.821751},{"Latitude":11.620689,"Longitude":61.08556},{"Latitude":-0.151127,"Longitude":56.81518},{"Latitude":-11.901085,"Longitude":52.539857},{"Latitude":-23.512671,"Longitude":47.788885},{"Latitude":-34.827746,"Longitude":41.933788},{"Latitude":-45.580038,"Longitude":33.935703},{"Latitude":-55.2425,"Longitude":21.87579},{"Latitude":-62.663981,"Longitude":2.525361},{"Latitude":-65.649768,"Longitude":-25.561001}]}}]},"Track":{"Cycle":22,"Passes":[{"Pass":131}]}}},"AdditionalAttributes":[{"Values":["S6A_P4_2__LR______20210618T232816_20210619T002429_20210619T220302_3373_022_131_065_EUM__OPE_ST_F02.SEN6"],"Name":"ProviderDataSource"}],"DataGranule":{"DayNightFlag":"Unspecified","ProductionDateTime":"2021-06-19T22:10:40.000Z"},"CollectionReference":{"Version":"E","ShortName":"JASON_CS_S6A_L0_ALT_ACQ"}}
Loading

0 comments on commit add4d79

Please sign in to comment.