Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit e40fbbe

Browse files
committed
various unit test modifications and accounting for UTC timezone on YAML cases
Signed-off-by: Neal Ensor <[email protected]>
1 parent dfc896c commit e40fbbe

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/main/java/gov/osti/services/Validation.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import gov.osti.repository.SubversionRepository;
1717
import java.io.IOException;
1818
import java.io.Serializable;
19-
import java.math.BigDecimal;
2019
import java.net.URLEncoder;
2120
import java.util.regex.Matcher;
2221
import java.util.regex.Pattern;
@@ -60,7 +59,7 @@ public ApiResponse() {
6059
* @return the isValid
6160
*/
6261
public Boolean isValid() {
63-
return isValid;
62+
return (null==isValid) ? false : isValid;
6463
}
6564

6665
/**
@@ -102,7 +101,7 @@ public class Validation {
102101
// API host for servicing external validation calls
103102
private static final String API_HOST = DoeServletContextListener.getConfigurationProperty("api.host");
104103
// a JSON mapper
105-
private static final ObjectMapper mapper = new ObjectMapper();
104+
protected static final ObjectMapper mapper = new ObjectMapper();
106105
// static DOI resolution prefix
107106
private static final String DOI_BASE_URL = "https://doi.org/";
108107

src/test/java/gov/osti/connectors/MetadataYamlTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.io.File;
1818
import java.io.FileReader;
1919
import java.text.SimpleDateFormat;
20+
import java.time.ZoneId;
21+
import java.time.format.DateTimeFormatter;
2022
import java.util.Date;
2123
import java.util.List;
2224
import org.junit.After;
@@ -215,10 +217,12 @@ public void testYamlToMetadata() throws Exception {
215217
assertTrue ("Should be DOE", reorg.isDOE());
216218

217219
Date issue_date = metadata.getReleaseDate();
218-
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
219220

220221
assertNotNull("Date is missing", issue_date);
221-
assertEquals ("Date is wrong", "06/02/1999", sdf.format(issue_date));
222+
assertEquals ("Date is wrong", "06/02/1999",
223+
DateTimeFormatter.ofPattern("MM/dd/yyyy")
224+
.withZone(ZoneId.of("UTC"))
225+
.format(issue_date.toInstant()));
222226

223227
log.info("Writing back out:");
224228
log.info(HttpUtil.writeMetadataYaml(metadata));

src/test/java/gov/osti/services/ValidationTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*/
33
package gov.osti.services;
44

5+
import java.io.IOException;
56
import org.junit.After;
67
import org.junit.AfterClass;
78
import org.junit.Before;
@@ -51,6 +52,18 @@ public void testIsValidEmail() {
5152
}
5253
}
5354

55+
/**
56+
* Test for specific failing Boolean conversions in API responses.
57+
*
58+
* @throws IOException on unexpected errors
59+
*/
60+
@Test
61+
public void testApiResponse() throws IOException {
62+
ApiResponse response = Validation.mapper.readValue("{}", ApiResponse.class);
63+
64+
assertFalse ("Empty JSON should be invalid", response.isValid());
65+
}
66+
5467
/**
5568
* Test of isValidUrl method, of class Validation.
5669
*/

0 commit comments

Comments
 (0)