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 
32 use Mockery as M;
33 
34 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
35 include_once(__DIR__.'/SchedulerTestRunnerCli.php');
36 include_once(__DIR__.'/SchedulerTestRunnerMock.php');
37 
42 class SchedulerTest extends \PHPUnit\Framework\TestCase
43 {
45  private $testDb;
47  private $dbManager;
49  private $testInstaller;
50 
52  private $licenseDao;
54  private $clearingDao;
56  private $clearingDecisionProcessor;
58  private $agentLicenseEventProcessor;
60  private $uploadDao;
62  private $uploadPermDao;
64  private $highlightDao;
66  private $showJobsDao;
68  private $copyrightDao;
70  private $compatibilityDao;
72  private $runnerCli;
74  private $runnerMock;
75 
79  protected function setUp() : void
80  {
81  $this->testDb = new TestPgDb("deciderSched");
82  $this->dbManager = $this->testDb->getDbManager();
83  $this->testDb->setupSysconfig();
84 
85  $this->licenseDao = new LicenseDao($this->dbManager);
86  $logger = M::mock('Monolog\Logger');
87  $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
88  $this->uploadDao = new UploadDao($this->dbManager, $logger, $this->uploadPermDao);
89  $this->copyrightDao = new CopyrightDao($this->dbManager, $this->uploadDao);
90  $this->highlightDao = new HighlightDao($this->dbManager);
91  $agentDao = new AgentDao($this->dbManager, $logger);
92  $this->agentLicenseEventProcessor = new AgentLicenseEventProcessor($this->licenseDao, $agentDao);
93  $clearingEventProcessor = new ClearingEventProcessor();
94  $this->clearingDao = new ClearingDao($this->dbManager, $this->uploadDao);
95  $this->showJobsDao = new ShowJobsDao($this->dbManager, $this->uploadDao);
96  $this->clearingDecisionProcessor = new ClearingDecisionProcessor($this->clearingDao, $this->agentLicenseEventProcessor, $clearingEventProcessor, $this->dbManager);
97  $this->copyrightDao = M::mock(CopyrightDao::class);
98  $this->compatibilityDao = M::mock(CompatibilityDao::class);
99 
100  $this->compatibilityDao->shouldReceive('getCompatibilityForFile')->andReturn(true);
101 
102  global $container;
103  $container = M::mock('ContainerBuilder');
104  $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManager);
105 
106  $this->runnerMock = new SchedulerTestRunnerMock($this->dbManager, $agentDao,
107  $this->clearingDao, $this->uploadDao, $this->highlightDao,
108  $this->showJobsDao, $this->copyrightDao, $this->compatibilityDao,
109  $this->licenseDao, $this->clearingDecisionProcessor,
110  $this->agentLicenseEventProcessor);
111  $this->runnerCli = new SchedulerTestRunnerCli($this->testDb);
112  }
113 
117  protected function tearDown() : void
118  {
119  $this->testDb->fullDestruct();
120  $this->testDb = null;
121  $this->dbManager = null;
122  $this->licenseDao = null;
123  $this->highlightDao = null;
124  $this->showJobsDao = null;
125  $this->clearingDao = null;
126  $this->copyrightDao = null;
127  M::close();
128  }
129 
133  private function setUpRepo()
134  {
135  $sysConf = $this->testDb->getFossSysConf();
136  $this->testInstaller = new TestInstaller($sysConf);
137  $this->testInstaller->init();
138  $this->testInstaller->cpRepo();
139  }
140 
144  private function rmRepo()
145  {
146  $this->testInstaller->rmRepo();
147  $this->testInstaller->clear();
148  }
149 
153  private function setUpTables()
154  {
155  $this->testDb->createPlainTables(array('upload','upload_reuse','uploadtree','uploadtree_a','license_ref','license_ref_bulk',
156  'license_set_bulk','clearing_decision','clearing_decision_event','clearing_event','license_file','highlight',
157  'highlight_keyword','agent','pfile','ars_master','users','group_user_member','license_map','jobqueue','job',
158  'report_info','license_rules'), false);
159  $this->testDb->createSequences(array('agent_agent_pk_seq','pfile_pfile_pk_seq','upload_upload_pk_seq','nomos_ars_ars_pk_seq',
160  'license_file_fl_pk_seq','license_ref_rf_pk_seq','license_ref_bulk_lrb_pk_seq',
161  'clearing_decision_clearing_decision_pk_seq','clearing_event_clearing_event_pk_seq','FileLicense_pkey',
162  'jobqueue_jq_pk_seq','job_job_pk_seq','license_rules_lr_pk_seq'),false);
163  $this->testDb->createViews(array('license_file_ref'),false);
164  $this->testDb->createConstraints(array('agent_pkey','pfile_pkey','upload_pkey_idx','clearing_event_pkey','jobqueue_pkey','license_rules_pkey'),false);
165  $this->testDb->alterTables(array('agent','pfile','upload','ars_master','license_ref_bulk','license_set_bulk','clearing_event',
166  'clearing_decision','license_file', 'license_ref','highlight','jobqueue','job','license_rules'),false);
167  $this->testDb->createInheritedTables();
168  $this->testDb->createInheritedArsTables(array('nomos','monk','copyright'));
169 
170  $this->testDb->insertData(array('pfile','upload','uploadtree_a','users','group_user_member','agent','license_file',
171  'nomos_ars','monk_ars','copyright_ars'), false);
172  $this->testDb->insertData_license_ref(80);
173 
174  $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
175  }
176 
182  private function getHeartCount($output)
183  {
184  $matches = array();
185  if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches)) {
186  return intval($matches[1]);
187  } else {
188  return -1;
189  }
190  }
191 
194  {
195  $this->runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($this->runnerMock);
196  }
197 
200  {
201  $this->runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($this->runnerCli);
202  }
203 
204  private function runnerDeciderScanWithNoEventsAndOnlyNomosShouldNotMakeADecision($runner)
205  {
206  $this->setUpTables();
207  $this->setUpRepo();
208 
209  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
210 
211  $licId1 = $licenseRef1->getId();
212 
213  $agentNomosId = 6;
214  $pfile = 4;
215  $jobId = 15;
216 
217  $this->dbManager->queryOnce("DELETE FROM license_file");
218  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
219  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
220  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
221  $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)"
222  . " VALUES ($jobId, 2, 'decider', '2', '2014-08-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
223 
224  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId, $args='');
225 
226  $this->assertTrue($success, 'cannot run runner');
227  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
228 
229  assertThat($this->getHeartCount($output), equalTo(0));
230 
231  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
232  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
233  assertThat($decisions, is(arrayWithSize(0)));
234 
235  $this->rmRepo();
236  }
237 
240  {
241  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($this->runnerMock);
242  }
243 
246  {
247  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($this->runnerCli);
248  }
249 
250  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkShouldMakeADecision($runner)
251  {
252  $this->setUpTables();
253  $this->setUpRepo();
254 
255  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
256 
257  $licId1 = $licenseRef1->getId();
258 
259  $agentNomosId = 6;
260  $agentMonkId = 5;
261  $pfile = 4;
262 
263  $this->dbManager->queryOnce("DELETE FROM license_file");
264  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
265  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
266  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
267 
268  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
269  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
270  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
271  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
272 
273  $this->assertTrue($success, 'cannot run runner');
274  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
275 
276  assertThat($this->getHeartCount($output), equalTo(1));
277 
278  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
279  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
280  assertThat($decisions, is(arrayWithSize(1)));
281 
282  $this->rmRepo();
283  }
284 
287  {
288  $this->runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($this->runnerMock);
289  }
290 
293  {
294  $this->runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($this->runnerCli);
295  }
296 
297  private function runnerDeciderScanWithNoEventsAndNomosNotContainedInMonkShouldNotMakeADecision($runner)
298  {
299  $this->setUpTables();
300  $this->setUpRepo();
301 
302  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
303 
304  $licId1 = $licenseRef1->getId();
305 
306  $agentNomosId = 6;
307  $agentMonkId = 5;
308  $pfile = 4;
309 
310  $this->dbManager->queryOnce("DELETE FROM license_file");
311  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
312  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
313  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
314 
315  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
316  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
317  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
318 
319  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
320 
321  $this->assertTrue($success, 'cannot run runner');
322  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
323 
324  assertThat($this->getHeartCount($output), equalTo(0));
325 
326  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
327  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
328  assertThat($decisions, is(arrayWithSize(0)));
329 
330  $this->rmRepo();
331  }
332 
335  {
336  $this->runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($this->runnerMock);
337  }
338 
341  {
342  $this->runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($this->runnerCli);
343  }
344 
345  private function runnerDeciderScanWithNoEventsAndNomosContainedInOneOfTwoEqualsMonkShouldMakeADecision($runner)
346  {
347  $this->setUpTables();
348  $this->setUpRepo();
349 
350  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
351 
352  $licId1 = $licenseRef1->getId();
353 
354  $agentNomosId = 6;
355  $agentMonkId = 5;
356  $pfile = 4;
357 
358  $this->dbManager->queryOnce("DELETE FROM license_file");
359  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
360  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
361  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
362 
363  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId1,$pfile,$agentMonkId)");
364  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,11,2)");
365  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
366 
367  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId1,$pfile,$agentMonkId)");
368  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
369  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,18,19)");
370 
371  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
372 
373  $this->assertTrue($success, 'cannot run runner');
374  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
375 
376  assertThat($this->getHeartCount($output), equalTo(1));
377 
378  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
379  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
380  assertThat($decisions, is(arrayWithSize(1)));
381 
382  $this->rmRepo();
383  }
384 
387  {
388  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($this->runnerMock);
389  }
390 
393  {
394  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($this->runnerCli);
395  }
396 
397  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithMappedLicenseShouldMakeADecision($runner)
398  {
399  $this->setUpTables();
400  $this->setUpRepo();
401 
402  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
403  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
404  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
405 
406  $licId1 = $licenseRef1->getId();
407  $licId2 = $licenseRef2->getId();
408  $licId3 = $licenseRef3->getId();
409 
410  $agentNomosId = 6;
411  $agentMonkId = 5;
412  $pfile = 4;
413 
414  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
415  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId3, $licId1, ".LicenseMap::CONCLUSION.")");
416 
417  $this->dbManager->queryOnce("DELETE FROM license_file");
418  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
419  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
420  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
421 
422  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
423  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
424  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
425 
426  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentMonkId)");
427  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
428  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
429 
430  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
431 
432  $this->assertTrue($success, 'cannot run runner');
433  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
434 
435  assertThat($this->getHeartCount($output), equalTo(1));
436 
437  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
438  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
439  assertThat($decisions, is(arrayWithSize(1)));
440 
441  $this->rmRepo();
442  }
443 
446  {
447  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($this->runnerMock);
448  }
449 
452  {
453  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($this->runnerCli);
454  }
455 
456  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchShouldNotMakeADecision($runner)
457  {
458  $this->setUpTables();
459  $this->setUpRepo();
460 
461  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
462  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
463  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
464 
465  $licId1 = $licenseRef1->getId();
466  $licId2 = $licenseRef2->getId();
467  $licId3 = $licenseRef3->getId();
468 
469  $agentNomosId = 6;
470  $agentMonkId = 5;
471  $agentOther = 8;
472  $pfile = 4;
473 
474  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
475 
476  $this->dbManager->queryOnce("DELETE FROM license_file");
477  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
478  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
479  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
480 
481  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
482  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
483  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
484 
485  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentOther)");
486  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
487  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
488 
489  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
490 
491  $this->assertTrue($success, 'cannot run runner');
492  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
493 
494  assertThat($this->getHeartCount($output), equalTo(0));
495 
496  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
497  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
498  assertThat($decisions, is(arrayWithSize(0)));
499 
500  $this->rmRepo();
501  }
502 
505  {
506  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($this->runnerMock);
507  }
508 
511  {
512  $this->runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($this->runnerCli);
513  }
514 
515  private function runnerDeciderScanWithNoEventsAndNomosContainedInMonkWithButWithOtherAgentMatchForSameLicenseShouldMakeADecision($runner)
516  {
517  $this->setUpTables();
518  $this->setUpRepo();
519 
520  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
521  $licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
522  $licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
523 
524  $licId1 = $licenseRef1->getId();
525  $licId2 = $licenseRef2->getId();
526  $licId3 = $licenseRef3->getId();
527 
528  $agentNomosId = 6;
529  $agentMonkId = 5;
530  $agentOther = 8;
531  $pfile = 4;
532 
533  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId2, $licId1, ".LicenseMap::CONCLUSION.")");
534  $this->dbManager->queryOnce("INSERT INTO license_map(rf_fk, rf_parent, usage) VALUES ($licId3, $licId1, ".LicenseMap::CONCLUSION.")");
535 
536  $this->dbManager->queryOnce("DELETE FROM license_file");
537  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentNomosId)");
538  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,10,3)");
539  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,18,3)");
540 
541  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12223,$licId2,$pfile,$agentMonkId)");
542  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,6,2)");
543  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12223,13,19)");
544 
545  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12224,$licId3,$pfile,$agentOther)");
546  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,9,2)");
547  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12224,13,19)");
548 
549  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=6, $groupId=4, $jobId=31, $args="");
550 
551  $this->assertTrue($success, 'cannot run runner');
552  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
553 
554  assertThat($this->getHeartCount($output), equalTo(1));
555 
556  $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
557  $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
558  assertThat($decisions, is(arrayWithSize(1)));
559 
560  $this->rmRepo();
561  }
562 
563 
566  {
567  $this->runnerBulkReuseShouldScheduleMonkBulk($this->runnerMock);
568  }
569 
570  private function runnerBulkReuseShouldScheduleMonkBulk($runner)
571  {
572  $this->setUpTables();
573  $this->setUpRepo();
574 
575  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
576  $licId1 = $licenseRef1->getId();
577 
578  $agentBulk = 6;
579  $pfile = 4;
580  $jobId = 16;
581  $otherJob = 333;
582  $groupId = 2;
583 
584  $this->dbManager->queryOnce("DELETE FROM license_file");
585  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$agentBulk)");
586  $this->dbManager->queryOnce("INSERT INTO highlight (fl_fk,start,len) VALUES(12222,12,3)");
587  $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)"
588  . " VALUES ($jobId, 2, 'decider', '123456', '2014-08-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
589 
590  $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)"
591  . " VALUES ($jobId-1, $otherJob, 'monkbulk', '123456', '2014-08-07 09:22:22.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, NULL)");
592  $this->dbManager->queryOnce("INSERT INTO job (job_pk, job_queued, job_priority, job_upload_fk, job_user_fk, job_group_fk)"
593  . " VALUES ($otherJob, '2014-08-07 09:22:22.718312+00', 0, 1, 2, $groupId)");
594 
595  $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)");
596  $this->dbManager->queryOnce("INSERT INTO license_set_bulk (lrb_fk, rf_fk, removing) VALUES (123456, $licId1, 'f')");
597 
598  $this->dbManager->queryOnce("INSERT INTO upload_reuse (upload_fk, reused_upload_fk, group_fk, reused_group_fk, reuse_mode)"
599  . " VALUES (2, 1, $groupId, $groupId, 0)");
600 
601  require_once 'HelperPluginMock.php';
602  list($success,$output,$retCode) = $runner->run($uploadId=2, $userId=2, $groupId, $jobId, $args='-r4');
603 
604  $this->assertTrue($success, 'cannot run runner');
605  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
606 
607  $this->rmRepo();
608  }
609 
612  {
613  $this->runnerShouldMakeDecisionAsWipIfUnhandledScannerEvent($this->runnerMock);
614  }
615 
616  private function runnerShouldMakeDecisionAsWipIfUnhandledScannerEvent($runner)
617  {
618  $this->setUpTables();
619  $this->setUpRepo();
620  $monkAgentId = 5;
621 
622  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
623  $licId1 = $licenseRef1->getId();
624 
625  $pfile = 4;
626  $jobId = 16;
627  $groupId = 2;
628  $userId = 2;
629  $itemId = 7;
630 
631  $this->dbManager->queryOnce("DELETE FROM license_file");
632 
633  /* insert NoLicenseKnown decisions */
634  $this->dbManager->queryOnce("INSERT INTO clearing_decision (uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)"
635  . " VALUES ($itemId, $pfile, $userId, $groupId, ".DecisionTypes::IDENTIFIED.", ".DecisionScopes::ITEM.", '2015-05-04 11:43:18.276425+02')");
636  $isWipBeforeDecider = $this->clearingDao->isDecisionCheck($itemId, $groupId, DecisionTypes::WIP);
637  assertThat($isWipBeforeDecider, equalTo(false));
638 
639  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$monkAgentId)");
640  $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)"
641  . " VALUES ($jobId, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')");
642 
643  list($success,$output,$retCode) = $runner->run($uploadId=1, $userId, $groupId, $jobId, $args='-r8');
644 
645  $this->assertTrue($success, 'cannot run runner');
646  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
647 
648  $isWip = $this->clearingDao->isDecisionCheck($itemId, $groupId, DecisionTypes::WIP);
649  assertThat($isWip, equalTo(true));
650 
651  $this->rmRepo();
652  }
653 
656  {
657  $this->runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($this->runnerMock);
658  }
659 
660  private function runnerDeciderRealShouldMakeNoDecisionForIrrelevantFiles($runner)
661  {
662  $this->setUpTables();
663  $this->setUpRepo();
664  $monkAgentId = 5;
665 
666  $licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
667  $licId1 = $licenseRef1->getId();
668 
669  $pfile = 4;
670  $jobId = 16;
671  $groupId = 2;
672  $userId = 2;
673  $itemId = 7;
674  $itemTreeBounds = new ItemTreeBounds($itemId, 'uploadtree_a', $uploadId=1, 15, 16);
675 
676  $this->dbManager->queryOnce("DELETE FROM license_file");
677 
678  /* insert NoLicenseKnown decisions */
679  $this->dbManager->queryOnce("INSERT INTO clearing_decision (clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, scope, date_added)"
680  . " VALUES (2, $itemId, $pfile, $userId, $groupId, ".DecisionTypes::IRRELEVANT.", ".DecisionScopes::ITEM.", '2015-05-04 11:43:18.276425+02')");
681  $lastDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
682  $lastClearingId = $lastDecision->getClearingId();
683 
684  $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,$licId1,$pfile,$monkAgentId)");
685  $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)"
686  . " VALUES ($jobId, 2, 'decider', '2', '2015-06-07 09:57:27.718312+00', NULL, '', 0, NULL, 6, NULL, NULL, NULL, '-r8')");
687 
688  list($success,$output,$retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, '');
689 
690  $this->assertTrue($success, 'cannot run runner');
691  $this->assertEquals($retCode, 0, 'decider failed (did you make test?): '.$output);
692 
693  $newDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId);
694  assertThat($newDecision->getClearingId(), equalTo($lastClearingId));
695 
696  $this->rmRepo();
697  }
698 }
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