mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-25 01:18:37 +00:00
Add tests
This commit is contained in:
parent
05467992e5
commit
73121e222c
@ -1699,10 +1699,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
||||
IPrimitiveType<?> divInstance = (IPrimitiveType<?>) divElement.newInstance();
|
||||
try {
|
||||
divInstance.setValueAsString(IOUtils.toString(theResponseReader));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidResponseException(400, "Failed to process HTML response from server", e);
|
||||
} catch (IOException e) {
|
||||
throw new InvalidResponseException(400, "Failed to process HTML response from server", e);
|
||||
} catch (Exception e) {
|
||||
throw new InvalidResponseException(400, "Failed to process HTML response from server: " + e.getMessage(), e);
|
||||
}
|
||||
divChild.getMutator().addValue(textInstance, divInstance);
|
||||
return (T) instance;
|
||||
|
@ -60,7 +60,10 @@ import ca.uhn.fhir.validation.ValidationSupportChain;
|
||||
|
||||
public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResourceDao<T> {
|
||||
|
||||
@Autowired
|
||||
/**
|
||||
* TODO: set this to required after the next release
|
||||
*/
|
||||
@Autowired(required=false)
|
||||
@Qualifier("myJpaValidationSupportDstu2")
|
||||
private IValidationSupport myJpaValidationSupport;
|
||||
|
||||
|
@ -4,9 +4,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.either;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -62,6 +60,7 @@ import ca.uhn.fhir.parser.XmlParserDstu2Test;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
@ -1265,6 +1264,33 @@ public class GenericClientDstu2Test {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadWithSummaryInvalid() throws Exception {
|
||||
String msg = "<>>>><<<<>";
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_HTML + "; charset=UTF-8"));
|
||||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
try {
|
||||
client.read()
|
||||
.resource(Patient.class)
|
||||
.withId("123")
|
||||
.summaryMode(SummaryEnum.TEXT)
|
||||
.execute();
|
||||
fail();
|
||||
} catch (InvalidResponseException e) {
|
||||
assertThat(e.getMessage(), containsString("String does not appear to be valid"));
|
||||
}
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadWithSummaryParamHtml() throws Exception {
|
||||
String msg = "<div>HELP IM A DIV</div>";
|
||||
|
@ -1,6 +1,6 @@
|
||||
package ca.uhn.fhir.validation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.ValueSet;
|
||||
@ -15,7 +15,12 @@ public class ValidationSupportChain implements IValidationSupport {
|
||||
private List<IValidationSupport> myChain;
|
||||
|
||||
public ValidationSupportChain(IValidationSupport... theValidationSupportModules) {
|
||||
myChain = Arrays.asList(theValidationSupportModules);
|
||||
myChain = new ArrayList<IValidationSupport>();
|
||||
for (IValidationSupport next : theValidationSupportModules) {
|
||||
if (next != null) {
|
||||
myChain.add(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user