Browse Source

Agregado test de profile rest

gabriel 7 years ago
parent
commit
5f7f8f0fa9

+ 1 - 1
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Response;
 use Symfony\Bundle\FrameworkBundle\Client;
 
 /**
- * Class ClientRESTControllerTest
+ * Class ONURESTControllerTest
  * @package FTTHBundle\tests
  * En caso de modificar las tablas solo se deberia modificar la funcion "obtainData" agregando los campos necesarios.
  */

+ 258 - 0
src/FTTHBundle/tests/ProfileRESTControllerTest.php

@@ -0,0 +1,258 @@
+<?php
+
+namespace FTTHBundle\tests;
+
+use WebserviceBundle\tests\WebTestCaseBase;
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Bundle\FrameworkBundle\Client;
+
+/**
+ * Class ProfileRESTControllerTest
+ * @package FTTHBundle\tests
+ * En caso de modificar las tablas solo se deberia modificar la funcion "obtainData" agregando los campos necesarios.
+ */
+class ProfileRESTControllerTest extends WebTestCaseBase
+{
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getUri()
+    {
+        return '/api/profiles.json';
+    }
+
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getUriPutDelete()
+    {
+        return '/api/profiles/';
+    }
+
+    /**
+     * Genera los datos a manipular.
+     * @param string $key Contiene la key a buscar en los datos.
+     * @return array|string Retorna el array con los datos o el valor de la key pasada como parametro.
+     * @throws \Exception Lanza un excepcion en caso de no encontrar la key.
+     */
+    protected function obtainData($key = null)
+    {
+        $datos = array();
+        $datos['name'] = '5m-1m wifi';
+        $datos['tenancyId'] = '1';
+        $datos['download'] = '5120000';
+        $datos['upload'] = '1024000';
+        $datos['extraData'] = json_encode('{prueba:pp}');
+
+        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_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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();
+        }
+        // realizo la consulta
+        if ($data == null) {
+            $data = array('name' => $this->obtainData('name'), 'tenancyId' => $this->obtainData('tenancyId'));
+        }
+        $this->getClient()->request('GET', $uri . $this->generateFilters($data));
+        // obtengo la respuesta
+        return $this->getClient()->getResponse();
+    }
+
+    /**
+     * Realiza el alta.
+     * post_profile -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST:post
+     * Method: POST
+     */
+    public function testPOST()
+    {
+        // inicializo con los datos del webservicemock
+        $this->initDefault();
+        // hago la inserccion llamando al servicio por post
+        $this->getClient()->request('POST', $this->getUri(), $this->obtainData());
+        // obtengo la respuesta
+        $response = $this->getClient()->getResponse();
+        $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
+    }
+
+    /**
+     * Realiza una busqueda.
+     * get_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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'), strtolower($response->getContent()), "Error al buscar al onu.");
+    }
+
+    /**
+     * Realiza una modificacion.
+     * put_profile -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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();
+        // creo el nuevo set de datos a enviar.
+        $data = $this->obtainDataChange($this->obtainData(), array('upload' => '111222333', '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_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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('111222333', strtolower($response->getContent()), "Error al buscar al onu modificado.");
+    }
+
+
+    /**
+     * Realiza una baja.
+     * delete_profile -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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 = array('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_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST: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.");
+    }
+
+    /**
+     * Realiza el alta.
+     * post_profile -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST:post
+     * Method: POST
+     */
+    public function testMIGRATIONS()
+    {
+        // inicializo con los datos del webservicemock
+        $this->initDefault();
+        // hago la inserccion llamando al servicio por post
+        $this->getClient()->request('POST', '/api/profiles/profiles/migrate.json', $this->obtainData());
+        // obtengo la respuesta
+        $response = $this->getClient()->getResponse();
+        $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
+    }
+
+    /**
+     * Realiza una busqueda.
+     * get_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST:cget
+     * Method: GET
+     */
+    public function testGET_MIGRATIONS()
+    {
+        // 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'), strtolower($response->getContent()), "Error al buscar al onu.");
+    }
+
+    /**
+     * Realiza una baja.
+     * delete_profile -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST:delete
+     * Method: DELETE
+     */
+    public function testDELETE_MIGRATIONS()
+    {
+        // 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 = array('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_profiles -> /api/profiles.{_format}
+     * controller: FTTHBundle:ProfileREST:cget
+     * Method: GET
+     */
+    public function testGET_DELETE_MIGRATIONS()
+    {
+        $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.");
+    }
+
+}