Here is an example I put together hoping it would cover your question:

A method that takes a TS input:

package hapiexamples;

import ca.uhn.hl7v2.model.DataTypeException;
import ca.uhn.hl7v2.model.v24.datatype.TS;
import ca.uhn.hl7v2.util.DeepCopy;

/**
*
* @author vowlesi
*/
public class TSMethod {
    public static TS doSomethingToTsDatatype(TS inputTs) throws 
DataTypeException {
        TS resultTs = new TS(inputTs.getMessage());
        DeepCopy.copy(inputTs, resultTs);
        return resultTs;
    }
}

A test case for the method:

package hapiexamples;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.v24.datatype.TS;
import ca.uhn.hl7v2.model.v24.message.ADT_A01;
import java.io.IOException;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author vowlesi
*/
public class TSMethodTest {

    public TSMethodTest() {
    }

    @Test
    public void testdoSomethingToTsDatatype() throws HL7Exception, IOException {
        ADT_A01 dummyMessage = new ADT_A01();
        dummyMessage.initQuickstart("ADT", "A01", "T");
        Date now = new Date();
        
dummyMessage.getMSH().getDateTimeOfMessage().getTs1_TimeOfAnEvent().setValue(now);
        TS resultTs = 
TSMethod.doSomethingToTsDatatype(dummyMessage.getMSH().getDateTimeOfMessage());
        assertEquals("result date matches original created value", now, 
resultTs.getTs1_TimeOfAnEvent().getValueAsDate());
    }

}

Hope this helps
Ian


From: John Giotta [mailto:jdgio...@gmail.com]
Sent: Thursday, 28 January 2016 5:34 AM
To: hl7api-devel@lists.sourceforge.net
Subject: [HAPI-devel] Unit Tests for TS DataType

How can write a unit test for a TS datatype?
My method expects a TS object as a parameter.

********************************************************************************
This email, including any attachments sent with it, is confidential and for the 
sole use of the intended recipient(s). This confidentiality is not waived or 
lost, if you receive it and you are not the intended recipient(s), or if it is 
transmitted/received in error.
Any unauthorised use, alteration, disclosure, distribution or review of this 
email is strictly prohibited.  The information contained in this email, 
including any attachment sent with it, may be subject to a statutory duty of 
confidentiality if it relates to health service matters.
If you are not the intended recipient(s), or if you have received this email in 
error, you are asked to immediately notify the sender by telephone collect on 
Australia +61 1800 198 175 or by return email.  You should also delete this 
email, and any copies, from your computer system network and destroy any hard 
copies produced.
If not an intended recipient of this email, you must not copy, distribute or 
take any action(s) that relies on it; any form of disclosure, modification, 
distribution and/or publication of this email is also prohibited.
Although Queensland Health takes all reasonable steps to ensure this email does 
not contain malicious software, Queensland Health does not accept 
responsibility for the consequences if any person's computer inadvertently 
suffers any disruption to services, loss of information, harm or is infected 
with a virus, other malicious computer programme or code that may occur as a 
consequence of receiving this email.
Unless stated otherwise, this email represents only the views of the sender and 
not the views of the Queensland Government.
**********************************************************************************

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to