This repository was archived by the owner on Oct 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
main/java/gov/osti/services Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1616import gov .osti .repository .SubversionRepository ;
1717import java .io .IOException ;
1818import java .io .Serializable ;
19- import java .math .BigDecimal ;
2019import java .net .URLEncoder ;
2120import java .util .regex .Matcher ;
2221import 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
Original file line number Diff line number Diff line change 1717import java .io .File ;
1818import java .io .FileReader ;
1919import java .text .SimpleDateFormat ;
20+ import java .time .ZoneId ;
21+ import java .time .format .DateTimeFormatter ;
2022import java .util .Date ;
2123import java .util .List ;
2224import 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 ));
Original file line number Diff line number Diff line change 22 */
33package gov .osti .services ;
44
5+ import java .io .IOException ;
56import org .junit .After ;
67import org .junit .AfterClass ;
78import 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 */
You can’t perform that action at this time.
0 commit comments