public function testInvalidServicePackType()
 {
     $servicePack = new ServicePackModel($this->_data);
     $result = $this->_validator->isValid($servicePack->getId());
     $this->assertFalse($result);
     $messages = $this->_validator->getMessages();
     $this->assertArrayHasKey(App_Validate_Ericsson_ServicePackExistsById::ERROR_INVALID_TYPE, $messages);
 }
    public function testAllDataTariff()
    {
        $this->_user = $this->_createAuthUser(array('userName' => 'TariffPlanUserTest', 'organizationId' => self::PROVIDER_COMMERCIAL_ORG_ID));
        $json = '{
    "id": "",
    "name": "BSPA6",
    "description": "Just a description...",
    "published": "",
    "customers": "",
    "serviceProviderId": "",
    "serviceProviderName": "",
    "currency": "",
    "tariffPlanServicesId": "",
    "tariffPlanServicesName": "",
    "tariffPlanLifeCycleId": "",
    "tariffPlanLifeCycleName": "",
    "lifeCycleId": "",
    "lifeCycleName": "",
    "modified": false,
    "listsLocked": true,
    "whiteList": [],
    "blackList": [],
    "roamingList": [],
    "restrictions": {
        "id": "352",
        "serviceProviderId": "provider-ORG_SRVPROVIDER135aa5298cf7qRjXt",
        "name": "1331810308.9193",
        "description": "description",
        "voice": {
            "mo": {
                "home": true,
                "roaming": true,
                "international": true
            },
            "mt": {
                "home": true,
                "roaming": true,
                "international": false
            }
        },
        "sms": {
            "mo": {
                "home": true,
                "roaming": true,
                "international": true
            },
            "mt": {
                "home": true,
                "roaming": true,
                "international": false
            }
        },
        "data": {
            "home": true,
            "roaming": true,
            "international": false
        },
        "type": "",
        "organizationId": "",
        "operator": []
    },
    "lifeCycle": {
        "name": "name",
        "description": "description",
        "status": [
            {
                "status": "INACTIVE_NEW",
                "transitions": [
                    {
                        "destinationStatus": "TEST",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "SUSPENDED",
                        "manual": true,
                        "automatic": true,
                        "automaticInfo": {
                            "timerCause": true,
                            "firstUseCause": false,
                            "voucherCause": false
                        }
                    }
                ],
                "timer": 60
            },
            {
                "status": "TEST",
                "transitions": [
                    {
                        "destinationStatus": "SUSPENDED",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "manual": true,
                        "automatic": false,
                        "destinationStatus": "ACTIVATION_READY"
                    }
                ],
                "vouchers": {
                    "data": {
                        "home": 33792
                    },
                    "voice": {},
                    "sms": {}
                }
            },
            {
                "status": "ACTIVATION_READY",
                "transitions": [
                    {
                        "destinationStatus": "ACTIVE",
                        "manual": false,
                        "automatic": true,
                        "automaticInfo": {
                            "timerCause": false,
                            "firstUseCause": true,
                            "voucherCause": false
                        }
                    },
                    {
                        "destinationStatus": "SUSPENDED",
                        "manual": true,
                        "automatic": false
                    }
                ]
            },
            {
                "status": "ACTIVE",
                "transitions": [
                    {
                        "destinationStatus": "DEACTIVATED",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "SUSPENDED",
                        "manual": true,
                        "automatic": false
                    }
                ]
            },
            {
                "status": "DEACTIVATED",
                "transitions": [
                    {
                        "destinationStatus": "ACTIVE",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "SUSPENDED",
                        "manual": true,
                        "automatic": false
                    }
                ]
            },
            {
                "status": "SUSPENDED",
                "transitions": [
                    {
                        "destinationStatus": "INACTIVE_NEW",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "ACTIVE",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "DEACTIVATED",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "RETIRED",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "TEST",
                        "manual": true,
                        "automatic": false
                    },
                    {
                        "destinationStatus": "ACTIVATION_READY",
                        "manual": true,
                        "automatic": false
                    }
                ]
            },
            {
                "status": "RETIRED"
            }
        ],
        "id": "",
        "type": "lifeCycle"
    },
    "tariffPlanServices": {
        "id": "",
        "type": "",
        "name": "FromTemplate",
        "description": "",
        "currency": "978",
        "defaultOrigVoice": {
            "pool": false,
            "t2N": 1,
            "t2S": 0,
            "t2Q": 0
        },
        "origVoice": [],
        "defaultTermVoice": {
            "pool": false,
            "t2N": 1,
            "t2S": 0,
            "t2Q": 0
        },
        "termVoice": [],
        "defaultSms": {
            "pool": false,
            "t2N": 1,
            "t2Q": 0
        },
        "sms": [],
        "defaultData": {
            "pool": false,
            "t6Q": 0,
            "t6N": 1048576
        },
        "data": [],
        "modified": false
    },
    "tariffPlanLifeCycle": {
        "name": "1331810308.3954",
        "description": "description",
        "status": [
            {
                "status": "ACTIVE",
                "cost": 0
            },
            {
                "status": "DEACTIVATED",
                "cost": 0
            }
        ],
        "transitions": [
            {
                "statusStart": "INACTIVE_NEW",
                "statusFinal": "ACTIVATION_READY",
                "cost": 0
            },
            {
                "statusStart": "INACTIVE_NEW",
                "statusFinal": "TEST",
                "cost": 0
            },
            {
                "statusStart": "INACTIVE_NEW",
                "statusFinal": "ACTIVATION_PENDANT",
                "cost": 0
            },
            {
                "statusStart": "DEACTIVATED",
                "statusFinal": "ACTIVE",
                "cost": 0
            },
            {
                "statusStart": "SUSPENDED",
                "statusFinal": "RETIRED",
                "cost": 0
            }
        ],
        "id": "514",
        "modified": false,
        "type": "",
        "currencyId": "978",
        "lifeCycleId": "514",
        "lifeCycleName": "1331810308.3954"
    }
}';
        $data = Zend_Json::decode($json);
        $sp = new Model\ServicePackModel($data);
        $validator = new Validate\LifeCycleValidate();
        $this->assertTrue($validator->isValid($sp->getLifeCycle()));
    }
 protected function _createServicePack()
 {
     $sp = new Model\ServicePackModel($this->_servicePackData);
     $sp->setLifeCycleId($this->_createLifeCycle());
     $sp->setRestrictionsId($this->_createRestrictions());
     $sp->setTariffPlanLifeCycleId($this->_createTariffPlanLifeCycle());
     $sp->setTariffPlanServicesId($this->_createTariffPlanServices());
     $this->_spMapper->insert($sp);
     $this->assertNotNull($sp->getId());
     $newSp = $this->_spMapper->findOneById($sp->getId());
     $this->assertNotNull($newSp);
     //         $this->_checkSavedData($sp->exportData(), $newSp, "ServicePack");
     $this->assertFalse($newSp->getPublished(), "ServicePack mustn't be published");
     return $sp->getId();
 }
 protected function _updateEricsson(ServicePackModel $model)
 {
     $methodName = self::METHOD_NAME_UPDATE;
     $proto = $this->_createProto($methodName);
     $data = $this->_mapModelToEricssonModel($model->exportData());
     $updateData = new PB\ServicePack\ServicePackUpdate();
     $updateData->parse($data, new \DrSlump\Protobuf\Codec\PhpArray());
     $proto->setUpdateData($updateData);
     $proto->setId($model->getId());
     $response = $this->_sendRequest($methodName, array('protoMessage' => $proto));
     return $this->_checkPutResponse($response);
 }
 /**
  * @param  Application\Model\ServicePackModel $service
  * @return boolean
  */
 public function removeCustomer(ServicePackModel $service, OrgModelAbstract $org)
 {
     if (!strlen((string) $service->getId())) {
         throw new AppEx\InvalidArgumentException("Service pack does not have an Id");
     }
     if (!$org instanceof OrgCustomerModel) {
         throw new AppEx\InvalidArgumentException("Organization must be a customer.");
     }
     $orgId = $org->getId();
     if (!isset($orgId) && !strlen($orgId)) {
         throw new AppEx\InvalidArgumentException("Organization customer does not have an Id");
     }
     if ($service->commercialGroup) {
         $errors[] = "\t- " . \Zend_Json::encode('Service Pack already has commercial groups assigned ');
         $errors = implode("\n", $errors);
         throw new AppEx\ValidateException("The supplServices model does not pass the validation rules:\n" . $errors);
     }
     $result = $this->getMapper()->removeCustomer($service->getId(), $org->getId());
     \App::audit('Removed customer ' . $org->getId() . ' from service pack with Id ' . $service->getId(), $service);
     return $result;
 }
 /**
  * @expectedException \Application\Exceptions\ValidateException
  * @expectedExceptionMessage The ServicePack does not pass the validation rules.
  */
 public function testSumaDiscountsValidationException()
 {
     $sp = array("id" => "123", "name" => "BS_All_Act", "description" => "Description", "published" => "PUBLISHED", "customers" => array(array("id" => "customer-4ddd31cd0e49ad4073000003", "name" => "customer")), "serviceProviderId" => "provider-movistar1376f0c049eGAFyImcQxeblg", "serviceProviderName" => "movistar", "currency" => "978", "tariffPlanServicesId" => "2", "tariffPlanServicesName" => "1395771944.3417", "tariffPlanLifeCycleId" => "2", "tariffPlanLifeCycleName" => "1395771944.2079", "lifeCycleId" => "2", "lifeCycleName" => "1395771944.6719", "modified" => false, "listsLocked" => true, "discounts" => array("discounts" => array(array("customerId" => "customer-4ddd31cd0e49ad4073000003", "customerName" => "customer", "voice" => 9000, "data" => 2000, "sms" => 3000)), "modified" => true), "voucherOnlyDiscounts" => array("discounts" => array(array("customerId" => "customer-4ddd31cd0e49ad4073000003", "customerName" => "customer", "voice" => 9000, "data" => 2000, "sms" => 3000)), "modified" => true), "maxSubscriptions" => 0);
     $srvModel = new ServicePackModel();
     $srvModel->load($sp['id']);
     $srvModel->setId($sp['id']);
     $srvModel->setDiscounts($sp['discounts']['discounts']);
     $service = \Application\Service\ServicePackService::getInstance();
     $service->validate($srvModel, true, new ServicePack\VoucherOnlyDiscountsValidate());
 }