Merge branch 'master' of github.com:jamesagnew/hapi-fhir
This commit is contained in:
commit
bf303507d8
|
@ -23,6 +23,7 @@ package ca.uhn.fhir.util;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class TestUtil {
|
public class TestUtil {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestUtil.class);
|
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
|
* 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.
|
* static fields seems to solve this.
|
||||||
*/
|
*/
|
||||||
@CoverageIgnore
|
|
||||||
public static void clearAllStaticFieldsForUnitTest() {
|
public static void clearAllStaticFieldsForUnitTest() {
|
||||||
|
|
||||||
Class<?> theType;
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public DecimalType(long theValue) {
|
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
|
* Sets a new value using an integer
|
||||||
*/
|
*/
|
||||||
public void setValueAsInteger(int theValue) {
|
public void setValueAsInteger(int theValue) {
|
||||||
setValue(new BigDecimal(theValue));
|
setValue(BigDecimal.valueOf(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new value using a long
|
* Sets a new value using a long
|
||||||
*/
|
*/
|
||||||
public void setValue(long theValue) {
|
public void setValue(long theValue) {
|
||||||
setValue(new BigDecimal(theValue));
|
setValue(BigDecimal.valueOf(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new value using a double
|
* Sets a new value using a double
|
||||||
*/
|
*/
|
||||||
public void setValue(double theValue) {
|
public void setValue(double theValue) {
|
||||||
setValue(new BigDecimal(theValue));
|
setValue(BigDecimal.valueOf(theValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,7 +31,6 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
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.Create;
|
||||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||||
import ca.uhn.fhir.rest.annotation.Read;
|
import ca.uhn.fhir.rest.annotation.Read;
|
||||||
|
@ -55,6 +54,7 @@ public class CreateDstu3Test {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateWithInvalidContent() throws Exception {
|
public void testCreateWithInvalidContent() throws Exception {
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
|
||||||
httpPost.setEntity(new StringEntity("FOO", ContentType.parse("application/xml+fhir; charset=utf-8")));
|
httpPost.setEntity(new StringEntity("FOO", ContentType.parse("application/xml+fhir; charset=utf-8")));
|
||||||
HttpResponse status = ourClient.execute(httpPost);
|
HttpResponse status = ourClient.execute(httpPost);
|
||||||
|
@ -65,8 +65,9 @@ public class CreateDstu3Test {
|
||||||
ourLog.info("Response was:\n{}", responseContent);
|
ourLog.info("Response was:\n{}", responseContent);
|
||||||
|
|
||||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
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 '<'
 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'"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import ca.uhn.fhir.parser.DataFormatException;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
|
||||||
public class BaseDateTimeTypeDstu3Test {
|
public class BaseDateTimeTypeDstu3Test {
|
||||||
private static Locale ourDefaultLocale;
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeTypeDstu3Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeTypeDstu3Test.class);
|
||||||
private SimpleDateFormat myDateInstantParser;
|
private SimpleDateFormat myDateInstantParser;
|
||||||
|
|
||||||
|
@ -209,23 +208,4 @@ public class BaseDateTimeTypeDstu3Test {
|
||||||
assertThat(human, containsString("12"));
|
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,6 +381,11 @@
|
||||||
AuthorizationInterceptor can now allow or deny requests to extended
|
AuthorizationInterceptor can now allow or deny requests to extended
|
||||||
operations (e.g. $everything)
|
operations (e.g. $everything)
|
||||||
</action>
|
</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>
|
||||||
<release version="1.5" date="2016-04-20">
|
<release version="1.5" date="2016-04-20">
|
||||||
<action type="fix" issue="339">
|
<action type="fix" issue="339">
|
||||||
|
|
Loading…
Reference in New Issue