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

This commit is contained in:
jamesagnew 2016-06-24 06:11:00 -04:00
commit bf303507d8
6 changed files with 64 additions and 28 deletions

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.util;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Locale;
public class TestUtil {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestUtil.class);
@ -34,7 +35,6 @@ public class TestUtil {
* tons of memory being used by the end and the JVM crashes in Travis. Manually clearing all of the
* static fields seems to solve this.
*/
@CoverageIgnore
public static void clearAllStaticFieldsForUnitTest() {
Class<?> theType;
@ -64,6 +64,27 @@ public class TestUtil {
}
}
}
/*
* Set some system properties randomly after each test.. this is kind of hackish,
* but it helps us make sure we don't have any tests that depend on a particular
* environment
*/
Locale[] available = { Locale.CANADA, Locale.GERMANY, Locale.TAIWAN };
Locale newLocale = available[(int) (Math.random() * available.length)];
Locale.setDefault(newLocale);
ourLog.info("Tests are running in locale: " + newLocale.getDisplayName());
if (Math.random() < 0.5) {
ourLog.info("Tests are using WINDOWS line endings and ISO-8851-1");
System.setProperty("file.encoding", "ISO-8859-1");
System.setProperty("line.separator", "\r\n");
} else {
ourLog.info("Tests are using UNIX line endings and UTF-8");
System.setProperty("file.encoding", "UTF-8");
System.setProperty("line.separator", "\n");
}
}
}

View File

@ -74,7 +74,7 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
* Constructor
*/
public DecimalType(long theValue) {
setValue(new BigDecimal(theValue));
setValue(theValue);
}
/**
@ -148,21 +148,21 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
* Sets a new value using an integer
*/
public void setValueAsInteger(int theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
/**
* Sets a new value using a long
*/
public void setValue(long theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
/**
* Sets a new value using a double
*/
public void setValue(double theValue) {
setValue(new BigDecimal(theValue));
setValue(BigDecimal.valueOf(theValue));
}
@Override

View File

@ -0,0 +1,29 @@
package ca.uhn.fhir.model;
import static org.junit.Assert.*;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.junit.Test;
public class DecimalTypeTest {
@Test
public void testDoubleValue() {
DecimalType d = new DecimalType(1.2D);
assertEquals("1.2", d.getValueAsString());
d = new DecimalType();
d.setValue(1.2D);
assertEquals("1.2", d.getValueAsString());
d = new DecimalType();
d.setValue(10);
assertEquals("10", d.getValueAsString());
d = new DecimalType();
d.setValue(10L);
assertEquals("10", d.getValueAsString());
}
}

View File

@ -31,7 +31,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
@ -55,6 +54,7 @@ public class CreateDstu3Test {
*/
@Test
public void testCreateWithInvalidContent() throws Exception {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
httpPost.setEntity(new StringEntity("FOO", ContentType.parse("application/xml+fhir; charset=utf-8")));
HttpResponse status = ourClient.execute(httpPost);
@ -65,8 +65,9 @@ public class CreateDstu3Test {
ourLog.info("Response was:\n{}", responseContent);
assertEquals(400, status.getStatusLine().getStatusCode());
String expected = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"Failed to parse request body as XML resource. Error was: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'F' (code 70) in prolog; expected '&lt;'&#xa; at [row,col {unknown-source}]: [1,1]\"/></issue></OperationOutcome>";
assertEquals(expected, responseContent);
assertThat(responseContent, containsString("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\""));
assertThat(responseContent, containsString("Failed to parse request body as XML resource. Error was: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'F'"));
}

View File

@ -20,7 +20,6 @@ import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.util.TestUtil;
public class BaseDateTimeTypeDstu3Test {
private static Locale ourDefaultLocale;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeTypeDstu3Test.class);
private SimpleDateFormat myDateInstantParser;
@ -209,23 +208,4 @@ public class BaseDateTimeTypeDstu3Test {
assertThat(human, containsString("12"));
}
public static void afterClass() {
Locale.setDefault(ourDefaultLocale);
}
@BeforeClass
public static void beforeClass() {
/*
* We cache the default locale, but temporarily set it to a random value during this test. This helps ensure
* that there are no language specific dependencies in the test.
*/
ourDefaultLocale = Locale.getDefault();
Locale[] available = { Locale.CANADA, Locale.GERMANY, Locale.TAIWAN };
Locale newLocale = available[(int) (Math.random() * available.length)];
Locale.setDefault(newLocale);
ourLog.info("Tests are running in locale: " + newLocale.getDisplayName());
}
}

View File

@ -381,6 +381,11 @@
AuthorizationInterceptor can now allow or deny requests to extended
operations (e.g. $everything)
</action>
<action type="fix">
DecimalType used BigDecimal constructor instead of valueOf method to
create a BigDecimal from a double, resulting in weird floating point
conversions. Thanks to Craig McClendon for reporting!
</action>
</release>
<release version="1.5" date="2016-04-20">
<action type="fix" issue="339">