Skip to content

Commit

Permalink
Fixed PIT named testForSubscriberAbsent for MCTS And RCH Beneficiary.
Browse files Browse the repository at this point in the history
  • Loading branch information
atishbeehyv123 committed Dec 24, 2018
1 parent eb27e9b commit ca0ec47
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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<MctsMother> retrieveAllMothers(MctsMotherDataService mctsMotherDataService){

SqlQueryExecution<List<MctsMother>> queryExecution = new SqlQueryExecution<List<MctsMother>>() {

@Override
public String getSqlQuery() {
return "Select * FROM nms_mcts_mothers";
}

@Override
public List<MctsMother> execute(Query query) {
query.setClass(MctsMother.class);
return (List<MctsMother>) query.execute();
}
};
return mctsMotherDataService.executeSQLQuery(queryExecution);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1642,7 +1621,7 @@ public void testForSubscriberAbsent() throws Exception {
status = transactionManager.getTransaction(new DefaultTransactionDefinition());
subscriber = subscriberService.getSubscriber(9439986187L);
assertTrue(subscriber.isEmpty());
List<MctsMother> mothers = mctsMotherDataService.retrieveAll();
List<MctsMother> mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService);
assertEquals(1,mothers.size());

transactionManager.commit(status);
Expand All @@ -1665,6 +1644,8 @@ public void testForSubscriberAbsent() throws Exception {
transactionManager.commit(status);
}



/* Test SubscriberMsisdnTracker in Mother Import
* Ignored due to NullPointerException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -846,7 +847,7 @@ public void testForSubscriberAbsent() throws Exception {
status = transactionManager.getTransaction(new DefaultTransactionDefinition());
subscriber = subscriberService.getSubscriber(9439986187L);
assertTrue(subscriber.isEmpty());
List<MctsMother> mothers = mctsMotherDataService.retrieveAll();
List<MctsMother> mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService);
Assert.assertEquals(1, mothers.size());
transactionManager.commit(status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -488,7 +489,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTable() throws Malfor
assertEquals(1, children.size());
assertEquals("Name 3", children.get(0).getName());

List<MctsMother> mothers = mctsMotherDataService.retrieveAll();
List<MctsMother> 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 {
Expand Down Expand Up @@ -618,7 +619,7 @@ public void shouldPerformImportWithUpdatesAndDeleteInFailedTableOneUpdateDate()
assertEquals(1, children.size());
assertEquals("Name y", children.get(0).getName());

List<MctsMother> mothers = mctsMotherDataService.retrieveAll();
List<MctsMother> mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService);
assertEquals(2, mothers.size()); // 1 record from mother import and 1 from child
assertEquals("Name x", mothers.get(0).getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -259,7 +260,7 @@ public void checkForZeroMother() throws IOException {

List<ChildImportRejection> childImportRejections = childRejectionDataService.retrieveAll();
assertEquals(0, childImportRejections.size());
List<MctsMother> mothers = mctsMotherDataService.retrieveAll();
List<MctsMother> mothers = HelperUtils.retrieveAllMothers(mctsMotherDataService);
assertEquals(0, mothers.size());
}

Expand Down

0 comments on commit ca0ec47

Please sign in to comment.