'Test', 'host' => '127.0.0.1', 'snmpComunity' => 'test', 'snmpVersion' => 1, 'executeSnmp' => true, 'extraData' => '', 'tenancyId' => '1', 'modelId' => '1', ]; if ($key == null) { return $datos; } else { if (isset($datos[$key])) { return $datos[$key]; } else { throw new \Exception("No se seteo la key del dato a obtener. key=" . $key); } } } /** * Realiza una busqueda. * get_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:cget * Method: GET * * @param string $uri Contiene la direccion. * @param array $data Contiene los filtros a utilizar en la busqueda. * * @return null|Response Retorna el response. */ private function generateGET($uri = null, $data = null) { $this->initDefault(); if ($uri == null) { $uri = $this->getUri(); } if ($data == null) { $data = [ 'name' => $this->obtainData('name'), 'tenancyId' => $this->obtainData('tenancyId'), ]; } $this->getClient()->request('GET', $uri . $this->generateFilters($data)); return $this->getClient()->getResponse(); } /** * Sobreescribe el device.device_listener */ private function setListener() { $webservicemock = $this->getContainerObject('webservice'); $listener = $this->getContainerObject('device.device_listener'); $listener->setWebservice($webservicemock); $validator = $this->getContainerObject('device.device_validator'); $validator->setWebservice($webservicemock); } /** * Realiza el alta. * post_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:post * Method: POST */ public function testPOST() { // inicializo con los datos del webservicemock $this->initDefault($this->obtainDataWebService()); // seteo los datos del listener $this->setListener(); // hago la inserccion llamando al servicio por post $this->getClient()->request('POST', $this->getPOSTUri(), $this->obtainData()); // obtengo la respuesta $response = $this->getClient()->getResponse(); $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http."); } /** * Realiza una busqueda. * get_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:cget * Method: GET */ public function testGET_POST() { // obtengo la respuesta $response = $this->generateGET(); // verifco el resultado $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http."); $this->assertJson($response->getContent(), "No se obtuvo un objeto json."); $this->assertContains($this->obtainData('name'), $response->getContent(), "Error al buscar CMTS."); } /** * Realiza una modificacion. * put_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:put * Method: PUT */ public function testPUT() { // realizo la consulta $response = $this->generateGET(); // busco el id $id = $this->getProperty($response, 'id'); // inicializo con los datos del webservicemock $this->initDefault($this->obtainDataWebService()); // seteo los datos del listener $this->setListener(); // creo el nuevo set de datos a enviar. $data = $this->obtainDataChange($this->obtainData(), [ 'name' => 'Test test', 'id' => $id, ]); // hago la modificacion llamando al servicio por put $this->getClient()->request('PUT', $this->getUriPutDelete() . $id, $data); // obtengo la respuesta $response = $this->getClient()->getResponse(); $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http."); } /** * Realiza una busqueda. * get_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:cget * Method: GET */ public function testGET_PUT() { $response = $this->generateGET(); // verifco el resultado $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http."); $this->assertJson($response->getContent(), "No se obtuvo un objeto json."); $this->assertContains('Test test', $response->getContent(), "Error al buscar CMTS modificado."); } /** * Realiza una baja. * delete_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:delete * Method: DELETE */ public function testDELETE() { // realizo la consulta $response = $this->generateGET(); // obtengo el id de la respuesta de la busqueda $id = $this->getProperty($response, 'id'); $this->initDefault(); // realizo la consulta $data = [ 'tenancy' => 1, ]; $this->getClient()->request('DELETE', $this->getUriPutDelete() . $id, $data); // obtengo la respuesta $response = $this->getClient()->getResponse(); $this->assertEquals(204, $response->getStatusCode(), "Error en la respuesta http."); } /** * Realiza una busqueda. * get_cmtss -> /api/cmtss.{_format} * controller: CablemodemBundle:CMTSREST:cget * Method: GET */ public function testGET_DELETE() { $response = $this->generateGET(); // verifco el resultado $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http."); $this->assertJson($response->getContent(), "No se obtuvo un objeto json."); } }