diff --git a/src/test/java/gov/nasa/cumulus/metadata/test/MetadataFilesToEchoTest.java b/src/test/java/gov/nasa/cumulus/metadata/test/MetadataFilesToEchoTest.java index 2905e62..4ffd528 100644 --- a/src/test/java/gov/nasa/cumulus/metadata/test/MetadataFilesToEchoTest.java +++ b/src/test/java/gov/nasa/cumulus/metadata/test/MetadataFilesToEchoTest.java @@ -14,6 +14,8 @@ import com.google.gson.GsonBuilder; import gov.nasa.cumulus.metadata.aggregator.*; +import gov.nasa.cumulus.metadata.aggregator.bo.TaskConfigBO; +import gov.nasa.cumulus.metadata.aggregator.factory.TaskConfigFactory; import gov.nasa.cumulus.metadata.state.MENDsIsoXMLSpatialTypeEnum; import gov.nasa.cumulus.metadata.umm.adapter.UMMGCollectionAdapter; import gov.nasa.cumulus.metadata.umm.adapter.UMMGListAdapter; @@ -994,4 +996,221 @@ public void testCreateJsonSwotCalVal() throws IOException, ParseException, XPath // load pre-saved file and perform json comparison 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 { + // Create isoXmlSpatial Hashtable which contains footprint, orbit then passed the hashtable to MetadataFilesToEcho contructor + MetadataAggregatorLambda lambda = new MetadataAggregatorLambda(); + org.json.simple.JSONArray array = new JSONArray(); + array.add("footprint"); + array.add("orbit"); + array.add("bbox"); + JSONObject config = new JSONObject(); + config.put("isoXMLSpatialType", array); + TaskConfigBO taskConfigBO = TaskConfigFactory.createTaskConfigBO(config); + HashSet h = taskConfigBO.getIsoXMLSpatialTypeHashSet(); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT)); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT)); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE)); + + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("swotIsoXMLSpatialTypeTestData/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01.nc.iso.xml").getFile()); + + // constructor to set isIso =true and the isoXmlSpatialHashtable + MetadataFilesToEcho mfte = new MetadataFilesToEcho(true, h); + mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01"); + File cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile()); + mfte.readConfiguration(cfgFile.getAbsolutePath()); + mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml"); + + JSONObject granule = mfte.createJson(); + JSONArray polygonPoints =((JSONArray)((JSONObject) ((JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("GPolygons")).get(0)).get("Boundary")).get("Points")); + Double latitude=(Double)((JSONObject)polygonPoints.get(0)).get("Latitude"); + Double longitude=(Double)((JSONObject)polygonPoints.get(0)).get("Longitude"); + assert latitude.doubleValue() ==-77.089598228; + assert longitude.doubleValue() == -121.56652283899999; + + latitude=(Double)((JSONObject)polygonPoints.get(27)).get("Latitude"); + longitude=(Double)((JSONObject)polygonPoints.get(27)).get("Longitude"); + assert latitude.doubleValue()==56.734470077; + assert longitude.doubleValue()==-21.668558564000023; + + latitude=(Double)((JSONObject)polygonPoints.get(64)).get("Latitude"); + longitude=(Double)((JSONObject)polygonPoints.get(64)).get("Longitude"); + assert latitude.doubleValue()==-77.089598228; + assert longitude.doubleValue()== -121.56652283899999; + + JSONObject orbit = ((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Orbit")); + assert ((Double)orbit.get("StartLatitude"))==-77.66; //-77.66 + assert ((Double)orbit.get("EndLatitude"))==77.66;// -> {Double@5567} 77.66 + assert ((Double)orbit.get("AscendingCrossing"))==-38.05; //-> {Double@5569} -38.05 + assertTrue(StringUtils.equals((String)orbit.get("StartDirection"), "A")); //-> A + assertTrue(StringUtils.equals((String)orbit.get("EndDirection"), "A")); //EndDirection -> A + + JSONObject bbox = (JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("BoundingRectangles")).get(0); + assert ((BigDecimal)bbox.get("WestBoundingCoordinate")).compareTo(new BigDecimal("-121.76947499999999990905052982270717620849609375")) ==0; + assert ((BigDecimal)bbox.get("SouthBoundingCoordinate")).compareTo(new BigDecimal("-78.271941999999995687176124192774295806884765625"))==0; + assert ((BigDecimal)bbox.get("EastBoundingCoordinate")).compareTo(new BigDecimal("45.675058000000035463017411530017852783203125"))==0; + assert ((BigDecimal)bbox.get("NorthBoundingCoordinate")).compareTo(new BigDecimal("78.272067999999990206561051309108734130859375"))==0; + + + // verify the pre-saved ummg.json file is equal to the granule json just built + assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json", granule)); + /** + * Test isoXMLSpatial:[footprint] + */ + clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first + array.add("footprint"); + config = new JSONObject(); + config.put("isoXMLSpatialType", array); + taskConfigBO = TaskConfigFactory.createTaskConfigBO(config); + h = taskConfigBO.getIsoXMLSpatialTypeHashSet(); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE)); + mfte = new MetadataFilesToEcho(true, h); + mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01"); + cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile()); + mfte.readConfiguration(cfgFile.getAbsolutePath()); + mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml"); + granule = mfte.createJson(); + polygonPoints =((JSONArray)((JSONObject) ((JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("GPolygons")).get(0)).get("Boundary")).get("Points")); + latitude=(Double)((JSONObject)polygonPoints.get(0)).get("Latitude"); + longitude=(Double)((JSONObject)polygonPoints.get(0)).get("Longitude"); + assert latitude.doubleValue() ==-77.089598228; + assert longitude.doubleValue() == -121.56652283899999; + + latitude=(Double)((JSONObject)polygonPoints.get(27)).get("Latitude"); + longitude=(Double)((JSONObject)polygonPoints.get(27)).get("Longitude"); + assert latitude.doubleValue()==56.734470077; + assert longitude.doubleValue()==-21.668558564000023; + + latitude=(Double)((JSONObject)polygonPoints.get(64)).get("Latitude"); + longitude=(Double)((JSONObject)polygonPoints.get(64)).get("Longitude"); + assert latitude.doubleValue()==-77.089598228; + assert longitude.doubleValue()== -121.56652283899999; + + orbit = ((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Orbit")); + assert orbit==null; + + bbox = (JSONObject) (((JSONObject)((JSONObject)((JSONObject) granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("BoundingRectangles")); + assert bbox == null; + // load pre-saved file and perform json comparison + assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json", granule)); + /** + * Test isoXMLSpatial:[bbox] + */ + clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first + array.add("bbox"); + config = new JSONObject(); + config.put("isoXMLSpatialType", array); + taskConfigBO = TaskConfigFactory.createTaskConfigBO(config); + h=taskConfigBO.getIsoXMLSpatialTypeHashSet(); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT)); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE)); + mfte = new MetadataFilesToEcho(true, h); + mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01"); + cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile()); + mfte.readConfiguration(cfgFile.getAbsolutePath()); + mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml"); + granule = mfte.createJson(); + JSONArray GPolygons = (JSONArray)((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("GPolygons"); + assert GPolygons ==null; + + orbit = ((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Orbit")); + assert orbit==null; + + bbox = (JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")) + .get("BoundingRectangles")).get(0); + assert ((BigDecimal)bbox.get("WestBoundingCoordinate")).compareTo(new BigDecimal("-121.76947499999999990905052982270717620849609375")) ==0; + assert ((BigDecimal)bbox.get("SouthBoundingCoordinate")).compareTo(new BigDecimal("-78.271941999999995687176124192774295806884765625"))==0; + 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(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json", granule)); + /** + * Test isoXMLSpatial:[orbit] + */ + clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first + array.add("orbit"); + config = new JSONObject(); + config.put("isoXMLSpatialType", array); + taskConfigBO = TaskConfigFactory.createTaskConfigBO(config); + h=taskConfigBO.getIsoXMLSpatialTypeHashSet(); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT)); + assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX)); + assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE)); + mfte = new MetadataFilesToEcho(true, h); + mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01"); + cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile()); + mfte.readConfiguration(cfgFile.getAbsolutePath()); + mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml"); + granule = mfte.createJson(); + JSONObject geometry = ((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry")); + assert geometry ==null; + + orbit = ((JSONObject)((JSONObject)((JSONObject)granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Orbit")); + assert ((Double)orbit.get("StartLatitude"))==-77.66; //-77.66 + assert ((Double)orbit.get("EndLatitude"))==77.66;// -> {Double@5567} 77.66 + assert ((Double)orbit.get("AscendingCrossing"))==-38.05; //-> {Double@5569} -38.05 + assertTrue(StringUtils.equals((String)orbit.get("StartDirection"), "A")); //-> A + assertTrue(StringUtils.equals((String)orbit.get("EndDirection"), "A")); //EndDirection -> A + // No Geometry object since there is neither footprint nor bbox + bbox = (((JSONObject)((JSONObject)((JSONObject) granule + .get("SpatialExtent")) + .get("HorizontalSpatialDomain")) + .get("Geometry"))); + assert bbox == null; + // load pre-saved file and perform json comparison + 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) { + isoXMLSpatialArray.clear(); + isoXMLSpatialHashSet.clear(); + granule.clear(); + } + } \ No newline at end of file diff --git a/src/test/java/gov/nasa/cumulus/metadata/test/UnitTestUtil.java b/src/test/java/gov/nasa/cumulus/metadata/test/UnitTestUtil.java index 68fe1d4..eda4a77 100644 --- a/src/test/java/gov/nasa/cumulus/metadata/test/UnitTestUtil.java +++ b/src/test/java/gov/nasa/cumulus/metadata/test/UnitTestUtil.java @@ -1,6 +1,5 @@ package gov.nasa.cumulus.metadata.test; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.FileUtils; import org.json.simple.JSONObject;