Browse Source

FD3-295 Fix test onu rest controller

Guillermo Espinoza 7 năm trước cách đây
mục cha
commit
d783267f9c
1 tập tin đã thay đổi với 66 bổ sung0 xóa
  1. 66 0
      src/FTTHBundle/tests/ONURESTControllerTest.php

+ 66 - 0
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -22,6 +22,22 @@ class ONURESTControllerTest extends WebTestCaseBase
         return '/api/onus.json';
     }
 
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getOLTUri()
+    {
+        return '/api/olts.json';
+    }
+
+    /**
+     * @return string Retorna la uri a consultar.
+     */
+    protected function getNAPUri()
+    {
+        return '/api/naps.json';
+    }
+
     /**
      * @return string Retorna la uri a consultar.
      */
@@ -81,6 +97,54 @@ class ONURESTControllerTest extends WebTestCaseBase
         }
     }
 
+    /**
+     * 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 obtainNAPData($key = null)
+    {
+        $datos = array();
+        $datos['olt'] = 1;
+        $datos['name'] = 'NAP';
+        $datos['tenancyId'] = 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);
+            }
+        }
+    }
+
+    /**
+     * 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 obtainOLTData($key = null)
+    {
+        $datos = array();
+        $datos['name'] = 'OLT';
+        $datos['ip'] = '127.0.0.1';
+        $datos['tenancyId'] = 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_onus -> /api/onus.{_format}
@@ -132,6 +196,8 @@ class ONURESTControllerTest extends WebTestCaseBase
         // seteo los datos del listener
         $this->setListener();
         // hago la inserccion llamando al servicio por post
+        $this->getClient()->request('POST', $this->getOLTUri(), $this->obtainOLTData());
+        $this->getClient()->request('POST', $this->getNAPUri(), $this->obtainNAPData());
         $this->getClient()->request('POST', $this->getUri(), $this->obtainData());
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();