@Test
  public void testExtendedClass() {
    FhirContext ctx = new FhirContext();
    ctx.getResourceDefinition(MyPatient.class);

    RuntimeResourceDefinition patient = ctx.getResourceDefinition("Patient");
    assertEquals(Patient.class, patient.getImplementingClass());

    RuntimeResourceDefinition def = ctx.getResourceDefinition(MyPatient.class);
    RuntimeResourceDefinition baseDef = def.getBaseDefinition();
    assertEquals(Patient.class, baseDef.getImplementingClass());
  }
public class ModelExtensionTest {
  private static final org.slf4j.Logger ourLog =
      org.slf4j.LoggerFactory.getLogger(ModelExtensionTest.class);
  private FhirContext ourCtx = FhirContext.forDstu1();

  @Test
  public void testModelExtension() throws DataFormatException {
    MyOrganization org = new MyOrganization();
    org.getName().setValue("org0");

    MyPatient patient = new MyPatient();
    patient.addIdentifier("foo", "bar");
    patient.getManagingOrganization().setResource(org);

    IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
    String str = p.encodeResourceToString(patient);

    ourLog.info(str);

    MyPatient parsed = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
    assertEquals("foo", parsed.getIdentifierFirstRep().getSystem().getValueAsString());

    //		assertEquals(MyOrganization.class,
    // parsed.getManagingOrganization().getResource().getClass());
    //		MyOrganization parsedOrg = (MyOrganization) parsed.getManagingOrganization().getResource();
    //		assertEquals("arg0", parsedOrg.getName().getValue());
  }

  @AfterClass
  public static void afterClassClearContext() {
    TestUtil.clearAllStaticFieldsForUnitTest();
  }
}
  @Test
  public void testModelExtension() throws DataFormatException {
    MyOrganization org = new MyOrganization();
    org.getName().setValue("org0");

    MyPatient patient = new MyPatient();
    patient.addIdentifier("foo", "bar");
    patient.getManagingOrganization().setResource(org);

    IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
    String str = p.encodeResourceToString(patient);

    ourLog.info(str);

    MyPatient parsed = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
    assertEquals("foo", parsed.getIdentifierFirstRep().getSystem().getValueAsString());

    //		assertEquals(MyOrganization.class,
    // parsed.getManagingOrganization().getResource().getClass());
    //		MyOrganization parsedOrg = (MyOrganization) parsed.getManagingOrganization().getResource();
    //		assertEquals("arg0", parsedOrg.getName().getValue());
  }