Hai Ishara, For your question how should i obtain patient data for the test? In side each testcase at the top of the class there should be a path to .xml file under src/test/resource and execute it do your testcase. eg executeDataSet(xmlfilepath);
Thank you. A.Karesh University of Surrey, UK. On Sun, Mar 25, 2012 at 3:55 PM, ishara premadasa <[email protected]>wrote: > Hi, > > Thank you very much for the guide. I created unit test methods for > PatientSearchCriteria class according to the @should requirement. But > however i have met an issue as i don't have much knowledge about from > where to retrieve data for the test. > > As an example this is the test method i wrote for > prepareCriteria_shouldSearchOnVoidedPatients() method. > > > */** > * @see {@link > org.openmrs.api.db.hibernate.PatientSearchCriteria#prepareCriteria(String, > String, java.util.List, boolean, boolean)} > */ > @Test > @Verifies(value = "should search on voided patients", method = > "prepareCriteria(String, String, List<PatientIdentifierType;>,boolean, > boolean)") > public void prepareCriteria_shouldSearchOnVoidedPatients() { > > SessionFactory sessionFactory = (SessionFactory) > applicationContext.getBean("sessionFactory"); > Session sess = sessionFactory.getCurrentSession(); > Criteria criteria = sess.createCriteria(Patient.class); > > String name = "Alice"; > String identifier = "id"; > List<PatientIdentifierType> identifiertypes = new > ArrayList<PatientIdentifierType>(); > > > PatientSearchCriteria patientSearchCriteria = new > PatientSearchCriteria(sessionFactory, > criteria); // create a patientSearchCriteria object > org.hibernate.Criteria receivedCriteria = > patientSearchCriteria.prepareCriteria(name, identifier, identifiertypes, > true, > true); > > List list = receivedCriteria.list(); > > Iterator itr = list.iterator(); > if (list.size() == 0) { > System.out.println("No Result Found !"); > } > while (itr.hasNext()) { > Object object = (Object) itr.next(); > Patient patient = (Patient) object; > if (patient.getIdentifiers() != null) { > for (PatientIdentifier pi : patient.getIdentifiers()) { > Assert.assertEquals(false, pi.isVoided()); > } > } else {} > } > > }* > > When i run the test it always return that *"No Result Found !" *as the > list of returned patients records is emply. I have created a criteria for > the Patient class however i don't know where it does refer to query Patient > entries. Can you pls help me on how should i obtain patient data for the > test? > > Thank you! > > > On Wed, Mar 21, 2012 at 6:40 PM, Ben Wolfe <[email protected]> wrote: > >> Yes, create the class if it doesn't exist. >> >> Both writing the @should and the associated test method are preferred! :-) >> >> Ben >> >> On Wed, Mar 21, 2012 at 1:24 AM, ishara premadasa >> <[email protected]>wrote: >> >>> Hi devs, >>> >>> I am working on the introductory ticket >>> TRUNK-248<https://tickets.openmrs.org/browse/TRUNK-248>which needs adding >>> @should notations according to code comments. I was >>> trying this with few classes, there are some things i need to clarify. >>> >>> As an example i came across this >>> org.openmrs.api.db.hibernate.PatientSearchCriteria class which has >>> following method. >>> >>> /** >>> * Utility method to add identifier expression to an existing >>> criteria >>> * >>> * @param criteria >>> * @param identifier >>> * @param identifierTypes >>> * @param matchIdentifierExactly >>> */ >>> private void addIdentifierCriterias(Criteria criteria, String >>> identifier, List<PatientIdentifierType> >>> identifierTypes, >>> boolean matchIdentifierExactly) { >>> *// TODO add junit test for searching on voided identifiers* >>> >>> According to the >>> guide<https://wiki.openmrs.org/display/docs/Unit+Testing+With+at-should+Annotation>provided >>> in the ticket, this should be annotated as, >>> >>> /** >>> * Utility method to add identifier expression to an existing >>> criteria >>> * >>> * @param criteria >>> * @param identifier >>> * @param identifierTypes >>> * @param matchIdentifierExactly >>> * *@should fail given null identifier* >>> */ >>> >>> In addition to that it says there must be a method in the test class >>> named *addIdentifierCriterias_shouldFailGivenNullIdentifier()* which >>> address this check. However there is no PatientSearchCriteriaTest class in >>> the project. Do i need to create test classes and methods along with the >>> fix for the error ? or is it only needed to change the code comment and add >>> the annotation without considering modifying the test class method? >>> >>> Thank you very much! >>> Ishara >>> >>> -- >>> *Best Regards.* >>> >>> *Ishara Premadasa,* >>> Final Year Undergraduate, >>> Dept. of Computer Science & Engineering, >>> University of Moratuwa >>> Sri Lanka. >>> http://isharapremadasa.blogspot.com >>> >>> >>> >>> ------------------------------ >>> Click here to >>> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-devel-l>from >>> OpenMRS Developers' mailing list >>> >> >> ------------------------------ >> Click here to >> unsubscribe<[email protected]?body=SIGNOFF%20openmrs-devel-l>from >> OpenMRS Developers' mailing list >> > > > > -- > *Best Regards.* > > *Ishara Premadasa,* > Final Year Undergraduate, > Dept. of Computer Science & Engineering, > University of Moratuwa > Sri Lanka. > http://isharapremadasa.blogspot.com > > > > ------------------------------ > Click here to > unsubscribe<[email protected]?body=SIGNOFF%20openmrs-devel-l>from > OpenMRS Developers' mailing list > _________________________________________ To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to [email protected] with "SIGNOFF openmrs-devel-l" in the body (not the subject) of your e-mail. [mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]

