/*
   * 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 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());
  }