Browse Source

Merge remote-tracking branch 'origin/master' into FD3-221

Luciano Andrade 7 years ago
parent
commit
809710294f

+ 1 - 1
.drone.yml

@@ -35,7 +35,7 @@ pipeline:
       - composer dump-autoload --optimize
       - chmod 0777 -R var/logs var/cache var/sessions
       - php bin/console doctrine:schema:update --force -vvv --env=test
-      - touch var/logs/{dev,test}.log
+      - touch var/logs/test.log
       - tail -f var/logs/*.log &
       - vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist
 

File diff suppressed because it is too large
+ 198 - 213
composer.lock


+ 42 - 0
src/FTTHBundle/Controller/ONURESTController.php

@@ -13,6 +13,8 @@ use Symfony\Component\HttpFoundation\Response;
 use WebserviceBundle\Controller\RESTController;
 use FOS\RestBundle\Controller\Annotations as Rest;
 
+use FOS\RestBundle\Controller\Annotations\Patch;
+
 /**
  * ONU controller.
  * @RouteResource("ONU")
@@ -71,4 +73,44 @@ class ONURESTController extends RESTController
         }
         return $resp;
     }
+
+    /**
+     * PATCH Route annotation.
+     * @Patch("/onus/{id}/apply/{workflow}/{transition}")
+     * @View(statusCode=201, serializerEnableMaxDepthChecks=true)
+     *
+     * @param Request $request
+     * @param $entity
+     * @param $transition
+     * @param $workflow
+     *
+     * @return Response
+     */
+    public function applyAction(Request $request, ONU $entity, String $workflow, String $transition)
+    {
+        try {
+
+	    $wr = $this->container->get("workflow.registry");
+	    $wf = $wr->get($entity, $workflow);
+
+	    $newState = $wf->apply($entity, $transition);
+
+
+	    $em = $this->container->get("doctrine.orm.entity_manager");
+	    $validator = $this->container->get('validator');
+	    $errors = $validator->validate($entity);
+	    if (count($errors) > 0) {
+		    $errorsString = (string) $errors;
+		    return FOSView::create($errorsString, Codes::HTTP_INTERNAL_SERVER_ERROR);
+	    }else{
+		    $entity->setAdministrativeState("suspend");
+		    $em->persist($entity);
+		    $em->flush($entity);
+
+		    return $entity;
+	    }
+        } catch (\Exception $e) {
+            return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
+        }
+    }
 }

+ 2 - 4
src/FTTHBundle/Form/ONUType.php

@@ -41,10 +41,8 @@ class ONUType extends AbstractType
             ->add('nap')
             ->add('ponSerialNumber')
             ->add('clientId')
-            ->add('administrativeState')
-            ->add('transitionState')
-            ->add('tenancyId')
-            ->add('extraData');
+            ->add('extraData')
+            ->add('tenancyId');
 
         $builder->addEventListener(
             FormEvents::PRE_SUBMIT,

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

@@ -41,6 +41,12 @@ class ONURESTControllerTest extends WebTestCaseBase
             json_encode(array(array("name" => "Stock", "id" => 1)));
         $datos['api/devices/check'] =
             json_encode(array(array('result' => true, 'errors' => null)));
+	$datos['api/devices'] =
+            json_encode(array('id' => 1));
+
+	$datos["client"] = array(array("id"=> 1));
+
+
         return $datos;
     }
 
@@ -60,7 +66,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         $datos['mac'] = '00:11:22:33';
         $datos['ponSerialNumber'] = 'pon';
         $datos['clientId'] = array('name' => 'Stock GZ [pruebass]');
-        $datos['transitionState'] = 'ts';
+        //$datos['transitionState'] = 'ts';
         $datos['tenancyId'] = 1;
         $datos['deviceId'] = 1;
 
@@ -115,6 +121,8 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->getClient()->request('POST', $this->getUri(), $this->obtainData());
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();
+
+        var_dump($response->getContent());
         $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
     }
 
@@ -174,6 +182,42 @@ class ONURESTControllerTest extends WebTestCaseBase
         $this->assertContains('pon_modifi', strtolower($response->getContent()), "Error al buscar al onu modificado.");
     }
 
+    /**
+     * Aplica una transicion de un workflow a una entidad
+     * apply_onus -> /api/onu/{id}/apply/{workflow}/{transition}.{_format}
+     * controller: ClientBundle:ClientREST:cget
+     * Method: GET
+     */
+    public function testAPPLY()
+    {
+        $this->initDefault($this->obtainDataWebService());
+        $response = $this->generateGET();
+        // verifco el resultado
+        $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
+        $this->assertJson($json = $response->getContent(), "No se obtuvo un objeto json.");
+
+	$json = json_decode($json, true);
+	$json = $json[0];
+
+	$this->assertEquals("active", $json["administrativeState"]);
+
+        $this->initDefault($this->obtainDataWebService());
+
+        $original = $this->getClient()->getContainer()->get('device.device_listener');
+	$fakeWebService = $this->getClient()->getContainer()->get('webservice');
+	$original->setWebservice($fakeWebService);
+
+	$this->getClient()->request('PATCH',
+		$this->getUriPutDelete().  $json["id"] . "/apply/administrative_state/active_to_suspend.json" , array());
+        $response = $this->getClient()->getResponse();
+
+	$json = json_decode($response->getContent(), true);
+
+        $this->assertEquals(201, $response->getStatusCode(), "Error en la respuesta http.");
+	$this->assertEquals("suspend", $json["administrativeState"]);
+
+        $response = $this->getClient()->getResponse();
+    }
 
     /**
      * Realiza una baja.

+ 71 - 0
src/FTTHBundle/tests/WorkflowOnuTest.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace FTTHBundle\tests;
+
+use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
+
+use FTTHBundle\Entity\ONU;
+
+/**
+ * @package FTTHBundle\tests
+ */
+class WorkflowOnuTest extends KernelTestCase
+{
+
+    protected function setUp()
+    {
+        self::bootKernel();
+
+        $this->em = static::$kernel->getContainer()
+            ->get('doctrine')
+            ->getManager();
+	$this->wr = static::$kernel->getContainer()
+            ->get('workflow.registry');
+
+    }
+
+    function testAdministrative(){
+        $onu = new ONU;
+	$onu->setPonSerialNumber("cafecafecafe");
+	$onu->setClientId(1);
+	$onu->setTenancyId(1);
+
+	try{
+		$this->em->persist($onu);
+		$this->em->flush();
+	}catch(\Exception $e){
+	
+	}
+
+	$this->assertEquals("active", $onu->getAdministrativeState());
+            
+
+	$wf = $this->wr->get($onu, "administrative_state");
+	
+	$wf->apply($onu, "active_to_suspend");
+
+	$this->assertEquals("suspend", $onu->getAdministrativeState());
+
+	$this->em->persist($onu);
+	$this->em->flush();
+
+        $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
+
+	$this->assertEquals("suspend", $newOnu->getAdministrativeState());
+
+	$wf->apply($newOnu, "suspend_to_active");
+
+	$this->em->persist($newOnu);
+	$this->em->flush();
+
+        $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
+	$this->assertEquals("active", $newOnu->getAdministrativeState());
+
+
+	if($newOnu){
+		$newOnu = $this->em->remove($newOnu);
+		$this->em->flush();
+	}
+	
+    }
+}