Fix unit tests
This commit is contained in:
parent
1fddb04fb3
commit
80826b62fd
|
@ -168,6 +168,13 @@
|
||||||
<version>0.8</version>
|
<version>0.8</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-all</artifactId>
|
||||||
|
<version>${hamcrest_version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
|
|
|
@ -1,25 +1,32 @@
|
||||||
package ca.uhn.fhir.model.primitive;
|
package ca.uhn.fhir.model.primitive;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.BasePrimitive;
|
import ca.uhn.fhir.model.api.BasePrimitive;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the FHIR ID type. This is the actual resource ID, meaning the ID that
|
||||||
|
* will be used in RESTful URLs, Resource References, etc. to represent a specific
|
||||||
|
* instance of a resource.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||||
|
* limit of 36 characters.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
@DatatypeDef(name = "id")
|
@DatatypeDef(name = "id")
|
||||||
public class IdDt extends BasePrimitive<String> {
|
public class IdDt extends BasePrimitive<String> {
|
||||||
|
|
||||||
private String myValue;
|
private String myValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ID.
|
* Create a new empty ID
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* <b>Description</b>:
|
|
||||||
* A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public IdDt() {
|
public IdDt() {
|
||||||
super();
|
super();
|
||||||
|
@ -33,11 +40,11 @@ public class IdDt extends BasePrimitive<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ID
|
* Create a new ID using a string
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>:
|
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||||
* A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
|
* limit of 36 characters.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
|
@ -48,6 +55,17 @@ public class IdDt extends BasePrimitive<String> {
|
||||||
setValue(theValue);
|
setValue(theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ID, using a BigDecimal input. Uses {@link BigDecimal#toPlainString()} to generate the string representation.
|
||||||
|
*/
|
||||||
|
public IdDt(BigDecimal thePid) {
|
||||||
|
if (thePid != null) {
|
||||||
|
setValue(thePid.toPlainString());
|
||||||
|
} else {
|
||||||
|
setValue(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return myValue;
|
return myValue;
|
||||||
|
@ -62,8 +80,8 @@ public class IdDt extends BasePrimitive<String> {
|
||||||
* Set the value
|
* Set the value
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>:
|
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||||
* A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
|
* limit of 36 characters.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
|
@ -79,8 +97,8 @@ public class IdDt extends BasePrimitive<String> {
|
||||||
* Set the value
|
* Set the value
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Description</b>:
|
* <b>Description</b>: A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length
|
||||||
* A whole number in the range 0 to 2^64-1 (optionally represented in hex), a uuid, an oid, or any other combination of lowercase letters, numerals, "-" and ".", with a length limit of 36 characters.
|
* limit of 36 characters.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* regex: [a-z0-9\-\.]{1,36}
|
* regex: [a-z0-9\-\.]{1,36}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import javax.xml.stream.events.XMLEvent;
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.model.api.BasePrimitive;
|
import ca.uhn.fhir.model.api.BasePrimitive;
|
||||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.SimpleSetter;
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
|
||||||
@DatatypeDef(name = "xhtml")
|
@DatatypeDef(name = "xhtml")
|
||||||
|
@ -23,13 +24,43 @@ public class XhtmlDt extends BasePrimitive<List<XMLEvent>> {
|
||||||
|
|
||||||
private List<XMLEvent> myValue;
|
private List<XMLEvent> myValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public XhtmlDt() {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor which accepts a string code
|
||||||
|
*
|
||||||
|
* @see #setValueAsString(String) for a description of how this value is applied
|
||||||
|
*/
|
||||||
|
@SimpleSetter()
|
||||||
|
public XhtmlDt(@SimpleSetter.Parameter(name = "theTextDiv") String theTextDiv) {
|
||||||
|
setValueAsString(theTextDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a textual DIV and parses it into XHTML events which are stored internally.
|
||||||
|
* <p>
|
||||||
|
* <b>Formatting note:</b> The text will be trimmed {@link String#trim()}. If the text does not start with
|
||||||
|
* an HTML tag (generally this would be a div tag), a div tag will be automatically
|
||||||
|
* placed surrounding the text.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setValueAsString(String theValue) throws DataFormatException {
|
public void setValueAsString(String theValue) throws DataFormatException {
|
||||||
if (theValue == null) {
|
if (theValue == null) {
|
||||||
myValue = null;
|
myValue = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String val = "<a>" + theValue + "</a>";
|
|
||||||
|
String val = theValue.trim();
|
||||||
|
if (!val.startsWith("<")) {
|
||||||
|
val = "<div>" + val + "</div>";
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ArrayList<XMLEvent> value = new ArrayList<XMLEvent>();
|
ArrayList<XMLEvent> value = new ArrayList<XMLEvent>();
|
||||||
XMLEventReader er = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(val));
|
XMLEventReader er = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(val));
|
||||||
|
|
|
@ -462,7 +462,8 @@ public class JsonParser extends BaseParser implements IParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!haveContent) {
|
if (!haveContent) {
|
||||||
theEventWriter.writeEnd();
|
// theEventWriter.writeEnd();
|
||||||
|
theEventWriter.flush(); // TODO: remove
|
||||||
theEventWriter.writeNull();
|
theEventWriter.writeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -19,7 +18,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hamcrest.core.IsNot;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
|
@ -37,8 +35,8 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.MethodNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.MethodNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
|
||||||
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
|
||||||
|
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
||||||
|
|
||||||
public abstract class RestfulServer extends HttpServlet {
|
public abstract class RestfulServer extends HttpServlet {
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.parser;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -34,6 +35,8 @@ public class JsonParserTest {
|
||||||
UndeclaredExtension undeclaredExtension = undeclaredExtensions.get(0);
|
UndeclaredExtension undeclaredExtension = undeclaredExtensions.get(0);
|
||||||
assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());
|
assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());
|
||||||
|
|
||||||
|
ctx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out));
|
||||||
|
|
||||||
String encoded = ctx.newJsonParser().encodeResourceToString(obs);
|
String encoded = ctx.newJsonParser().encodeResourceToString(obs);
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
|
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -31,6 +31,7 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven_javadoc_plugin_version>2.9.1</maven_javadoc_plugin_version>
|
<maven_javadoc_plugin_version>2.9.1</maven_javadoc_plugin_version>
|
||||||
<slf4j_version>1.6.6</slf4j_version>
|
<slf4j_version>1.6.6</slf4j_version>
|
||||||
|
<hamcrest_version>1.3</hamcrest_version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
Loading…
Reference in New Issue