コード例 #1
0
 /**
  * Show how Bidirectional relationships must be correctly managed in 
  * userland/application code. (See Doctrine the tutorial: 
  * "Consistency of bi-directional references on the inverse side of a 
  * relation have to be managed in userland application code. Doctrine 
  * cannot magically update your collections to be consistent."). 
  */
 public function testDowntimeEndpoint_BidirectionalJoinConsistencyManagement()
 {
     print __METHOD__ . "\n";
     // create a linked entity graph as beow:
     //
     //     se        (1 service)
     //    / | \
     // el1 el2 el3   (3 endpoints)
     //    \ | /
     //     dt1       (1 downtime)
     $se = TestUtil::createSampleService('service1');
     $el1 = TestUtil::createSampleEndpointLocation();
     $el2 = TestUtil::createSampleEndpointLocation();
     $el3 = TestUtil::createSampleEndpointLocation();
     $se->addEndpointLocationDoJoin($el1);
     $se->addEndpointLocationDoJoin($el2);
     $se->addEndpointLocationDoJoin($el3);
     $dt1 = new Downtime();
     $dt1->setDescription('downtime description');
     $dt1->setSeverity("WARNING");
     $dt1->setClassification("UNSCHEDULED");
     $dt1->addEndpointLocation($el1);
     $dt1->addEndpointLocation($el2);
     $dt1->addEndpointLocation($el3);
     // persist and flush
     $this->em->persist($se);
     $this->em->persist($el1);
     $this->em->persist($el2);
     $this->em->persist($el3);
     $this->em->persist($dt1);
     $this->em->flush();
     // Now delete the relationship between dt1 and el1 + el2 using OWNING
     // SIDE ONLY; since downtime is the OWNING side we must remove el1 + el2
     // from downtime to actually delete the relationships in the DB
     // (on the subsequent flush). Since we have only removed the relationship
     // on the downtime side, our in-mem entity model is now inconsistent !
     $dt1->getEndpointLocations()->removeElement($el1);
     //$el1->getDowntimes()->removeElement($dt1);
     $dt1->getEndpointLocations()->removeElement($el2);
     //$el2->getDowntimes()->removeElement($dt1);
     $this->em->flush();
     // Entity model in DB now looks like this:
     //     se
     //    / | \
     // el1 el2 el3
     //        /
     //     dt1      (note FKs/relationships have been removed)
     // Assert that there are still three EndpointLocations and one Downtimes in the database
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 3);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 1);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     // Assert that our in-mem entity model is now inconsistent with DB
     // when VIEWED FROM THE ENDPOINT SIDE.
     $this->assertEquals(1, count($el1->getDowntimes()));
     $this->assertEquals(1, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     // Assert that our in-mem entity model is consistent with DB
     // when VIEWED FROM THE DOWNTIME SIDE:
     // dt1 still has el3 linked (as expected) but not el1 or el2.
     // Note we use first() method to fetch first array collection entry!
     // (calling get(0) would not work as expected because the collection
     // is a map so array key values are preserved - el3 was added 3rd so it
     // preserves its zero-offset key value of 2).
     $this->assertEquals(1, count($dt1->getEndpointLocations()));
     $this->assertSame($el3, $dt1->getEndpointLocations()->first());
     $this->assertSame($el3, $dt1->getEndpointLocations()->get(2));
     // Next lines keep our in-mem inverse side consistent with DB. If we
     // didn't do this, then our first assertion on the following lines below
     // would fail! This shows that you have to keep your bi-directional
     // relationships consistent in userland/application code, doctrine
     // won't do this for you!
     $el1->getDowntimes()->removeElement($dt1);
     $el2->getDowntimes()->removeElement($dt1);
     // After updating the 'in-memory' entity model, check that el1 and el2
     // have no linked downtimes while el3 still has dt linked.
     // This mirrors what we have in the DB.
     $this->assertEquals(0, count($el1->getDowntimes()));
     $this->assertEquals(0, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     // our collection key value is still same
     $this->assertSame($el3, $dt1->getEndpointLocations()->get(2));
 }
コード例 #2
0
 /**
  * Test the <code>$serviceDAO->removeEndpoint($endpoint)</code> method.   
  */
 public function testServiceDAORemoveEndpoint()
 {
     print __METHOD__ . "\n";
     // create a linked entity graph as beow:
     //
     //      se -----|    (1 service)
     //     / | \    |
     //  el1 el2 el3 |    (3 endpoints)
     //  |  \ | /    |
     // dt0  dt1 ----|    (1 downtime)
     $dt1 = new Downtime();
     $dt1->setDescription('downtime description');
     $dt1->setSeverity("WARNING");
     $dt1->setClassification("UNSCHEDULED");
     $dt0 = new Downtime();
     $dt0->setDescription('downtime description');
     $dt0->setSeverity("WARNING");
     $dt0->setClassification("UNSCHEDULED");
     $se = TestUtil::createSampleService('service1');
     $el1 = TestUtil::createSampleEndpointLocation();
     $el2 = TestUtil::createSampleEndpointLocation();
     $el3 = TestUtil::createSampleEndpointLocation();
     $se->addEndpointLocationDoJoin($el1);
     $se->addEndpointLocationDoJoin($el2);
     $se->addEndpointLocationDoJoin($el3);
     //$se->_addDowntime($dt1); // we don't call this in client code !
     $dt1->addEndpointLocation($el1);
     $dt1->addEndpointLocation($el2);
     $dt1->addEndpointLocation($el3);
     $dt1->addService($se);
     $dt0->addEndpointLocation($el1);
     //$dt0->addService($se); // note we don't add this relationship for purposes of the test
     // persist and flush
     $this->em->persist($se);
     $this->em->persist($el1);
     $this->em->persist($el2);
     $this->em->persist($el3);
     $this->em->persist($dt1);
     $this->em->persist($dt0);
     $this->em->flush();
     // create DAO to test
     $serviceDao = new ServiceDAO();
     $serviceDao->setEntityManager($this->em);
     // remove first endpoint causing dt0 to be orphaned
     $serviceDao->removeEndpoint($el1);
     $this->em->flush();
     // Assert expected object graph
     //     se -----|   (1 service)
     //      | \    |
     //     el2 el3 |   (2 endpoints)
     //      | /    |
     // dt0 dt1-----|   (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 2);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el2->getDowntimes()));
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(2, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(2, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el2);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //       \     |
     //        el3  | (1 endpoints)
     //        /    |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 1);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(1, count($el3->getDowntimes()));
     $this->assertEquals(1, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(1, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
     // remove another el
     $serviceDao->removeEndpoint($el3);
     $this->em->flush();
     // Assert expected object graph in DB
     //     se -----| (1 service)
     //             |
     //             | (1 endpoints)
     //             |
     // dt0 dt1-----| (2 downtime)
     //
     $testConn = $this->getConnection();
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes");
     $this->assertTrue($result->getRowCount() == 2);
     $result = $testConn->createQueryTable('results_table', "SELECT * FROM Downtimes_EndpointLocations");
     $this->assertTrue($result->getRowCount() == 0);
     // Assert expected object graph in ORM Mem
     $this->assertEquals(0, count($se->getEndpointLocations()));
     $this->assertEquals(1, count($se->getDowntimes()));
     $this->assertEquals(0, count($dt1->getEndpointLocations()));
     $this->assertEquals(1, count($dt1->getServices()));
 }
コード例 #3
0
 */
$roleType1 = TestUtil::createSampleRoleType("NAME");
$roleType2 = TestUtil::createSampleRoleType("NAME2");
$this->em->persist($roleType1);
$this->em->persist($roleType2);
// Create a user
$userWithRoles = TestUtil::createSampleUser("Test", "Testing", "/c=test");
$this->em->persist($userWithRoles);
$userId = $userWithRoles->getId();
// Create an NGI, site and services
$ngi = TestUtil::createSampleNGI("MYNGI");
$site1 = TestUtil::createSampleSite('site1');
$site2 = TestUtil::createSampleSite('site2');
$service1 = TestUtil::createSampleService('site1_service1');
$service2 = TestUtil::createSampleService('site1_service2');
$endpoint1 = TestUtil::createSampleEndpointLocation();
$downtime1 = TestUtil::createSampleDowntime();
$downtime2 = TestUtil::createSampleDowntime();
$service1->addEndpointLocationDoJoin($endpoint1);
$downtime1->addEndpointLocation($endpoint1);
$downtime2->addEndpointLocation($endpoint1);
$site1->addServiceDoJoin($service1);
$site1->addServiceDoJoin($service2);
$ngi->addSiteDoJoin($site1);
$ngi->addSiteDoJoin($site2);
$certStatusLog1 = TestUtil::createSampleCertStatusLog();
$certStatusLog2 = TestUtil::createSampleCertStatusLog();
$site2->addCertificationStatusLog($certStatusLog1);
$site2->addCertificationStatusLog($certStatusLog2);
$this->em->persist($ngi);
$this->em->persist($site1);
コード例 #4
0
ファイル: ExtensionsTest.php プロジェクト: Tom-Byrne/gocdb
 /**
  * Show the creation of an endpoint and properties and that 
  * all data is removed on deletion of an endpoint or property
  */
 public function testEndpointPropertyDeletions()
 {
     print __METHOD__ . "\n";
     $service = TestUtil::createSampleService("TestService");
     $ngi = TestUtil::createSampleNGI("TestNGI");
     $site = TestUtil::createSampleSite("TestSite");
     $endpoint = TestUtil::createSampleEndpointLocation();
     //Join service to site, and site to NGI.
     $ngi->addSiteDoJoin($site);
     $site->addServiceDoJoin($service);
     $service->addEndpointLocationDoJoin($endpoint);
     //Create properties
     $prop1 = TestUtil::createSampleEndpointProperty("VO", "Atlas");
     $prop2 = TestUtil::createSampleEndpointProperty("VO", "CMS");
     $prop3 = TestUtil::createSampleEndpointProperty("VO", "Alice");
     $endpoint->addEndpointPropertyDoJoin($prop1);
     $endpoint->addEndpointPropertyDoJoin($prop2);
     $endpoint->addEndpointPropertyDoJoin($prop3);
     //Persist in the entity manager
     $this->em->persist($service);
     $this->em->persist($ngi);
     $this->em->persist($site);
     $this->em->persist($endpoint);
     $this->em->persist($prop1);
     $this->em->persist($prop2);
     $this->em->persist($prop3);
     //Commit to the database
     $this->em->flush();
     //Check endpoint has 3 properties associated with it
     $properties = $endpoint->getEndpointProperties();
     $this->assertTrue(count($properties) == 3);
     //Create an admin user that can delete a property
     $adminUser = TestUtil::createSampleUser('my', 'admin', '/my/admin');
     $adminUser->setAdmin(TRUE);
     $this->em->persist($adminUser);
     //Delete the property from the service
     $serviceService = new org\gocdb\services\ServiceService();
     $serviceService->setEntityManager($this->em);
     $serviceService->deleteEndpointProperty($adminUser, $prop1);
     //Check that the service now only has 2 properties
     $properties = $endpoint->getEndpointProperties();
     $this->assertTrue(count($properties) == 2);
     $this->em->flush();
     //Print names of properties
     foreach ($properties as $prop) {
         print $prop->getKeyName() . "-";
         print $prop->getKeyValue() . "\n";
     }
     //Check this via the database
     $con = $this->getConnection();
     //Get service id to use in sql statements
     $endpointId = $endpoint->getId();
     $result = $con->createQueryTable('results', "SELECT * FROM endpoint_properties WHERE PARENTENDPOINT_ID = '{$endpointId}'");
     //Assert that only 2 service properties exist in the database for this service
     $this->assertEquals(2, $result->getRowCount());
     //Now delete the endpont and check that it cascade deletes
     //the endpoint's associated properties
     $serviceService->deleteEndpoint($endpoint, $adminUser);
     $this->em->flush();
     //Check endpoint is gone
     $result = $con->createQueryTable('results', "SELECT * FROM EndpointLocations WHERE ID = '{$endpointId}'");
     $this->assertEquals(0, $result->getRowCount());
     //Check properties are gone
     $result = $con->createQueryTable('results', "SELECT * FROM endpoint_properties WHERE PARENTENDPOINT_ID = '{$endpointId}'");
     $this->assertEquals(0, $result->getRowCount());
 }