Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James Agnew 2014-11-20 16:41:42 -05:00
commit c0d125f288
3 changed files with 32 additions and 15 deletions

View File

@ -30,13 +30,16 @@ import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
*/ */
public class ValidationResult { public class ValidationResult {
private BaseOperationOutcome myOperationOutcome; private BaseOperationOutcome myOperationOutcome;
private boolean isSuccessful;
private ValidationResult(BaseOperationOutcome myOperationOutcome) { private ValidationResult(BaseOperationOutcome myOperationOutcome, boolean isSuccessful) {
this.myOperationOutcome = myOperationOutcome; this.myOperationOutcome = myOperationOutcome;
this.isSuccessful = isSuccessful;
} }
public static ValidationResult valueOf(BaseOperationOutcome myOperationOutcome) { public static ValidationResult valueOf(BaseOperationOutcome myOperationOutcome) {
return new ValidationResult(myOperationOutcome); boolean noIssues = myOperationOutcome == null || myOperationOutcome.getIssue().isEmpty();
return new ValidationResult(myOperationOutcome, noIssues);
} }
public BaseOperationOutcome getOperationOutcome() { public BaseOperationOutcome getOperationOutcome() {
@ -47,6 +50,7 @@ public class ValidationResult {
public String toString() { public String toString() {
return "ValidationResult{" + return "ValidationResult{" +
"myOperationOutcome=" + myOperationOutcome + "myOperationOutcome=" + myOperationOutcome +
", isSuccessful=" + isSuccessful +
", description='" + toDescription() + '\'' + ", description='" + toDescription() + '\'' +
'}'; '}';
} }
@ -67,6 +71,6 @@ public class ValidationResult {
* @return true if the validation was successful * @return true if the validation was successful
*/ */
public boolean isSuccessful() { public boolean isSuccessful() {
return myOperationOutcome == null || myOperationOutcome.getIssue().isEmpty(); return isSuccessful;
} }
} }

View File

@ -1,18 +1,19 @@
package ca.uhn.fhir.model.primitive; package ca.uhn.fhir.model.primitive;
import static org.junit.Assert.*; import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.DataFormatException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.lang3.time.FastDateFormat;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import java.text.SimpleDateFormat;
import ca.uhn.fhir.parser.DataFormatException; import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public class BaseDateTimeDtTest { public class BaseDateTimeDtTest {
private SimpleDateFormat myDateInstantParser; private SimpleDateFormat myDateInstantParser;
@ -39,7 +40,7 @@ public class BaseDateTimeDtTest {
Date instant = myDateInstantParser.parse("2001-02-03 13:01:02.555"); Date instant = myDateInstantParser.parse("2001-02-03 13:01:02.555");
for (FastDateFormat next : BaseDateTimeDt.getFormatters()) { for (FastDateFormat next : BaseDateTimeDt.getFormatters()) {
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("EST")); Calendar cal = Calendar.getInstance();
cal.setTime(instant); cal.setTime(instant);
String value = next.format(cal); String value = next.format(cal);
ourLog.info("String: {}", value); ourLog.info("String: {}", value);

View File

@ -2,7 +2,6 @@ package ca.uhn.fhir.validation;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import org.junit.Test; import org.junit.Test;
import java.util.List; import java.util.List;
@ -45,4 +44,17 @@ public class ValidationResultTest {
assertThat("ValidationResult#toString should contain the issue description", result.toString(), containsString(errorMessage)); assertThat("ValidationResult#toString should contain the issue description", result.toString(), containsString(errorMessage));
} }
/*
Test for https://github.com/jamesagnew/hapi-fhir/issues/51
*/
@Test
public void toString_ShouldNotCauseResultToBecomeFailure() {
OperationOutcome operationOutcome = new OperationOutcome();
ValidationResult result = ValidationResult.valueOf(operationOutcome);
assertEquals(true, result.isSuccessful());
// need to call toString to make sure any unwanted side effects are generated
@SuppressWarnings("UnusedDeclaration") String unused = result.toString();
assertEquals(true, result.isSuccessful());
}
} }