protected function _testNotify($proto, $protoType, $token = null) { // Authenticate $this->loginAsAsync(); // Prepare notify request $token = $token ?: sha1(time()); $req = new \Application\Proto\AsyncNotification\Service\Request(); $req->setToken($token); $req->setProto($protoType); $req->setMessage($proto->serialize()); // Notify async response $this->post(self::NS, array(), $req->serialize()); $this->assertResponseCode('200', $this->getResponse()->getBody()); return $token; }
/** * * @param string $path * @param mixed $data * @return mixed */ public function execute($path, $data = null, $req = null) { $res = parent::execute($path, $data, $req); $restMethod = $this->getRestMethod(); if (!isset($restMethod->mock->async->file)) { throw new Exception("No mock file defined for method."); } if (!file_exists($restMethod->mock->async->file)) { throw new Exception("No mock file for method. (" . $restMethod->mock->async->file . ")"); } // Get transaction ID $transactionId = $req['protoMessage']->getAccounting()->getTransactionId(); // Create notification proto from YAML $yaml = $this->_loadConfigFile($restMethod->mock->async->file)->toArray(); $phpType = $restMethod->mock->async->phpType; $message = new $phpType(); $message->parse($yaml, new \DrSlump\Protobuf\Codec\PhpArray()); // Use the operation described on the configuration if (!empty($restMethod->path)) { $message->setOperation($restMethod->path); } // Generate the asynchronous notification request $request = new \Application\Proto\AsyncNotification\Service\Request(); $request->setToken($transactionId); $request->setProto($restMethod->mock->async->type); $request->setMessage($message->serialize()); // Generate a random delay $delay = rand(1, 20); // Call the notification server try { $config = \App::config(); //TODO Maybe it must be localhost $client = new Zend_Http_Client('http://' . $config['resources']['gs-async']['host'] . '/AsyncNotification/Notify'); $client->setMethod(Zend_Http_Client::POST); $client->setRawData($request->serialize(), 'application/x-protobuf')->request('POST'); } catch (Exception $e) { \App::log()->warn($e); } return $res; }
private function _genDiagnosisNotification($transactionId) { $res = new \Application\Proto\SupDiagnosisAsync\DiagnosisNotification(); $result = new \Application\Proto\Result(); $result->setCode('OK'); $result->setReason('Operation successful'); $res->setResult($result); $simId = new \Application\Proto\SupProvision\Sim\SimId(); $simId->setImsi('1288228282'); $res->setSimId($simId); $res->setTaskId('taskId'); $res->setType(\Application\Proto\SupDiagnosis\Diagnosis\DiagnosisType::TYPE_2); $res->setResult(\Application\Proto\SupDiagnosisAsync\DiagnosisNotification\DiagnosisResult::GSM_UP); $dateInterval = new \Application\Proto\DateInterval(); $dateInterval->setStartDate('2011-11-11'); $dateInterval->setEndDate('2011-12-11'); $res->setTime($dateInterval); $req = new \Application\Proto\AsyncNotification\Service\Request(); $req->setToken($transactionId); $req->setProto('business.service.supdiagnosisasync.diagnosisasync'); $req->message = $res; return $req; }