@Test
  public void testUpdateMsisdnNumberAlreadyInUse() throws Exception {
    Long firstMsisdn = subscriptionHelper.makeNumber();
    Long secondMsisdn = subscriptionHelper.makeNumber();

    // create two child subscriptions with different MSISDNs
    Subscription firstSubscription =
        subscriptionHelper.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now(),
            SubscriptionPackType.CHILD,
            firstMsisdn);
    String firstChildId = "0123456789";
    firstSubscription.getSubscriber().setChild(new MctsChild(firstChildId));
    subscriberDataService.update(firstSubscription.getSubscriber());

    Subscription secondSubscription =
        subscriptionHelper.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now(),
            SubscriptionPackType.CHILD,
            secondMsisdn);
    String secondChildId = "9123456789";
    secondSubscription.getSubscriber().setChild(new MctsChild(secondChildId));
    subscriberDataService.update(secondSubscription.getSubscriber());

    // try to set the second child's MSISDN to the same number as the first child's MSISDN
    Reader reader =
        createUpdateReaderWithHeaders("1," + secondChildId + ",,,,,,,,,,,,," + firstMsisdn);
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    List<SubscriptionError> errors = subscriptionErrorDataService.findByContactNumber(firstMsisdn);
    assertEquals(1, errors.size());
  }
Esempio n. 2
0
  @Before
  public void doTheNeedful() {

    testingService.clearDatabase();

    rh =
        new RegionHelper(
            languageDataService,
            circleDataService,
            stateDataService,
            districtDataService,
            districtService);

    sh =
        new SubscriptionHelper(
            subscriptionService,
            subscriberDataService,
            subscriptionPackDataService,
            languageDataService,
            circleDataService,
            stateDataService,
            districtDataService,
            districtService);

    sh.childPack();
    sh.pregnancyPack();
    csrService.buildMessageDurationCache();
  }
  @Test
  public void testUpdateDOB() throws Exception {
    createLocationData();

    Long msisdn = subscriptionHelper.makeNumber();
    String childId = "0123456789";
    DateTime originalDOB = DateTime.now();
    DateTime updatedDOB = originalDOB.minusDays(100);

    subscriptionHelper.mksub(
        SubscriptionOrigin.MCTS_IMPORT, originalDOB, SubscriptionPackType.CHILD, msisdn);
    Subscriber subscriber = subscriberDataService.findByCallingNumber(msisdn);
    subscriber.setDateOfBirth(originalDOB);
    MctsChild child = new MctsChild(childId);
    child.setState(stateDataService.findByCode(21L));
    child.setDistrict(districtService.findByStateAndCode(child.getState(), 3L));
    subscriber.setChild(child);
    subscriberDataService.update(subscriber);

    // this updates the db with the new data (DOB)
    Reader reader =
        createUpdateReaderWithHeaders(
            "1," + childId + ",," + getDateString(updatedDOB) + ",,,,,,,,,,,");
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    // This query should return the updated subscriber information (but it doesn't...causing the
    // assert to fail)
    Subscriber updatedSubscriber = subscriberDataService.findByCallingNumber(msisdn);
    assertEquals(getDateString(updatedDOB), getDateString(updatedSubscriber.getDateOfBirth()));
    Subscription updatedSubscription =
        updatedSubscriber.getActiveAndPendingSubscriptions().iterator().next();
    assertEquals(getDateString(updatedDOB), getDateString(updatedSubscription.getStartDate()));
    assertEquals(SubscriptionStatus.ACTIVE, updatedSubscription.getStatus());
  }
Esempio n. 4
0
  /**
   * To verify that beneficiary(via mcts import) will be deactivated if he/she has MSISDN number
   * added to the DND database.
   */
  @Test
  public void verifyFT177() {

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now().minusDays(14));

    CallSummaryRecordDto csr =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), "11112233445566"),
            subscription.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(subscription, 0),
            sh.getWeekId(subscription, 0),
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.REJECTED,
            makeStatsMap(StatusCode.OBD_DNIS_IN_DND, 3),
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // verify that subscription created via MCTS-import is still Deactivated with reason "do not
    // disturb"
    subscription = subscriptionDataService.findBySubscriptionId(subscription.getSubscriptionId());
    assertEquals(SubscriptionStatus.DEACTIVATED, subscription.getStatus());
    assertEquals(DeactivationReason.DO_NOT_DISTURB, subscription.getDeactivationReason());
  }
  @Test
  public void testUpdateLMP() throws Exception {
    createLocationData();

    Long msisdn = subscriptionHelper.makeNumber();
    String motherId = "0123456789";
    DateTime originalLMP = DateTime.now().minusDays(100);
    DateTime updatedLMP = originalLMP.minusDays(200);

    subscriptionHelper.mksub(
        SubscriptionOrigin.MCTS_IMPORT, originalLMP, SubscriptionPackType.PREGNANCY, msisdn);
    Subscriber subscriber = subscriberDataService.findByCallingNumber(msisdn);
    subscriber.setLastMenstrualPeriod(originalLMP);
    MctsMother mother = new MctsMother(motherId);
    mother.setState(stateDataService.findByCode(21L));
    mother.setDistrict(districtService.findByStateAndCode(mother.getState(), 3L));
    subscriber.setMother(mother);
    subscriberDataService.update(subscriber);

    Reader reader =
        createUpdateReaderWithHeaders(
            "1," + motherId + ",,," + getDateString(updatedLMP) + ",,,,,,,,,,");
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    Subscriber updatedSubscriber = subscriberDataService.findByCallingNumber(msisdn);
    assertEquals(
        getDateString(updatedLMP), getDateString(updatedSubscriber.getLastMenstrualPeriod()));
    Subscription updatedSubscription =
        updatedSubscriber.getActiveAndPendingSubscriptions().iterator().next();
    assertEquals(
        getDateString(updatedLMP.plusDays(90)), getDateString(updatedSubscription.getStartDate()));
    assertEquals(SubscriptionStatus.ACTIVE, updatedSubscription.getStatus());
  }
Esempio n. 6
0
  /*
   * NMS_FT_163
   * To verify pregnancyPack Pack created via IVR, shouldn't get deactivated due to reason DND.
   */
  @Test
  public void verifyFT163() {

    Subscription subscription2 = sh.mksub(SubscriptionOrigin.IVR, DateTime.now().minusDays(14));

    CallSummaryRecordDto csr =
        new CallSummaryRecordDto(
            new RequestId(subscription2.getSubscriptionId(), "11112233445566"),
            subscription2.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(subscription2, 0),
            sh.getWeekId(subscription2, 0),
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.REJECTED,
            makeStatsMap(StatusCode.OBD_DNIS_IN_DND, 3),
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // verify that subscription created via IVR is still Active
    subscription2 = subscriptionDataService.findBySubscriptionId(subscription2.getSubscriptionId());
    assertEquals(SubscriptionStatus.ACTIVE, subscription2.getStatus());
  }
Esempio n. 7
0
  /**
   * To verify that pregnancyPack beneficiary should not be deactivated if the error “user number
   * does not exist” is not received for all failed delivery attempts during a scheduling period for
   * a message.
   */
  @Test
  public void verifyFT189() {

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.PREGNANCY);

    CallSummaryRecordDto csr =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), "11112233445566"),
            subscription.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(subscription, 0),
            sh.getWeekId(subscription, 0),
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_SWITCHEDOFF, 3),
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // verify that subscription is still Active
    subscription = subscriptionDataService.findBySubscriptionId(subscription.getSubscriptionId());
    assertEquals(SubscriptionStatus.ACTIVE, subscription.getStatus());

    // verify that call is rescheduled for next retry.
    assertEquals(1, callRetryDataService.count());

    List<CallRetry> retries = callRetryDataService.retrieveAll();

    assertEquals(subscription.getSubscriptionId(), retries.get(0).getSubscriptionId());
    assertEquals(CallStage.RETRY_1, retries.get(0).getCallStage());
    assertEquals(DayOfTheWeek.today().nextDay(), retries.get(0).getDayOfTheWeek());

    csr =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), "11112233445566"),
            subscription.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(subscription, 0),
            sh.getWeekId(subscription, 0),
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_INVALIDNUMBER, 3),
            0,
            3);

    eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // verify that subscription is still Active, it is not deactivated because call was not failed
    // due to invalid number for all retries.
    subscription = subscriptionDataService.findBySubscriptionId(subscription.getSubscriptionId());
    assertEquals(SubscriptionStatus.ACTIVE, subscription.getStatus());
  }
Esempio n. 8
0
  @Test
  public void verifyFT141() {

    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    // To check that NMS shall retry OBD message for which delivery fails for the first time with
    // two message per
    // week configuration.

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.PREGNANCY);
    String contentFileName = sh.getContentMessageFile(subscription, 0);

    csrDataService.create(
        new CallSummaryRecord(
            new RequestId(subscription.getSubscriptionId(), "11112233445566").toString(),
            subscription.getSubscriber().getCallingNumber(),
            "w1_1.wav",
            "w1_1",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_BUSY, 1),
            0,
            10,
            3));
    Map<Integer, Integer> callStats = new HashMap<>();
    callStats.put(StatusCode.OBD_FAILED_BUSY.getValue(), 1);
    CallSummaryRecordDto record =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), timestamp),
            subscription.getSubscriber().getCallingNumber(),
            contentFileName,
            "XXX",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            callStats,
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, record);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    assertEquals(1, callRetryDataService.count());

    List<CallRetry> retries = callRetryDataService.retrieveAll();

    assertEquals(subscription.getSubscriptionId(), retries.get(0).getSubscriptionId());
    assertEquals(CallStage.RETRY_1, retries.get(0).getCallStage());
    assertEquals(DayOfTheWeek.today().nextDay(), retries.get(0).getDayOfTheWeek());
  }
Esempio n. 9
0
  @Test
  public void verifyFT144() {

    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    // To check that NMS shall retry the OBD messages which failed as IVR did not attempt OBD for
    // those messages.

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.CHILD);
    String contentFileName = sh.getContentMessageFile(subscription, 0);
    CallRetry retry =
        callRetryDataService.create(
            new CallRetry(
                subscription.getSubscriptionId(),
                subscription.getSubscriber().getCallingNumber(),
                DayOfTheWeek.today(),
                CallStage.RETRY_1,
                contentFileName,
                "XXX",
                "XXX",
                "XX",
                SubscriptionOrigin.MCTS_IMPORT));

    Map<Integer, Integer> callStats = new HashMap<>();
    callStats.put(StatusCode.OBD_FAILED_NOATTEMPT.getValue(), 1);
    CallSummaryRecordDto record =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), timestamp),
            subscription.getSubscriber().getCallingNumber(),
            contentFileName,
            "XXX",
            "XXX",
            "XX",
            FinalCallStatus.FAILED,
            callStats,
            0,
            1);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, record);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // There should be one calls to retry since the one above was the last failed with No attempt
    assertEquals(1, callRetryDataService.count());

    List<CallRetry> retries = callRetryDataService.retrieveAll();

    assertEquals(subscription.getSubscriptionId(), retries.get(0).getSubscriptionId());
    assertEquals(CallStage.RETRY_2, retries.get(0).getCallStage());
    assertEquals(DayOfTheWeek.today().nextDay(), retries.get(0).getDayOfTheWeek());
  }
Esempio n. 10
0
  /**
   * To check that NMS shall retry OBD message for which second OBD retry fails with single message
   * per week configuration.
   */
  @Test
  public void verifyFT139() {
    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    // Create a record in the CallRetry table marked as "retry_2" and verify it is updated as
    // "retry_last" in
    // CallRetry table

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now().minusDays(3));
    String contentFileName = sh.getContentMessageFile(subscription, 0);
    CallRetry retry =
        callRetryDataService.create(
            new CallRetry(
                subscription.getSubscriptionId(),
                subscription.getSubscriber().getCallingNumber(),
                DayOfTheWeek.today(),
                CallStage.RETRY_2,
                contentFileName,
                "XXX",
                "XXX",
                "XX",
                SubscriptionOrigin.MCTS_IMPORT));

    Map<Integer, Integer> callStats = new HashMap<>();
    CallSummaryRecordDto record =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), timestamp),
            subscription.getSubscriber().getCallingNumber(),
            contentFileName,
            "XXX",
            "XXX",
            "XX",
            FinalCallStatus.FAILED,
            callStats,
            0,
            5);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, record);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // There should be one calls to retry since the retry 2 was failed.
    assertEquals(1, callRetryDataService.count());

    List<CallRetry> retries = callRetryDataService.retrieveAll();

    assertEquals(subscription.getSubscriptionId(), retries.get(0).getSubscriptionId());
    assertEquals(CallStage.RETRY_LAST, retries.get(0).getCallStage());
    assertEquals(DayOfTheWeek.today().nextDay(), retries.get(0).getDayOfTheWeek());
  }
Esempio n. 11
0
  /**
   * To check that NMS shall not retry OBD message for which all OBD attempts(1 actual+1 retry)
   * fails with two message per week configuration.
   */
  @Test
  public void verifyFT142() {

    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    // Create a record in the CallRetry table marked as "retry 1" and verify it is erased from the
    // CallRetry table

    Subscription subscription =
        sh.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now().minusDays(3),
            SubscriptionPackType.PREGNANCY);
    String contentFileName = sh.getContentMessageFile(subscription, 0);
    CallRetry retry =
        callRetryDataService.create(
            new CallRetry(
                subscription.getSubscriptionId(),
                subscription.getSubscriber().getCallingNumber(),
                DayOfTheWeek.today(),
                CallStage.RETRY_1,
                contentFileName,
                "XXX",
                "XXX",
                "XX",
                SubscriptionOrigin.MCTS_IMPORT));

    Map<Integer, Integer> callStats = new HashMap<>();
    CallSummaryRecordDto record =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), timestamp),
            subscription.getSubscriber().getCallingNumber(),
            contentFileName,
            "XXX",
            "XXX",
            "XX",
            FinalCallStatus.FAILED,
            callStats,
            0,
            5);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, record);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // There should be no calls to retry since the one above was the last try
    assertEquals(0, callRetryDataService.count());
  }
  @Test
  public void testUpdateDOBAndCompleteActiveSubscription() throws Exception {
    createLocationData();

    Long msisdn = subscriptionHelper.makeNumber();
    String childId = "0123456789";
    DateTime originalDOB = DateTime.now().minusDays(100);
    DateTime updatedDOB = originalDOB.minusDays(400);

    MctsChild child = new MctsChild(childId);
    child.setState(stateDataService.findByCode(21L));
    child.setDistrict(districtService.findByStateAndCode(child.getState(), 3L));
    makeMctsSubscription(child, originalDOB, SubscriptionPackType.CHILD, msisdn);

    // verify that the subscription is active
    Subscriber subscriber = subscriberDataService.findByCallingNumber(msisdn);
    Subscription subscription = subscriber.getAllSubscriptions().iterator().next();
    assertEquals(SubscriptionStatus.ACTIVE, subscription.getStatus());

    // now, via CSV update, change the DOB to a past subscription date; subscription should be
    // marked completed
    Reader reader =
        createUpdateReaderWithHeaders(
            "1," + childId + ",," + getDateString(updatedDOB) + ",,,,,,,,,,,");
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    Subscriber updatedSubscriber = subscriberDataService.findByCallingNumber(msisdn);
    assertEquals(getDateString(updatedDOB), getDateString(updatedSubscriber.getDateOfBirth()));
    Subscription updatedSubscription = updatedSubscriber.getAllSubscriptions().iterator().next();
    assertEquals(getDateString(updatedDOB), getDateString(updatedSubscription.getStartDate()));
    assertEquals(SubscriptionStatus.COMPLETED, updatedSubscription.getStatus());
  }
  /*
   * To verify that NMS is not able to change the location of
   * beneficiary using MCTS ID when location information is wrong.
   *
   * https://applab.atlassian.net/browse/NMS-231
   */
  @Test
  public void verifyFT325() throws Exception {
    createLocationData();

    Long msisdn = subscriptionHelper.makeNumber();
    String childId = "0123456789";

    MctsChild child = new MctsChild(childId);
    child.setState(stateDataService.findByCode(21L));
    child.setDistrict(districtService.findByStateAndCode(child.getState(), 2L));
    makeMctsSubscription(child, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, msisdn);

    // district provided in request doesn't exist in nms-db
    Reader reader = createUpdateReaderWithHeaders("1," + childId + ",,,,21,8,0026,453,,,,,,");
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    Subscriber subscriber = subscriberDataService.findByCallingNumber(msisdn);
    assertNotNull(subscriber);
    assertNotEquals(subscriber.getChild().getDistrict().getCode(), new Long(7));

    List<SubscriptionError> susbErrors = subscriptionErrorDataService.findByBeneficiaryId(childId);
    SubscriptionError susbError = susbErrors.iterator().next();
    assertNotNull(susbError);
    assertEquals(SubscriptionRejectionReason.INVALID_LOCATION, susbError.getRejectionReason());
  }
  @Test
  public void testUpdateMsisdnForSubscriberWithBothPacks() throws Exception {
    Long oldMsisdn = subscriptionHelper.makeNumber();
    Long newMsisdn = subscriptionHelper.makeNumber();

    Subscription childSubscription =
        subscriptionHelper.mksub(
            SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.CHILD, oldMsisdn);
    String childId = "0123456789";
    childSubscription.getSubscriber().setChild(new MctsChild(childId));
    subscriberDataService.update(childSubscription.getSubscriber());

    Subscription pregnancySubscription =
        subscriptionHelper.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now().minusDays(150),
            SubscriptionPackType.PREGNANCY,
            oldMsisdn);
    String motherId = "9876543210";
    pregnancySubscription.getSubscriber().setMother(new MctsMother(motherId));
    subscriberDataService.update(pregnancySubscription.getSubscriber());

    assertEquals(
        2,
        subscriberDataService
            .findByCallingNumber(oldMsisdn)
            .getActiveAndPendingSubscriptions()
            .size());

    Reader reader = createUpdateReaderWithHeaders("1," + motherId + ",,,,,,,,,,,,," + newMsisdn);
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    Subscriber pregnancySubscriber = subscriberDataService.findByCallingNumber(newMsisdn);
    Subscriber childSubscriber = subscriberDataService.findByCallingNumber(oldMsisdn);

    assertNotNull(pregnancySubscriber);
    assertNotNull(childSubscriber);
    assertNotEquals(childSubscriber, pregnancySubscriber);
    assertEquals(newMsisdn, pregnancySubscriber.getCallingNumber());
    assertEquals(oldMsisdn, childSubscriber.getCallingNumber());
    assertNull(pregnancySubscriber.getChild());
    assertNull(childSubscriber.getMother());
    assertEquals(1, pregnancySubscriber.getActiveAndPendingSubscriptions().size());
    assertEquals(1, childSubscriber.getActiveAndPendingSubscriptions().size());
  }
  @Before
  public void setUp() {
    testingService.clearDatabase();

    subscriptionHelper =
        new SubscriptionHelper(
            subscriptionService,
            subscriberDataService,
            subscriptionPackDataService,
            languageDataService,
            circleDataService,
            stateDataService,
            districtDataService,
            districtService);

    subscriptionHelper.pregnancyPack();
    subscriptionHelper.childPack();
  }
Esempio n. 16
0
  // Deactivate if user phone number does not exist
  // https://github.com/motech-implementations/mim/issues/169
  @Test
  public void verifyIssue169() {
    Subscription subscription = sh.mksub(SubscriptionOrigin.IVR, DateTime.now().minusDays(14));
    Subscriber subscriber = subscription.getSubscriber();

    csrDataService.create(
        new CallSummaryRecord(
            new RequestId(subscription.getSubscriptionId(), "11112233445566").toString(),
            subscription.getSubscriber().getCallingNumber(),
            "w1_1.wav",
            "w1_1",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_INVALIDNUMBER, 10),
            0,
            10,
            3));

    callRetryDataService.create(
        new CallRetry(
            subscription.getSubscriptionId(),
            subscription.getSubscriber().getCallingNumber(),
            DayOfTheWeek.today(),
            CallStage.RETRY_LAST,
            "w1_1.wav",
            "w1_1",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            SubscriptionOrigin.MCTS_IMPORT));

    CallSummaryRecordDto csr =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), "11112233445566"),
            subscription.getSubscriber().getCallingNumber(),
            "w1_1.wav",
            "w1_1",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_INVALIDNUMBER, 3),
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    subscription = subscriptionDataService.findBySubscriptionId(subscription.getSubscriptionId());
    assertEquals(SubscriptionStatus.DEACTIVATED, subscription.getStatus());
    assertEquals(DeactivationReason.INVALID_NUMBER, subscription.getDeactivationReason());
  }
Esempio n. 17
0
  /*
   *To verify 72Weeks Pack is marked completed after the Service Pack runs for its scheduled duration.
   */
  @Test
  public void verifyFT165() {
    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    int days = sh.pregnancyPack().getWeeks() * 7;
    Subscription sub =
        sh.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now().minusDays(days),
            SubscriptionPackType.PREGNANCY);
    int index = sh.getLastMessageIndex(sub);
    CallSummaryRecordDto r =
        new CallSummaryRecordDto(
            new RequestId(sub.getSubscriptionId(), timestamp),
            sub.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(sub, index),
            sh.getWeekId(sub, index),
            rh.hindiLanguage().getCode(),
            sh.getCircle(sub),
            FinalCallStatus.SUCCESS,
            makeStatsMap(StatusCode.OBD_SUCCESS_CALL_CONNECTED, 1),
            120,
            1);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, r);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);
    sub = subscriptionDataService.findBySubscriptionId(sub.getSubscriptionId());
    assertTrue(SubscriptionStatus.COMPLETED == sub.getStatus());
  }
 private void makeMctsSubscription(
     MctsBeneficiary beneficiary, DateTime startDate, SubscriptionPackType packType, Long number) {
   subscriptionHelper.mksub(SubscriptionOrigin.MCTS_IMPORT, startDate, packType, number);
   Subscriber subscriber = subscriberDataService.findByCallingNumber(number);
   if (packType == SubscriptionPackType.CHILD) {
     subscriber.setChild((MctsChild) beneficiary);
     subscriber.setDateOfBirth(startDate);
   } else {
     subscriber.setMother((MctsMother) beneficiary);
     subscriber.setLastMenstrualPeriod(startDate.minusDays(90));
   }
   subscriberDataService.update(subscriber);
 }
Esempio n. 19
0
  @Test
  public void verifyFT149() {

    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    // To check that NMS shall not retry the OBD messages which failed due to user number in dnd.

    Subscription subscription =
        sh.mksub(SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.CHILD);
    String contentFileName = sh.getContentMessageFile(subscription, 0);

    Map<Integer, Integer> callStats = new HashMap<>();
    callStats.put(StatusCode.OBD_DNIS_IN_DND.getValue(), 1);
    CallSummaryRecordDto record =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), timestamp),
            subscription.getSubscriber().getCallingNumber(),
            contentFileName,
            "XXX",
            "XXX",
            "XX",
            FinalCallStatus.REJECTED,
            callStats,
            0,
            1);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, record);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // There should be no calls to retry since the one above was the last rejected with DND reason
    assertEquals(0, callRetryDataService.count());
    subscription = subscriptionService.getSubscription(subscription.getSubscriptionId());
    assertTrue(SubscriptionStatus.DEACTIVATED == subscription.getStatus());
  }
  @Test
  public void testUpdateMsisdn() throws Exception {
    Long oldMsisdn = subscriptionHelper.makeNumber();
    Long newMsisdn = subscriptionHelper.makeNumber();

    Subscription subscription =
        subscriptionHelper.mksub(
            SubscriptionOrigin.MCTS_IMPORT, DateTime.now(), SubscriptionPackType.CHILD, oldMsisdn);
    String mctsId = "0123456789";

    subscription.getSubscriber().setChild(new MctsChild(mctsId));
    subscriberDataService.update(subscription.getSubscriber());

    Reader reader = createUpdateReaderWithHeaders("1," + mctsId + ",,,,,,,,,,,,," + newMsisdn);
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    Subscriber oldSubscriber = subscriberDataService.findByCallingNumber(oldMsisdn);
    assertNull(oldSubscriber.getChild());
    assertEquals(0, oldSubscriber.getActiveAndPendingSubscriptions().size());

    Subscriber subscriber = subscriberDataService.findByCallingNumber(newMsisdn);
    assertNotNull(subscriber);
    assertEquals(mctsId, subscriber.getChild().getBeneficiaryId());
  }
Esempio n. 21
0
  /*
   * To verify 48Weeks Pack is marked completed after the Service Pack runs for its scheduled
   * duration including one retry.
   */
  @Test
  public void verifyFT168() {
    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    int days = sh.childPack().getWeeks() * 7;
    Subscription sub =
        sh.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now().minusDays(days),
            SubscriptionPackType.CHILD);

    callRetryDataService.create(
        new CallRetry(
            sub.getSubscriptionId(),
            sub.getSubscriber().getCallingNumber(),
            DayOfTheWeek.today(),
            CallStage.RETRY_1,
            "w48_1.wav",
            "w48_1",
            "XXX",
            "XX",
            SubscriptionOrigin.MCTS_IMPORT));

    int index = sh.getLastMessageIndex(sub);
    CallSummaryRecordDto r =
        new CallSummaryRecordDto(
            new RequestId(sub.getSubscriptionId(), timestamp),
            sub.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(sub, index),
            sh.getWeekId(sub, index),
            rh.hindiLanguage().getCode(),
            sh.getCircle(sub),
            FinalCallStatus.SUCCESS,
            makeStatsMap(StatusCode.OBD_SUCCESS_CALL_CONNECTED, 1),
            120,
            1);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, r);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);
    sub = subscriptionDataService.findBySubscriptionId(sub.getSubscriptionId());
    assertTrue(SubscriptionStatus.COMPLETED == sub.getStatus());

    // verify call retry entry is also deleted from the database
    CallRetry retry = callRetryDataService.findBySubscriptionId(sub.getSubscriptionId());
    assertNull(retry);
  }
  @Test
  public void testUpdateLocation() throws Exception {
    createLocationData();

    Long msisdn = subscriptionHelper.makeNumber();
    String childId = "0123456789";

    MctsChild child = new MctsChild(childId);
    child.setState(stateDataService.findByCode(21L));
    child.setDistrict(districtService.findByStateAndCode(child.getState(), 2L));
    makeMctsSubscription(child, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, msisdn);

    Reader reader = createUpdateReaderWithHeaders("1," + childId + ",,,,21,3,0026,453,,,,,,");
    mctsBeneficiaryUpdateService.updateBeneficiaryData(reader);

    MctsChild updatedChild = mctsChildDataService.findByBeneficiaryId(childId);
    assertEquals(21L, (long) updatedChild.getState().getCode());
    assertEquals(3L, (long) updatedChild.getDistrict().getCode());
    assertEquals("0026", updatedChild.getTaluka().getCode());
    assertEquals(453L, (long) updatedChild.getHealthBlock().getCode());
  }
Esempio n. 23
0
  @Test
  public void verifyServiceFunctional() {
    Subscription subscription = sh.mksub(SubscriptionOrigin.IVR, DateTime.now().minusDays(14));

    CallSummaryRecordDto csr =
        new CallSummaryRecordDto(
            new RequestId(subscription.getSubscriptionId(), "11112233445566"),
            subscription.getSubscriber().getCallingNumber(),
            "w1_1.wav",
            "w1_1",
            rh.hindiLanguage().getCode(),
            rh.delhiCircle().getName(),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_INVALIDNUMBER, 3),
            0,
            3);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, csr);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);
  }
  @Test
  public void testUpdateBeneficiariesFromFile() throws Exception {
    createLocationData();

    // ----Create 4 beneficiaries:----

    String child1id = "1234567890";
    MctsChild child1 = new MctsChild(child1id);
    child1.setState(stateDataService.findByCode(21L));
    child1.setDistrict(districtService.findByStateAndCode(child1.getState(), 3L));
    Long child1msisdn = subscriptionHelper.makeNumber();
    makeMctsSubscription(
        child1, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, child1msisdn);

    String mother2id = "1234567899";
    MctsMother mother2 = new MctsMother(mother2id);
    mother2.setState(stateDataService.findByCode(21L));
    mother2.setDistrict(districtService.findByStateAndCode(mother2.getState(), 3L));
    Long mother2msisdn = subscriptionHelper.makeNumber();
    makeMctsSubscription(
        mother2, DateTime.now().minusDays(100), SubscriptionPackType.PREGNANCY, mother2msisdn);

    String mother3id = "9876543210";
    MctsMother mother3 = new MctsMother(mother3id);
    mother3.setState(stateDataService.findByCode(21L));
    mother3.setDistrict(districtService.findByStateAndCode(mother3.getState(), 3L));
    makeMctsSubscription(
        mother3,
        DateTime.now().minusDays(100),
        SubscriptionPackType.PREGNANCY,
        subscriptionHelper.makeNumber());

    Long child4msisdn = subscriptionHelper.makeNumber();
    MctsChild child4 = new MctsChild("9876543211");
    child4.setState(stateDataService.findByCode(21L));
    child4.setDistrict(districtService.findByStateAndCode(child4.getState(), 3L));
    makeMctsSubscription(
        child4, DateTime.now().minusDays(100), SubscriptionPackType.CHILD, child4msisdn);

    // ----Update all 4 via CSV:----

    mctsBeneficiaryUpdateService.updateBeneficiaryData(read("csv/mcts_beneficiary_update.csv"));

    // ----Validate updates to each:----

    // MSISDN update:
    Subscriber oldSubscriber1 = subscriberDataService.findByCallingNumber(child1msisdn);
    assertNull(oldSubscriber1.getChild());
    assertEquals(0, oldSubscriber1.getAllSubscriptions().size());

    Subscriber subscriber1 = subscriberDataService.findByCallingNumber(9439986187L);
    assertNotNull(subscriber1);
    assertEquals(child1id, subscriber1.getChild().getBeneficiaryId());

    // MSISDN update:
    Subscriber oldSubscriber2 = subscriberDataService.findByCallingNumber(mother2msisdn);
    assertNull(oldSubscriber2.getMother());
    assertEquals(0, oldSubscriber2.getAllSubscriptions().size());

    Subscriber subscriber2 = subscriberDataService.findByCallingNumber(9439986188L);
    assertNotNull(subscriber2);
    assertEquals(mother2id, subscriber2.getMother().getBeneficiaryId());

    // Location update:
    MctsMother updatedMother3 = mctsMotherDataService.findByBeneficiaryId(mother3id);
    assertEquals(21L, (long) updatedMother3.getState().getCode());
    assertEquals(3L, (long) updatedMother3.getDistrict().getCode());
    assertEquals("0026", updatedMother3.getTaluka().getCode());
    assertEquals(453L, (long) updatedMother3.getHealthBlock().getCode());

    // DOB update:
    String updatedDOB = "01-07-2015";
    Subscriber subscriber4 = subscriberDataService.findByCallingNumber(child4msisdn);
    assertEquals(updatedDOB, getDateString(subscriber4.getDateOfBirth()));
    Subscription updatedSubscription =
        subscriber4.getActiveAndPendingSubscriptions().iterator().next();
    assertEquals(updatedDOB, getDateString(updatedSubscription.getStartDate()));
    assertEquals(SubscriptionStatus.ACTIVE, updatedSubscription.getStatus());
  }
Esempio n. 25
0
  /*
   * To verify that childPack Subscription should not be marked completed after just first retry.
   */
  @Test
  public void verifyFT187() {
    String timestamp = DateTime.now().toString(TIME_FORMATTER);

    SubscriptionHelper sh =
        new SubscriptionHelper(
            subscriptionService,
            subscriberDataService,
            subscriptionPackDataService,
            languageDataService,
            circleDataService,
            stateDataService,
            districtDataService,
            districtService);

    int days = sh.childPack().getWeeks() * 7;
    Subscription sub =
        sh.mksub(
            SubscriptionOrigin.MCTS_IMPORT,
            DateTime.now().minusDays(days),
            SubscriptionPackType.CHILD);

    callRetryDataService.create(
        new CallRetry(
            sub.getSubscriptionId(),
            sub.getSubscriber().getCallingNumber(),
            DayOfTheWeek.today(),
            CallStage.RETRY_1,
            "w48_1.wav",
            "w48_1",
            "XXX",
            "XX",
            SubscriptionOrigin.MCTS_IMPORT));

    int index = sh.getLastMessageIndex(sub);
    CallSummaryRecordDto r =
        new CallSummaryRecordDto(
            new RequestId(sub.getSubscriptionId(), timestamp),
            sub.getSubscriber().getCallingNumber(),
            sh.getContentMessageFile(sub, index),
            sh.getWeekId(sub, index),
            sh.getLanguageCode(sub),
            sh.getCircle(sub),
            FinalCallStatus.FAILED,
            makeStatsMap(StatusCode.OBD_FAILED_SWITCHEDOFF, 10),
            120,
            1);

    Map<String, Object> eventParams = new HashMap<>();
    eventParams.put(CSR_PARAM_KEY, r);
    MotechEvent motechEvent = new MotechEvent(PROCESS_SUMMARY_RECORD_SUBJECT, eventParams);
    csrService.processCallSummaryRecord(motechEvent);

    // There should be one calls to retry since the retry 2 was failed.
    assertEquals(1, callRetryDataService.count());

    List<CallRetry> retries = callRetryDataService.retrieveAll();

    assertEquals(sub.getSubscriptionId(), retries.get(0).getSubscriptionId());
    assertEquals(CallStage.RETRY_2, retries.get(0).getCallStage());
    assertEquals(DayOfTheWeek.today().nextDay(), retries.get(0).getDayOfTheWeek());

    // verify that subscription is still Active, as last message was not delivered successfully and
    // retries
    // are left
    sub = subscriptionDataService.findBySubscriptionId(sub.getSubscriptionId());
    assertEquals(SubscriptionStatus.ACTIVE, sub.getStatus());
  }