Object Creation during testing

If I need to create an object (in this case a microchip) for testing

the current test uses 

protected IMObject create(String shortName) {
    IMObject object = service.create(shortName);
    assertNotNull(object);
    return object;
}

to create the object however the new archetype uses a local lookup for the implant site.  This causes a 

JXPathInvalidAccessException: Cannot set property: /implantSite - no such property

I assume I will need to create a new function 

PatientTestHelper.createMicrochip()

rather than using a default constructor pattern.

<archetypes>
    <archetype name="entityIdentity.microchip.1.0"
               latest="true" primary="false"
               type="org.openvpms.component.business.domain.im.common.EntityIdentity" displayName="Microchip">
        <node name="id" path="/id" type="java.lang.Long" hidden="true" readOnly="true"/>
        <node name="microchip" path="/identity" type="java.lang.String"
              minCardinality="1" maxlength="15"/>
        <node name="name" type="java.lang.String" path="/name"
              hidden="true" minCardinality="1" derived="true"
              derivedValue="/identity"/>
        <node name="description" type="java.lang.String"
              path="/description" minCardinality="0"/>
        <node name="implantSite" defaultValue="DORSAL_NECK" displayName="Implant Site" type="java.lang.String"
              path="/implantSite" minCardinality="0">
            <assertion name="lookup.local">
                <propertyList name="entries">
                    <property name="DORSAL_NECK" value="Dorsal Surface of Neck between Shoulders"/>
                    <property name="LEFT_SHOULDER" value="Left Shoulder / Neck"/>
                    <property name="RIGHT_SHOULDER" value="Right Shoulder / Neck Region"/>
                    <property name="VENTRAL_NECK" value="Ventral Area of Neck"/>
            </propertyList>
            </assertion>
        </node>
        <node name="implantDate" displayName="Implant Date or Scan Date" path="/startTime" type="java.util.Date"
              defaultValue="java.util.Date.new()" minCardinality="0"/>
    </archetype>
</archetypes>

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Object Creation during testing

Any node that isn't a field in the class needs to be stored in the details map. You need to use:

       <node name="implantSite" defaultValue="DORSAL_NECK" displayName="Implant Site" type="java.lang.String"
              path="/details/implantSite" minCardinality="0">
            <assertion name="lookup.local">
                <propertyList name="entries">
                    <property name="DORSAL_NECK" value="Dorsal Surface of Neck between Shoulders"/>
                    <property name="LEFT_SHOULDER" value="Left Shoulder / Neck"/>
                    <property name="RIGHT_SHOULDER" value="Right Shoulder / Neck Region"/>
                    <property name="VENTRAL_NECK" value="Ventral Area of Neck"/>
            </propertyList>
            </assertion>
        </node>
        <node name="/details/implantDate" displayName="Implant Date or Scan Date" path="/startTime" type="java.util.Date"
              defaultValue="java.util.Date.new()" minCardinality="0"/>

You can then access as follows:

IMObject microchip = create("entityIdentity.microchip");
IMObjectBean bean = new IMObjectBean(microchip);
bean.setValue("implantSite", "VENTRAL_NECK");
bean.setValue("implantDate", new Date());
Syndicate content