diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/helperUtils/HelperUtils.java b/testing/src/test/java/org/motechproject/nms/testing/it/helperUtils/HelperUtils.java new file mode 100644 index 000000000..6472ca439 --- /dev/null +++ b/testing/src/test/java/org/motechproject/nms/testing/it/helperUtils/HelperUtils.java @@ -0,0 +1,30 @@ +package org.motechproject.nms.testing.it.helperUtils; + +import org.motechproject.mds.query.SqlQueryExecution; +import org.motechproject.nms.kilkari.domain.MctsMother; +import org.motechproject.nms.kilkari.repository.MctsMotherDataService; + +import javax.jdo.Query; +import java.util.List; + +public class HelperUtils { + + + public static List retrieveAllMothers(MctsMotherDataService mctsMotherDataService){ + + SqlQueryExecution> queryExecution = new SqlQueryExecution>() { + + @Override + public String getSqlQuery() { + return "Select * FROM nms_mcts_mothers"; + } + + @Override + public List execute(Query query) { + query.setClass(MctsMother.class); + return (List) query.execute(); + } + }; + return mctsMotherDataService.executeSQLQuery(queryExecution); + } +} diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/MctsBeneficiaryImportServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/MctsBeneficiaryImportServiceBundleIT.java index 3c7243668..9bc78857f 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/MctsBeneficiaryImportServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/MctsBeneficiaryImportServiceBundleIT.java @@ -14,38 +14,24 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.motechproject.nms.csv.domain.CsvAuditRecord; import org.motechproject.nms.csv.repository.CsvAuditRecordDataService; import org.motechproject.nms.kilkari.domain.*; import org.motechproject.nms.kilkari.repository.*; import org.motechproject.nms.kilkari.service.MctsBeneficiaryImportReaderService; import org.motechproject.nms.kilkari.service.SubscriberService; import org.motechproject.nms.kilkari.service.SubscriptionService; -import org.motechproject.nms.region.domain.Circle; -import org.motechproject.nms.region.domain.District; -import org.motechproject.nms.region.domain.HealthBlock; -import org.motechproject.nms.region.domain.HealthFacility; -import org.motechproject.nms.region.domain.HealthFacilityType; -import org.motechproject.nms.region.domain.HealthSubFacility; -import org.motechproject.nms.region.domain.State; -import org.motechproject.nms.region.domain.Taluka; -import org.motechproject.nms.region.domain.Village; +import org.motechproject.nms.region.domain.*; import org.motechproject.nms.region.repository.CircleDataService; import org.motechproject.nms.region.repository.DistrictDataService; import org.motechproject.nms.region.repository.LanguageDataService; import org.motechproject.nms.region.repository.StateDataService; -import org.motechproject.nms.region.service.DistrictService; -import org.motechproject.nms.region.service.HealthBlockService; -import org.motechproject.nms.region.service.HealthFacilityService; -import org.motechproject.nms.region.service.HealthSubFacilityService; -import org.motechproject.nms.region.service.LanguageService; -import org.motechproject.nms.region.service.TalukaService; -import org.motechproject.nms.region.service.VillageService; +import org.motechproject.nms.region.service.*; import org.motechproject.nms.rejectionhandler.domain.ChildImportRejection; import org.motechproject.nms.rejectionhandler.domain.MotherImportRejection; import org.motechproject.nms.rejectionhandler.repository.ChildRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.MotherRejectionDataService; import org.motechproject.nms.testing.it.api.utils.RequestBuilder; +import org.motechproject.nms.testing.it.helperUtils.HelperUtils; import org.motechproject.nms.testing.it.utils.RegionHelper; import org.motechproject.nms.testing.it.utils.SubscriptionHelper; import org.motechproject.nms.testing.service.TestingService; @@ -73,14 +59,7 @@ import java.util.Set; import static org.junit.Assert.*; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createDistrict; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createHealthBlock; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createHealthFacility; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createHealthFacilityType; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createHealthSubFacility; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createState; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createTaluka; -import static org.motechproject.nms.testing.it.utils.RegionHelper.createVillage; +import static org.motechproject.nms.testing.it.utils.RegionHelper.*; @RunWith(PaxExam.class) @ExamReactorStrategy(PerSuite.class) @@ -1642,7 +1621,7 @@ public void testForSubscriberAbsent() throws Exception { status = transactionManager.getTransaction(new DefaultTransactionDefinition()); subscriber = subscriberService.getSubscriber(9439986187L); assertTrue(subscriber.isEmpty()); - List mothers = mctsMotherDataService.retrieveAll(); + List mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService); assertEquals(1,mothers.size()); transactionManager.commit(status); @@ -1665,6 +1644,8 @@ public void testForSubscriberAbsent() throws Exception { transactionManager.commit(status); } + + /* Test SubscriberMsisdnTracker in Mother Import * Ignored due to NullPointerException */ diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/RchBeneficiaryImportServiceBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/RchBeneficiaryImportServiceBundleIT.java index 1ca14435b..a8f737174 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/RchBeneficiaryImportServiceBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/kilkari/RchBeneficiaryImportServiceBundleIT.java @@ -57,6 +57,7 @@ import org.motechproject.nms.rejectionhandler.domain.MotherImportRejection; import org.motechproject.nms.rejectionhandler.repository.ChildRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.MotherRejectionDataService; +import org.motechproject.nms.testing.it.helperUtils.HelperUtils; import org.motechproject.nms.testing.it.utils.RegionHelper; import org.motechproject.nms.testing.it.utils.SubscriptionHelper; import org.motechproject.nms.testing.service.TestingService; @@ -846,7 +847,7 @@ public void testForSubscriberAbsent() throws Exception { status = transactionManager.getTransaction(new DefaultTransactionDefinition()); subscriber = subscriberService.getSubscriber(9439986187L); assertTrue(subscriber.isEmpty()); - List mothers = mctsMotherDataService.retrieveAll(); + List mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService); Assert.assertEquals(1, mothers.size()); transactionManager.commit(status); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java index 028ce15ba..ac40ef2ce 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/mcts/MctsImportBundleIT.java @@ -34,6 +34,7 @@ import org.motechproject.nms.rejectionhandler.repository.ChildRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.FlwImportRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.MotherRejectionDataService; +import org.motechproject.nms.testing.it.helperUtils.HelperUtils; import org.motechproject.nms.testing.it.mcts.util.*; import org.motechproject.nms.testing.service.TestingService; import org.motechproject.testing.osgi.BasePaxIT; @@ -488,7 +489,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor assertEquals(1, children.size()); assertEquals("Name 3", children.get(0).getName()); - List mothers = mctsMotherDataService.retrieveAll(); + List mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService); assertEquals(2, mothers.size()); // 2 records from mother import and 2 from child assertEquals("Name 3", mothers.get(0).getName()); } finally { @@ -618,7 +619,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate() assertEquals(1, children.size()); assertEquals("Name y", children.get(0).getName()); - List mothers = mctsMotherDataService.retrieveAll(); + List mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService); assertEquals(2, mothers.size()); // 1 record from mother import and 1 from child assertEquals("Name x", mothers.get(0).getName()); diff --git a/testing/src/test/java/org/motechproject/nms/testing/it/rch/RchWebServiceFacadeBundleIT.java b/testing/src/test/java/org/motechproject/nms/testing/it/rch/RchWebServiceFacadeBundleIT.java index eee5bbe60..3eccb45c9 100644 --- a/testing/src/test/java/org/motechproject/nms/testing/it/rch/RchWebServiceFacadeBundleIT.java +++ b/testing/src/test/java/org/motechproject/nms/testing/it/rch/RchWebServiceFacadeBundleIT.java @@ -24,6 +24,7 @@ import org.motechproject.nms.rejectionhandler.repository.ChildRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.FlwImportRejectionDataService; import org.motechproject.nms.rejectionhandler.repository.MotherRejectionDataService; +import org.motechproject.nms.testing.it.helperUtils.HelperUtils; import org.motechproject.nms.testing.it.rch.util.*; import org.motechproject.nms.testing.service.TestingService; import org.motechproject.scheduler.service.MotechSchedulerService; @@ -259,7 +260,7 @@ public void checkForZeroMother() throws IOException { List childImportRejections = childRejectionDataService.retrieveAll(); assertEquals(0, childImportRejections.size()); - List mothers = mctsMotherDataService.retrieveAll(); + List mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService); assertEquals(0, mothers.size()); }