Explorar el Código

Merge branch 'FD3-430' of https://bitbucket.org/ikflowdat/cablemodem into FD3-449

Conflicts:
	src/CablemodemBundle/Resources/translations/CablemodemBundle.es.yml
Maxi Schvindt hace 7 años
padre
commit
37886f20e1

+ 12 - 1
src/CablemodemBundle/Admin/CablemodemAdmin.php

@@ -17,8 +17,11 @@ class CablemodemAdmin extends WorkflowBaseAdmin
     {
         $datagridMapper
             ->add('clientId')
+            ->add('model')
             ->add('mac')
             ->add('activationCode')
+            ->add('node')
+            ->add('profile')
         ;
     }
 
@@ -29,8 +32,11 @@ class CablemodemAdmin extends WorkflowBaseAdmin
     {
         $listMapper
             ->add('clientId')
+            ->add('model')
             ->add('mac')
             ->add('activationCode')
+            ->add('node')
+            ->add('profile')
             ->add('currentState', 'string', array(
                 'template' => 'WorkflowBundle:Workflow:base_list_field_current_state.html.twig',
                 ))
@@ -54,8 +60,11 @@ class CablemodemAdmin extends WorkflowBaseAdmin
     {
         $formMapper
             ->add('clientId')
+            ->add('model')
             ->add('mac')
             ->add('activationCode')
+            ->add('node')
+            ->add('profile')
         ;
     }
 
@@ -66,9 +75,11 @@ class CablemodemAdmin extends WorkflowBaseAdmin
     {
         $showMapper
             ->add('clientId')
+            ->add('model')
             ->add('mac')
             ->add('activationCode')
-            ->add('currentState')
+            ->add('node')
+            ->add('profile')
         ;
     }
 }

+ 25 - 3
src/CablemodemBundle/Form/CablemodemType.php

@@ -13,16 +13,38 @@ class CablemodemType extends AbstractType
      */
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
-        $builder->add('clientId')->add('mac')->add('activationCode')->add('created')->add('updated')->add('currentState')->add('administrativeState')->add('transitionState')->add('extraData')->add('tenancyId')->add('node')->add('profile')->add('model')->add('workflow')->add('location');
+        $builder
+            ->add('clientId')
+            ->add('mac')
+            ->add('activationCode')
+            ->add('created', 'datetime', array(
+                'widget' => 'single_text',
+                'date_format' => 'yyyy-MM-dd HH:mm:ss'
+            ))
+            ->add('updated', 'datetime', array(
+                'widget' => 'single_text',
+                'date_format' => 'yyyy-MM-dd HH:mm:ss',
+            ))
+            ->add('currentState')
+            ->add('administrativeState')
+            ->add('transitionState')
+            ->add('extraData')
+            ->add('tenancyId')
+            ->add('node')
+            ->add('profile')
+            ->add('model')
+            ->add('workflow')
+            ->add('location');
     }
-    
+
     /**
      * {@inheritdoc}
      */
     public function configureOptions(OptionsResolver $resolver)
     {
         $resolver->setDefaults(array(
-            'data_class' => 'CablemodemBundle\Entity\Cablemodem'
+            'data_class' => 'CablemodemBundle\Entity\Cablemodem',
+            'csrf_protection' => false
         ));
     }
 

+ 14 - 0
src/CablemodemBundle/Resources/translations/CablemodemBundle.es.yml

@@ -27,6 +27,9 @@ filter:
     label_snmp_comunity: SNMP Comunity
     label_snmp_version: SNMP Version
     label_execute_snmp: Execute SNMP
+    label_model: Modelo
+    label_node: Nodo
+    label_profile: Perfil
 form:
     label_name: Nombre
     label_parent: Padre
@@ -46,6 +49,10 @@ form:
     label_terminals: Terminales
     label_docsis_template: Docsis Template
     label_mta_docsis_template: Mta Docsis Template
+    label_model: Modelo
+    label_node: Nodo
+    label_profile: Perfil
+    label_extra_data: Extra Data
 list:
     label_id: Id
     label_name: Nombre
@@ -68,6 +75,9 @@ list:
     label_terminals: Terminales
     label_docsis_template: Docsis Template
     label_mta_docsis_template: Mta Docsis Template
+    label_model: Modelo
+    label_node: Nodo
+    label_profile: Perfil
 show:
     label_id: Id
     label_name: Nombre
@@ -89,3 +99,7 @@ show:
     label_terminals: Terminales
     label_docsis_template: Docsis Template
     label_mta_docsis_template: Mta Docsis Template
+    label_model: Modelo
+    label_node: Nodo
+    label_profile: Perfil
+    label_extra_data: Extra Data

+ 268 - 0
src/CablemodemBundle/tests/CablemodemRESTControllerTest.php

@@ -0,0 +1,268 @@
+<?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 CablemodemRESTControllerTest extends WebTestCaseBase
+{
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getUri()
+    {
+        return '/api/cablemodems.json';
+    }
+
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getUriPutDelete()
+    {
+        return '/api/cablemodems/';
+    }
+
+    /**
+     * 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['clientId'] = '1';
+        $datos['mac'] = '780cb8f8901c';
+        $datos['activationCode'] = '';
+        $datos['created'] = '2018-01-12 14:17:22';
+        $datos['updated'] = '2018-01-12 14:17:22';
+        $datos['currentState'] = '';
+        $datos['administrativeState'] = '';
+        $datos['transitionState'] = 'activo';
+        $datos['extraData'] = '';
+        $datos['tenancyId'] = '1';
+        $datos['node'] = '';
+        $datos['profile'] = '';
+        $datos['model'] = '';
+        $datos['workflow'] = '';
+        $datos['location'] = '';
+
+        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('mac' => $this->obtainData('mac'), '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('mac'), 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('transitionState' => 'aviso', '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('aviso', 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.");
+//    }
+
+}