@Search(queryName = "declaredExtInclude")
    public List<ExtPatient> declaredExtInclude() {
      Organization o1 = new Organization();
      o1.getNameElement().setValue("o1");
      o1.setId("o1");

      Organization o2 = new Organization();
      o2.getNameElement().setValue("o2");
      o2.setId("o2");
      o1.getPartOf().setResource(o2);

      ExtPatient p1 = new ExtPatient();
      p1.setId("p1");
      p1.addIdentifier().setValue("p1");
      p1.getSecondOrg().setResource(o1);

      ExtPatient p2 = new ExtPatient();
      p2.setId("p2");
      p2.addIdentifier().setValue("p2");
      p2.getSecondOrg().setResource(o1);

      return Arrays.asList(p1, p2);
    }
  @Test
  public void testView() {

    ExtPatient src = new ExtPatient();
    src.addIdentifier("urn:sys", "id1");
    src.addIdentifier("urn:sys", "id2");
    src.getExt().setValue(100);
    src.getModExt().setValue(200);

    String enc = ourCtx.newXmlParser().encodeResourceToString(src);
    IParser parser = ourCtx.newXmlParser();
    Patient nonExt = parser.parseResource(Patient.class, enc);

    assertEquals(Patient.class, nonExt.getClass());
    assertEquals("urn:sys", nonExt.getIdentifier().get(0).getSystem().getValueAsString());
    assertEquals("id1", nonExt.getIdentifier().get(0).getValue().getValue());
    assertEquals("urn:sys", nonExt.getIdentifier().get(1).getSystem().getValueAsString());
    assertEquals("id2", nonExt.getIdentifier().get(1).getValue().getValueAsString());

    List<ExtensionDt> ext = nonExt.getUndeclaredExtensionsByUrl("urn:ext");
    assertEquals(1, ext.size());
    assertEquals("urn:ext", ext.get(0).getUrlAsString());
    assertEquals(IntegerDt.class, ext.get(0).getValueAsPrimitive().getClass());
    assertEquals("100", ext.get(0).getValueAsPrimitive().getValueAsString());

    List<ExtensionDt> modExt = nonExt.getUndeclaredExtensionsByUrl("urn:modExt");
    assertEquals(1, modExt.size());
    assertEquals("urn:modExt", modExt.get(0).getUrlAsString());
    assertEquals(IntegerDt.class, modExt.get(0).getValueAsPrimitive().getClass());
    assertEquals("200", modExt.get(0).getValueAsPrimitive().getValueAsString());

    ExtPatient va = ourCtx.newViewGenerator().newView(nonExt, ExtPatient.class);
    assertEquals("urn:sys", va.getIdentifier().get(0).getSystem().getValueAsString());
    assertEquals("id1", va.getIdentifier().get(0).getValue().getValue());
    assertEquals("urn:sys", va.getIdentifier().get(1).getSystem().getValueAsString());
    assertEquals("id2", va.getIdentifier().get(1).getValue().getValueAsString());
    assertEquals(100, va.getExt().getValue().intValue());
    assertEquals(200, va.getModExt().getValue().intValue());
    assertEquals(0, va.getAllUndeclaredExtensions().size());
  }