Just some cleanup

This commit is contained in:
jamesagnew 2016-02-28 18:25:20 -05:00
parent b27d2776f1
commit d8c571dfdc
4 changed files with 63 additions and 66 deletions

View File

@ -547,7 +547,6 @@ public abstract class BaseParser implements IParser {
return parseTagList(new StringReader(theString));
}
@SuppressWarnings("cast")
protected List<? extends IBase> preProcessValues(BaseRuntimeChildDefinition metaChildUncast, IBaseResource theResource, List<? extends IBase> theValues) {
if (myContext.getVersion().getVersion().isRi()) {

View File

@ -73,7 +73,7 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding
}
@Override
public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException {
public IBundleProvider invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException {
IBaseResource conf = (IBaseResource) invokeServerMethod(theServer, theRequest, theMethodParams);
return new SimpleBundleProvider(conf);
}

View File

@ -286,7 +286,6 @@ public class RestfulServerUtils {
float q = 1.0f;
EncodingEnum encoding;
boolean pretty = false;
if (endSpaceIndex == -1) {
if (startSpaceIndex == 0) {
encoding = Constants.FORMAT_VAL_TO_ENCODING.get(nextToken);
@ -684,6 +683,19 @@ public class RestfulServerUtils {
// return count;
// }
public static Integer tryToExtractNamedParameter(RequestDetails theRequest, String theParamName) {
String[] retVal = theRequest.getParameters().get(theParamName);
if (retVal == null) {
return null;
}
try {
return Integer.parseInt(retVal[0]);
} catch (NumberFormatException e) {
ourLog.debug("Failed to parse {} value '{}': {}", new Object[] { theParamName, retVal[0], e });
return null;
}
}
public static void validateResourceListNotNull(List<? extends IBaseResource> theResourceList) {
if (theResourceList == null) {
throw new InternalErrorException("IBundleProvider returned a null list of resources - This is not allowed");
@ -698,17 +710,4 @@ public class RestfulServerUtils {
}
}
public static Integer tryToExtractNamedParameter(RequestDetails theRequest, String theParamName) {
String[] retVal = theRequest.getParameters().get(theParamName);
if (retVal == null) {
return null;
}
try {
return Integer.parseInt(retVal[0]);
} catch (NumberFormatException e) {
ourLog.debug("Failed to parse {} value '{}': {}", new Object[] { theParamName, retVal[0], e });
return null;
}
}
}

View File

@ -36,13 +36,60 @@ public class ReadDstu2Test {
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu2();
private static boolean ourInitializeProfileList;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadDstu2Test.class);
private static int ourPort;
private static Server ourServer;
private static RestfulServer ourServlet;
private static boolean ourInitializeProfileList;
@Before
public void before() {
ourServlet.setAddProfileTag(AddProfileTagEnum.NEVER);
ourInitializeProfileList = false;
}
/**
* See #302
*/
@Test
public void testAddProfile() throws Exception {
ourServlet.setAddProfileTag(AddProfileTagEnum.ALWAYS);
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123&_format=xml");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(responseContent, containsString("p1ReadValue"));
assertThat(responseContent, containsString("p1ReadId"));
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"p1ReadId\"/><meta><profile value=\"http://foo_profile\"/></meta><identifier><value value=\"p1ReadValue\"/></identifier></Patient>", responseContent);
ourLog.info(responseContent);
}
/**
* See #302
*/
@Test
public void testAddProfileToExistingList() throws Exception {
ourServlet.setAddProfileTag(AddProfileTagEnum.ALWAYS);
ourInitializeProfileList = true;
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123&_format=xml");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(responseContent, containsString("p1ReadValue"));
assertThat(responseContent, containsString("p1ReadId"));
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"p1ReadId\"/><meta><profile value=\"http://foo\"/><profile value=\"http://foo_profile\"/></meta><identifier><value value=\"p1ReadValue\"/></identifier></Patient>", responseContent);
ourLog.info(responseContent);
}
/**
* In DSTU2+ the resource ID appears in the resource body
*/
@ -79,54 +126,6 @@ public class ReadDstu2Test {
ourLog.info(responseContent);
}
@Before
public void before() {
ourServlet.setAddProfileTag(AddProfileTagEnum.NEVER);
ourInitializeProfileList = false;
}
/**
* See #302
*/
@Test
public void testAddProfile() throws Exception {
ourServlet.setAddProfileTag(AddProfileTagEnum.ALWAYS);
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123&_format=xml");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(responseContent, containsString("p1ReadValue"));
assertThat(responseContent, containsString("p1ReadId"));
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"p1ReadId\"/><meta><profile value=\"http://foo_profile\"/></meta><identifier><value value=\"p1ReadValue\"/></identifier></Patient>", responseContent);
ourLog.info(responseContent);
}
/**
* See #302
*/
@Test
public void testAddProfileToExistingList() throws Exception {
ourServlet.setAddProfileTag(AddProfileTagEnum.ALWAYS);
ourInitializeProfileList = true;
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123&_format=xml");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
assertThat(responseContent, containsString("p1ReadValue"));
assertThat(responseContent, containsString("p1ReadId"));
assertEquals("<Patient xmlns=\"http://hl7.org/fhir\"><id value=\"p1ReadId\"/><meta><profile value=\"http://foo\"/><profile value=\"http://foo_profile\"/></meta><identifier><value value=\"p1ReadValue\"/></identifier></Patient>", responseContent);
ourLog.info(responseContent);
}
@AfterClass
public static void afterClass() throws Exception {
ourServer.stop();