/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gov.hhs.fha.nhinc.cpp; import gov.hhs.fha.nhinc.mpilib.Identifier; import gov.hhs.fha.nhinc.mpilib.Identifiers; import gov.hhs.fha.nhinc.mpilib.MiniMpi; import gov.hhs.fha.nhinc.mpilib.Patient; import gov.hhs.fha.nhinc.mpilib.PersonName; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.w3c.dom.Document; import static org.junit.Assert.*; /** * * @author svalluripalli */ public class CPPOperationsTest { private static final String orgId = "123"; private static final String patId = "123-123"; public CPPOperationsTest() { } @BeforeClass public static void setUpClass() throws Exception { } @AfterClass public static void tearDownClass() throws Exception { } @Before public void setUp() { } @After public void tearDown() { } @Test public void testSaveCPP() { CPPOperations ops = new CPPOperations(); //ops.saveCPP("123", "123", "asdf"); } @Test public void testUpdateOptInNoMpi() { String xacml = getXMLStringForOptOut(); CPPOperations ops = new CPPOperations(); String ack = ops.updateOptIn(patId, orgId, xacml); assertEquals("Patient Not Found in MPI",ack); } @Test public void testUpdateOptInMpi(){ String xacml = getXMLStringForOptOut(); //removePatient(); createPatient(); CPPOperations ops = new CPPOperations(); String ack = ops.updateOptIn(patId, orgId, xacml); removePatient(); assertEquals("Patient OptInOut Flag Updated Successfully",ack); } @Test public void testUpdateOptInNotifyDocument(){ String xacml = getXMLStringForOptOut(); gov.hhs.fha.nhinc.repository.model.Document doc = new gov.hhs.fha.nhinc.repository.model.Document(); doc.setDocumentUniqueId("12345"); createPatient(); CPPOperations ops = new CPPOperations(); //Commented this line build server will fail...Uncomment to test with Actual Service EntitySubscription... //ops.updateOptInNotifyDocument(patId, orgId, xacml,doc); removePatient(); } private String getXMLStringForOptOut(){ Document doc = null; Identifier id = null; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance( ); DocumentBuilder builder = builderFactory.newDocumentBuilder( ); doc = builder.parse (new org.xml.sax.InputSource ("test/gov/hhs/fha/nhinc/cpp/OptOut.xml")); id = CPPUtils.extractPatientId(doc); boolean opt = CPPUtils.isOptedIn(doc); System.out.println("Opted in status is ----->"+opt); }catch (Exception ex) { assertEquals(1,0); } return CPPUtils.DocumentToString(doc); } private void createPatient(){ Patient p = new Patient(); PersonName name = new PersonName("Test", "Dummy"); p.setName(name); Identifiers ids = new Identifiers(); Identifier id = new Identifier(patId,orgId); ids.add(id); p.setIdentifiers(ids); p.setOptedIn(true); MiniMpi mpi = MiniMpi.GetMpiInstance(); mpi.Reset(); mpi.AddUpdate(p); } private void removePatient(){ Patient p = new Patient(); PersonName name = new PersonName("Test", "Dummy"); p.setName(name); Identifiers ids = new Identifiers(); Identifier id = new Identifier(patId,orgId); ids.add(id); p.setIdentifiers(ids); MiniMpi mpi = MiniMpi.GetMpiInstance(); mpi.Reset(); mpi.Delete(p, orgId); } }