FOSSology  4.4.0
Open Source License Compliance by Open Source Software
schedulerTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2019 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
11 namespace Fossology\Decider\Test;
12 
31 use Mockery as M;
32 
33 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
34 include_once(__DIR__.'/SchedulerTestRunnerCli.php');
35 include_once(__DIR__.'/SchedulerTestRunnerMock.php');
36 
41 class SchedulerTest extends \PHPUnit\Framework\TestCase
42 {
44  private $testDb;
46  private $dbManager;
48  private $testInstaller;
49 
51  private $licenseDao;
53  private $clearingDao;
55  private $clearingDecisionProcessor;
57  private $agentLicenseEventProcessor;
59  private $uploadDao;
61  private $uploadPermDao;
63  private $highlightDao;
65  private $showJobsDao;
67  private $copyrightDao;
69  private $runnerCli;
71  private $runnerMock;
72 
76  protected function setUp() : void
77  {
78  $this->testDb = new TestPgDb("deciderSched");
79  $this->dbManager = $this->testDb->getDbManager();
80  $this->testDb->setupSysconfig();
81 
82  $this->licenseDao = new LicenseDao($this->dbManager);
83  $logger = M::mock('Monolog\Logger');
84  $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
85  $this->uploadDao = new UploadDao($this->dbManager, $logger, $this->uploadPermDao);
86  $this->copyrightDao = new CopyrightDao($this->dbManager, $this->uploadDao);
87  $this->highlightDao = new HighlightDao($this->dbManager);
88  $agentDao = new AgentDao($this->dbManager, $logger);
89  $this->agentLicenseEventProcessor = new AgentLicenseEventProcessor($this->licenseDao, $agentDao);
90  $clearingEventProcessor = new ClearingEventProcessor();
91  $this->clearingDao = new ClearingDao($this->dbManager, $this->uploadDao);
92  $this->showJobsDao = new ShowJobsDao($this->dbManager, $this->uploadDao);
93  $this->clearingDecisionProcessor = new ClearingDecisionProcessor($this->clearingDao, $this->agentLicenseEventProcessor, $clearingEventProcessor, $this->dbManager);
94  $this->copyrightDao = M::mock(CopyrightDao::class);
95 
96  global $container;
97  $container = M::mock('ContainerBuilder');
98  $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManager);
99 
100  $this->runnerMock = new SchedulerTestRunnerMock($this->dbManager, $agentDao,
101  $this->clearingDao, $this->uploadDao, $this->highlightDao,
102  $this->showJobsDao, $this->copyrightDao, $this->clearingDecisionProcessor,
103  $this->agentLicenseEventProcessor);
104  $this->runnerCli = new SchedulerTestRunnerCli($this->testDb);
105  }
106 
110  protected function tearDown() : void
111  {
112  $this->testDb->fullDestruct();
113  $this->testDb = null;
114  $this->dbManager = null;
115  $this->licenseDao = null;
116  $this->highlightDao = null;
117  $this->showJobsDao = null;
118  $this->clearingDao = null;
119  $this->copyrightDao = null;
120  M::close();
121  }
122 
126  private function setUpRepo()
127  {
128  $sysConf = $this->testDb->getFossSysConf();
129  $this->testInstaller = new TestInstaller($sysConf);
130  $this->testInstaller->init();
131  $this->testInstaller->cpRepo();
132  }
133 
137  private function rmRepo()
138  {
139  $this->testInstaller->rmRepo();
140  $this->testInstaller->clear();
141  }
142 
146  private function setUpTables()
147  {
148  $this->testDb->createPlainTables(array('upload','upload_reuse','uploadtree','uploadtree_a','license_ref','license_ref_bulk',
149  'license_set_bulk','clearing_decision','clearing_decision_event','clearing_event','license_file','highlight',
150  'highlight_keyword','agent','pfile','ars_master','users','group_user_member','license_map','jobqueue','job',
151  'report_info'), false);
152  $this->testDb->createSequences(array('agent_agent_pk_seq','pfile_pfile_pk_seq','upload_upload_pk_seq','nomos_ars_ars_pk_seq',
153  'license_file_fl_pk_seq','license_ref_rf_pk_seq','license_ref_bulk_lrb_pk_seq',
154  'clearing_decision_clearing_decision_pk_seq','clearing_event_clearing_event_pk_seq','FileLicense_pkey',
155  'jobqueue_jq_pk_seq','job_job_pk_seq'),false);
156  $this->testDb->createViews(array('license_file_ref'),false);
157  $this->testDb->createConstraints(array('agent_pkey','pfile_pkey','upload_pkey_idx','clearing_event_pkey','jobqueue_pkey'),false);
158  $this->testDb->alterTables(array('agent','pfile','upload','ars_master','license_ref_bulk','license_set_bulk','clearing_event',
159  'clearing_decision','license_file', 'license_ref','highlight','jobqueue','job'),false);
160  $this->testDb->createInheritedTables();
161  $this->testDb->createInheritedArsTables(array('nomos','monk','copyright'));
162 
163  $this->testDb->insertData(array('pfile','upload','uploadtree_a','users','group_user_member','agent','license_file',
164  'nomos_ars','monk_ars','copyright_ars'), false);
165  $this->testDb->insertData_license_ref(80);
166 
167  $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
168  }
169 
175  private function getHeartCount($output)
176  {
177  $matches = array();
178  if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches)) {
179  return intval($matches[1]);
180  } else {
181  return -1;
182  }
183  }
184 
187  {
188  $this->runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($this->runnerMock);
189  }
190 
193  {
194  $this->runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($this->runnerCli);
195  }
196 
197  private function runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($runner)
198  {
199  $this->setUpTables();
200  $this->setUpRepo();
201 
202  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
203 
204  $licId1 = $licenseRef1->getId();
205 
206  $agentNomosId = 6;
207  $pfile = 4;
208  $jobId = 15;
209 
210  $this->dbManager->queryOnce("DELETE FROM license_file");
211  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
212  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
213  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
214  $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)"
215  . " VALUES ($jobId, 2, 'decider', '2', '2014-08-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
216 
217  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId, $args='');
218 
219  $this->assertTrue($success, 'cannot run runner');
220  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
221 
222  assertThat($this->getHeartCount($output), equalTo(0));
223 
224  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
225  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
226  assertThat($decisions, is(arrayWithSize(0)));
227 
228  $this->rmRepo();
229  }
230 
233  {
234  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($this->runnerMock);
235  }
236 
239  {
240  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($this->runnerCli);
241  }
242 
243  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($runner)
244  {
245  $this->setUpTables();
246  $this->setUpRepo();
247 
248  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
249 
250  $licId1 = $licenseRef1->getId();
251 
252  $agentNomosId = 6;
253  $agentMonkId = 5;
254  $pfile = 4;
255 
256  $this->dbManager->queryOnce("DELETE FROM license_file");
257  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
258  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
259  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
260 
261  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
262  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
263  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
264  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
265 
266  $this->assertTrue($success, 'cannot run runner');
267  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
268 
269  assertThat($this->getHeartCount($output), equalTo(1));
270 
271  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
272  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
273  assertThat($decisions, is(arrayWithSize(1)));
274 
275  $this->rmRepo();
276  }
277 
280  {
281  $this->runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($this->runnerMock);
282  }
283 
286  {
287  $this->runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($this->runnerCli);
288  }
289 
290  private function runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($runner)
291  {
292  $this->setUpTables();
293  $this->setUpRepo();
294 
295  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
296 
297  $licId1 = $licenseRef1->getId();
298 
299  $agentNomosId = 6;
300  $agentMonkId = 5;
301  $pfile = 4;
302 
303  $this->dbManager->queryOnce("DELETE FROM license_file");
304  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
305  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
306  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
307 
308  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
309  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
310  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
311 
312  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
313 
314  $this->assertTrue($success, 'cannot run runner');
315  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
316 
317  assertThat($this->getHeartCount($output), equalTo(0));
318 
319  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
320  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
321  assertThat($decisions, is(arrayWithSize(0)));
322 
323  $this->rmRepo();
324  }
325 
328  {
329  $this->runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($this->runnerMock);
330  }
331 
334  {
335  $this->runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($this->runnerCli);
336  }
337 
338  private function runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($runner)
339  {
340  $this->setUpTables();
341  $this->setUpRepo();
342 
343  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
344 
345  $licId1 = $licenseRef1->getId();
346 
347  $agentNomosId = 6;
348  $agentMonkId = 5;
349  $pfile = 4;
350 
351  $this->dbManager->queryOnce("DELETE FROM license_file");
352  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
353  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
354  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
355 
356  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
357  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
358  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
359 
360  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId1,$pfile,$agentMonkId)");
361  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
362  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,18,19)");
363 
364  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
365 
366  $this->assertTrue($success, 'cannot run runner');
367  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
368 
369  assertThat($this->getHeartCount($output), equalTo(1));
370 
371  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
372  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
373  assertThat($decisions, is(arrayWithSize(1)));
374 
375  $this->rmRepo();
376  }
377 
380  {
381  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($this->runnerMock);
382  }
383 
386  {
387  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($this->runnerCli);
388  }
389 
390  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($runner)
391  {
392  $this->setUpTables();
393  $this->setUpRepo();
394 
395  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
396  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
397  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
398 
399  $licId1 = $licenseRef1->getId();
400  $licId2 = $licenseRef2->getId();
401  $licId3 = $licenseRef3->getId();
402 
403  $agentNomosId = 6;
404  $agentMonkId = 5;
405  $pfile = 4;
406 
407  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
408  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId3, $licId1, ".LicenseMap::CONCLUSION.")");
409 
410  $this->dbManager->queryOnce("DELETE FROM license_file");
411  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
412  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
413  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
414 
415  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
416  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
417  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
418 
419  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentMonkId)");
420  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
421  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
422 
423  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
424 
425  $this->assertTrue($success, 'cannot run runner');
426  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
427 
428  assertThat($this->getHeartCount($output), equalTo(1));
429 
430  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
431  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
432  assertThat($decisions, is(arrayWithSize(1)));
433 
434  $this->rmRepo();
435  }
436 
439  {
440  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($this->runnerMock);
441  }
442 
445  {
446  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($this->runnerCli);
447  }
448 
449  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($runner)
450  {
451  $this->setUpTables();
452  $this->setUpRepo();
453 
454  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
455  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
456  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
457 
458  $licId1 = $licenseRef1->getId();
459  $licId2 = $licenseRef2->getId();
460  $licId3 = $licenseRef3->getId();
461 
462  $agentNomosId = 6;
463  $agentMonkId = 5;
464  $agentOther = 8;
465  $pfile = 4;
466 
467  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
468 
469  $this->dbManager->queryOnce("DELETE FROM license_file");
470  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
471  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
472  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
473 
474  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
475  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
476  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
477 
478  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentOther)");
479  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
480  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
481 
482  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
483 
484  $this->assertTrue($success, 'cannot run runner');
485  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
486 
487  assertThat($this->getHeartCount($output), equalTo(0));
488 
489  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
490  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
491  assertThat($decisions, is(arrayWithSize(0)));
492 
493  $this->rmRepo();
494  }
495 
498  {
499  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($this->runnerMock);
500  }
501 
504  {
505  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($this->runnerCli);
506  }
507 
508  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($runner)
509  {
510  $this->setUpTables();
511  $this->setUpRepo();
512 
513  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
514  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
515  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
516 
517  $licId1 = $licenseRef1->getId();
518  $licId2 = $licenseRef2->getId();
519  $licId3 = $licenseRef3->getId();
520 
521  $agentNomosId = 6;
522  $agentMonkId = 5;
523  $agentOther = 8;
524  $pfile = 4;
525 
526  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
527  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId3, $licId1, ".LicenseMap::CONCLUSION.")");
528 
529  $this->dbManager->queryOnce("DELETE FROM license_file");
530  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
531  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
532  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
533 
534  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
535  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
536  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
537 
538  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentOther)");
539  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
540  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
541 
542  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
543 
544  $this->assertTrue($success, 'cannot run runner');
545  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
546 
547  assertThat($this->getHeartCount($output), equalTo(1));
548 
549  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
550  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
551  assertThat($decisions, is(arrayWithSize(1)));
552 
553  $this->rmRepo();
554  }
555 
556 
559  {
560  $this->runnerBulkReuseShouldScheduleMonkBulk($this->runnerMock);
561  }
562 
563  private function runnerBulkReuseShouldScheduleMonkBulk($runner)
564  {
565  $this->setUpTables();
566  $this->setUpRepo();
567 
568  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
569  $licId1 = $licenseRef1->getId();
570 
571  $agentBulk = 6;
572  $pfile = 4;
573  $jobId = 16;
574  $otherJob = 333;
575  $groupId = 2;
576 
577  $this->dbManager->queryOnce("DELETE FROM license_file");
578  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentBulk)");
579  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
580  $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)"
581  . " VALUES ($jobId, 2, 'decider', '123456', '2014-08-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
582 
583  $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)"
584  . " VALUES ($jobId-1, $otherJob, 'monkbulk', '123456', '2014-08-07 09:22:22.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
585  $this->dbManager->queryOnce("INSERT INTO job (job_pk, job_queued, job_priority, job_upload_fk, job_user_fk, job_group_fk)"
586  . " VALUES ($otherJob, '2014-08-07 09:22:22.718312+00', 0, 1, 2, $groupId)");
587 
588  $this->dbManager->queryOnce("INSERT INTO license_ref_bulk (lrb_pk, user_fk, group_fk, rf_text, upload_fk, uploadtree_fk) VALUES (123456, 2, $groupId, 'foo bar', 1, 1)");
589  $this->dbManager->queryOnce("INSERT INTO license_set_bulk (lrb_fk, rf_fk, removing) VALUES (123456, $licId1, 'f')");
590 
591  $this->dbManager->queryOnce("INSERT INTO upload_reuse (upload_fk, reused_upload_fk, group_fk, reused_group_fk, reuse_mode)"
592  . " VALUES (2, 1, $groupId, $groupId, 0)");
593 
594  require_once 'HelperPluginMock.php';
595  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=2, $groupId, $jobId, $args='-r4');
596 
597  $this->assertTrue($success, 'cannot run runner');
598  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
599 
600  $this->rmRepo();
601  }
602 
605  {
606  $this->runnerShouldMakeDecisionAsWipIfUnhandledScannerEvent($this->runnerMock);
607  }
608 
609  private function runnerShouldMakeDecisionAsWipIfUnhandledScannerEvent($runner)
610  {
611  $this->setUpTables();
612  $this->setUpRepo();
613  $monkAgentId = 5;
614 
615  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
616  $licId1 = $licenseRef1->getId();
617 
618  $pfile = 4;
619  $jobId = 16;
620  $groupId = 2;
621  $userId = 2;
622  $itemId = 7;
623 
624  $this->dbManager->queryOnce("DELETE FROM license_file");
625 
626  /* insert NoLicenseKnown decisions */
627  $this->dbManager->queryOnce("INSERT INTO clearing_decision (uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)"
628  . " VALUES ($itemId, $pfile, $userId, $groupId, ".DecisionTypes::IDENTIFIED.", ".DecisionScopes::ITEM.", '2015-05-04 11:43:18.276425+02')");
629  $isWipBeforeDecider = $this->clearingDao->isDecisionCheck($itemId, $groupId, DecisionTypes::WIP);
630  assertThat($isWipBeforeDecider, equalTo(false));
631 
632  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$monkAgentId)");
633  $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)"
634  . " VALUES ($jobId, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')");
635 
636  list($success,$output,$retCode) = $runner->run($uploadId=1, $userId, $groupId, $jobId, $args='-r8');
637 
638  $this->assertTrue($success, 'cannot run runner');
639  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
640 
641  $isWip = $this->clearingDao->isDecisionCheck($itemId, $groupId, DecisionTypes::WIP);
642  assertThat($isWip, equalTo(true));
643 
644  $this->rmRepo();
645  }
646 
649  {
650  $this->runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($this->runnerMock);
651  }
652 
653  private function runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($runner)
654  {
655  $this->setUpTables();
656  $this->setUpRepo();
657  $monkAgentId = 5;
658 
659  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
660  $licId1 = $licenseRef1->getId();
661 
662  $pfile = 4;
663  $jobId = 16;
664  $groupId = 2;
665  $userId = 2;
666  $itemId = 7;
667  $itemTreeBounds = new ItemTreeBounds($itemId, 'uploadtree_a', $uploadId=1, 15, 16);
668 
669  $this->dbManager->queryOnce("DELETE FROM license_file");
670 
671  /* insert NoLicenseKnown decisions */
672  $this->dbManager->queryOnce("INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)"
673  . " VALUES (2, $itemId, $pfile, $userId, $groupId, ".DecisionTypes::IRRELEVANT.", ".DecisionScopes::ITEM.", '2015-05-04 11:43:18.276425+02')");
674  $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
675  $lastClearingId = $lastDecision->getClearingId();
676 
677  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$monkAgentId)");
678  $this->dbManager->queryOnce("INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed, jq_log, jq_runonpfile, jq_host, jq_cmd_args)"
679  . " VALUES ($jobId, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')");
680 
681  list($success,$output,$retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, '');
682 
683  $this->assertTrue($success, 'cannot run runner');
684  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
685 
686  $newDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
687  assertThat($newDecision->getClearingId(), equalTo($lastClearingId));
688 
689  $this->rmRepo();
690  }
691 }
Test cases for interaction between decider and scheduler.
testDeciderMockScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision()
testDeciderRealScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision()
setUp()
Setup the objects, database and repository.
testDeciderMockScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision()
testDeciderMockScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision()
getHeartCount($output)
Get the heart count value from the agent output.
rmRepo()
Destroy test repository.
testDeciderMockScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision()
setUpRepo()
Setup test repository.
tearDown()
Destroy objects, database and repository.
setUpTables()
Create test tables required by agent.
testDeciderRealScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision()
testDeciderMockScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision()
testDeciderRealScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision()
testDeciderRealScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision()
testDeciderRealScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision()
Utility functions to process ClearingDecision.
Wrapper class for license map.
Definition: LicenseMap.php:19
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16