Skip to content

Commit

Permalink
unit test against pre-saved ummg.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed Apr 17, 2024
1 parent e32e83e commit 2833f8e
Show file tree
Hide file tree
Showing 26 changed files with 3,377 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update to use CMA 2.0.0, thus allowing 2.0.3 layer for lambda
- Update build to use java 11
- To generate java 11 compatible UMMG schema POJOs, jsonschema2pojo shall make use of command line parameter: --target-version 1.11
- **PODAAC-6169**
- SWOT iso.xml
- OPERA iso.xml
- SWOT archive.xml
- .mp
- SWOT CalVal XML
- Does/does not cross the IDL
### Deprecated
### Removed
### Fixed
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String PerformFunction(String input, Context context) throws Exception {
}

/*
Typically should only have 1 file tagged with "Data"
Typically should only have 1 file tagged as "data"
*/
//data location
String s3Location = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -99,7 +100,6 @@ public void readConfiguration(String file) throws IOException, ParseException {
(Boolean) metadata.get("rangeIs360"),
null,
additionalAttributes);

}

/**
Expand Down Expand Up @@ -1081,7 +1081,18 @@ public void writeJson(String outputLocation)
throws IOException, ParseException, URISyntaxException{
JSONObject granuleJson = createJson();
JSONUtils.cleanJSON(granuleJson);
FileUtils.writeStringToFile(new File(outputLocation), granuleJson.toJSONString());
FileUtils.writeStringToFile(new File(outputLocation), granuleJson.toJSONString(), StandardCharsets.UTF_8);
}

public void writeJson(String outputLocation, JSONObject jsonObject)
throws IOException{
JSONObject granuleJson = jsonObject;
FileUtils.writeStringToFile(new File(outputLocation), granuleJson.toJSONString(), StandardCharsets.UTF_8);
}

public void writeJson(String outputLocation, String jsonStr)
throws IOException{
FileUtils.writeStringToFile(new File(outputLocation), jsonStr, StandardCharsets.UTF_8);
}

public Dataset getDataset(){
Expand Down

Large diffs are not rendered by default.

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
}
}
Loading

0 comments on commit 2833f8e

Please sign in to comment.