コード例 #1
0
  @Test
  public void testReturnLinks() throws Exception {
    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");

    CloseableHttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
    assertEquals(10, bundle.getEntries().size());

    Patient p = bundle.getResources(Patient.class).get(0);
    assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
    assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
    assertEquals(
        "http://localhost:" + ourPort + "/Patient/99881",
        bundle.getEntries().get(0).getLinkAlternate().getValue());

    assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
    assertEquals(
        "http://localhost:" + ourPort + "/Patient/99881",
        ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
  }
コード例 #2
0
  /** #149 */
  @Test
  public void testReturnLinksWithAddressStrategy() throws Exception {
    ourServlet.setServerAddressStrategy(
        new HardcodedServerAddressStrategy("https://blah.com/base"));

    HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=findWithLinks");

    CloseableHttpResponse status = ourClient.execute(httpGet);
    String responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);

    ourLog.info(responseContent);

    assertEquals(10, bundle.getEntries().size());
    assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
    assertEquals(
        "https://blah.com/base/Patient?_query=findWithLinks", bundle.getLinkSelf().getValue());

    Patient p = bundle.getResources(Patient.class).get(0);
    assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
    assertEquals("http://foo/Patient?_id=1", bundle.getEntries().get(0).getLinkSearch().getValue());
    assertEquals(
        "https://blah.com/base/Patient/99881",
        bundle.getEntries().get(0).getLinkAlternate().getValue());
    assertEquals("http://foo/Patient?_id=1", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
    assertEquals(
        "https://blah.com/base/Patient/99881", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));

    String linkNext = bundle.getLinkNext().getValue();
    ourLog.info(linkNext);
    assertThat(linkNext, startsWith("https://blah.com/base?_getpages="));

    /*
     * Load the second page
     */
    String urlPart = linkNext.substring(linkNext.indexOf('?'));
    String link = "http://localhost:" + ourPort + urlPart;
    httpGet = new HttpGet(link);

    status = ourClient.execute(httpGet);
    responseContent = IOUtils.toString(status.getEntity().getContent());
    IOUtils.closeQuietly(status.getEntity().getContent());
    assertEquals(200, status.getStatusLine().getStatusCode());
    bundle = ourCtx.newXmlParser().parseBundle(responseContent);

    ourLog.info(responseContent);

    assertEquals(10, bundle.getEntries().size());
    assertEquals("https://blah.com/base", bundle.getLinkBase().getValue());
    assertEquals(linkNext, bundle.getLinkSelf().getValue());

    p = bundle.getResources(Patient.class).get(0);
    assertEquals("AAANamed", p.getIdentifierFirstRep().getValue().getValue());
    assertEquals(
        "http://foo/Patient?_id=11", bundle.getEntries().get(0).getLinkSearch().getValue());
    assertEquals(
        "https://blah.com/base/Patient/998811",
        bundle.getEntries().get(0).getLinkAlternate().getValue());
    assertEquals("http://foo/Patient?_id=11", ResourceMetadataKeyEnum.LINK_SEARCH.get(p));
    assertEquals(
        "https://blah.com/base/Patient/998811", ResourceMetadataKeyEnum.LINK_ALTERNATE.get(p));
  }