ClientTest.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:FHIR-Server 作者:
@Test
public void testUpdateWithVersion() throws Exception {

    Patient patient = new Patient();
    patient.addIdentifier("urn:foo", "123");

    ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
    when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
    when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
    when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8"));
    when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
    when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));

    ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
    MethodOutcome response = client.updatePatient(new IdDt("Patient/100/_history/200"), patient);

    assertEquals(HttpPut.class, capt.getValue().getClass());
    HttpPut post = (HttpPut) capt.getValue();
    assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100"));
    assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient"));
    assertThat(post.getFirstHeader("Content-Location").getValue(), StringEndsWith.endsWith("Patient/100/_history/200"));
    assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue());
    assertEquals("200", response.getId().getVersionIdPart());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号