44 private $uploadPermDao;
46 private $highlightDao;
48 protected function setUp()
50 $this->testDb =
new TestPgDb(
"monkBulk");
51 $this->
dbManager = $this->testDb->getDbManager();
54 $logger =
new Logger(
"MonkBulkTest");
55 $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
61 protected function tearDown()
63 $this->testDb->fullDestruct();
66 $this->licenseDao = null;
67 $this->highlightDao = null;
68 $this->clearingDao = null;
71 private function runBulkMonk($userId = 2, $groupId = 2, $jobId = 1, $bulkId = 3)
73 $sysConf = $this->testDb->getFossSysConf();
75 $agentName =
"monkbulk";
77 $agentDir = dirname(dirname(__DIR__));
79 system(
"install -D $agentDir/VERSION-monkbulk $sysConf/mods-enabled/$agentName/VERSION");
81 $pipeFd = popen(
"echo '0\n$bulkId\n0' | $execDir/$agentName -c $sysConf --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start",
"r");
82 $this->assertTrue($pipeFd !==
false,
'running monk bulk failed');
85 while (($buffer = fgets($pipeFd, 4096)) !==
false) {
88 $retCode = pclose($pipeFd);
90 unlink(
"$sysConf/mods-enabled/$agentName/VERSION");
91 rmdir(
"$sysConf/mods-enabled/$agentName");
92 rmdir(
"$sysConf/mods-enabled");
94 return array($output,$retCode);
97 private function setUpRepo()
99 $sysConf = $this->testDb->getFossSysConf();
101 $confFile = $sysConf.
"/fossology.conf";
102 system(
"touch ".$confFile);
103 $config =
"[FOSSOLOGY]\ndepth = 0\npath = $sysConf/repo\n";
104 file_put_contents($confFile, $config);
106 $testRepoDir = dirname(dirname(dirname(__DIR__))).
"/lib/php/Test/";
107 system(
"cp -a $testRepoDir/repo $sysConf/");
110 private function rmRepo()
112 $sysConf = $this->testDb->getFossSysConf();
113 system(
"rm $sysConf/repo -rf");
114 unlink($sysConf.
"/fossology.conf");
117 private function setUpTables()
119 $this->testDb->createPlainTables(array(
'upload',
'uploadtree',
'license_ref',
'license_ref_bulk',
'license_set_bulk',
120 'clearing_event',
'clearing_decision',
'clearing_decision_event',
'license_file',
'highlight',
'highlight_bulk',
'agent',
'pfile',
'ars_master',
'users'),
false);
121 $this->testDb->createSequences(array(
'agent_agent_pk_seq',
'pfile_pfile_pk_seq',
'upload_upload_pk_seq',
'nomos_ars_ars_pk_seq',
'license_file_fl_pk_seq',
'license_ref_rf_pk_seq',
'license_ref_bulk_lrb_pk_seq',
'clearing_event_clearing_event_pk_seq'),
false);
122 $this->testDb->createViews(array(
'license_file_ref'),
false);
123 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
'FileLicense_pkey',
'clearing_event_pkey',
'license_ref_bulk_pkey',
'license_set_bulk_fkey'),
false);
124 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_ref_bulk',
'license_set_bulk',
'clearing_event',
'license_file',
'highlight'),
false);
125 $this->testDb->createInheritedTables();
126 $this->testDb->insertData(array(
'pfile',
'upload',
'uploadtree_a',
'users'),
false);
127 $this->testDb->insertData_license_ref();
130 private function getHeartCount($output)
133 if (preg_match(
"/.*HEART: ([0-9]*).*/", $output, $matches)) {
134 return intval($matches[1]);
144 $this->setUpTables();
153 $this->setUpTables();
162 $refText =
"The GNU General Public License is a free, copyleft license for software and other kinds of works.";
164 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
166 $this->assertGreaterThan($expected=0, $bulkId);
169 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
171 $this->assertEquals($retCode, 0,
'monk bulk failed: '.$output);
174 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
175 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
177 assertThat(count($relevantDecisionsItem6),is(equalTo(1)));
178 assertThat(count($relevantDecisionsItem7),is(equalTo(1)));
179 assertThat($relevantDecisionsItem6,hasKeyInArray($licenseId));
181 $refSecondText =
"Our General Public Licenses are designed to make sure that you " .
182 "have the freedom to distribute copies of free software";
183 $licenseSecondId = 215;
184 $bulkSecondId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseSecondId => $removing), $refSecondText);
187 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkSecondId);
189 $this->assertEquals($retCode, 0,
'monk bulk failed: '.$output);
190 $relevantDecisionsItemPfile3 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
191 $relevantDecisionsItemPfile4 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
192 assertThat(count($relevantDecisionsItemPfile3), is(equalTo(1)));
194 assertThat(count($relevantDecisionsItemPfile4), is(equalTo(2)));
195 assertThat($relevantDecisionsItemPfile4, hasKeyInArray($licenseSecondId));
201 public function testRunMonkBulkScan()
203 $this->setUpTables();
214 $refText =
"The GNU General Public License is a free, copyleft license for software and other kinds of works.";
216 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId,
217 array($licenseId1 => $removing1, $licenseId2 => $removing2), $refText);
219 $this->assertGreaterThan($expected=0, $bulkId);
222 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
223 $this->assertEquals(6, $this->getHeartCount($output));
226 $this->assertEquals($retCode, 0,
'monk bulk failed: '.$output);
229 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
230 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
232 assertThat(count($relevantDecisionsItem6),is(equalTo(2)));
233 assertThat(count($relevantDecisionsItem7),is(equalTo(2)));
235 assertThat($relevantDecisionsItem6,hasKeyInArray($rfForACE));
237 $clearingEvent = $relevantDecisionsItem6[$rfForACE];
238 $eventId = $clearingEvent->getEventId();
239 $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
241 assertThat(count($bulkHighlights), is(1));
244 $bulkHighlight1 = $bulkHighlights[0];
245 assertThat($bulkHighlight1->getLicenseId(), is(equalTo($licenseId1)));
246 assertThat($bulkHighlight1->getType(), is(equalTo(Highlight::BULK)));
247 assertThat($bulkHighlight1->getStart(), is(3));
248 assertThat($bulkHighlight1->getEnd(), is(103));
251 assertThat($relevantDecisionsItem6,hasKeyInArray($rfForACE));
253 $clearingEvent = $relevantDecisionsItem6[$rfForACE];
254 $eventId = $clearingEvent->getEventId();
255 $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
257 assertThat(count($bulkHighlights), is(1));
260 $bulkHighlight2 = $bulkHighlights[0];
261 assertThat($bulkHighlight2->getLicenseId(), is(equalTo($licenseId2)));
262 assertThat($bulkHighlight2->getType(), is(equalTo(Highlight::BULK)));
263 assertThat($bulkHighlight2->getStart(), is(3));
264 assertThat($bulkHighlight2->getEnd(), is(103));
266 $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
268 assertThat(count($bulkHighlights), is(equalTo(2)));
269 assertThat($bulkHighlights, containsInAnyOrder($bulkHighlight1, $bulkHighlight2));
273 public function testRunMonkBulkScanWithMultipleLicenses()
275 $this->setUpTables();
284 $refText =
"The GNU General Public License is a free, copyleft license for software and other kinds of works.";
286 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
288 $this->assertGreaterThan($expected = 0, $bulkId);
291 list($output, $retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
292 $this->assertEquals(6, $this->getHeartCount($output));
295 $this->assertEquals($retCode, 0,
'monk bulk failed: ' . $output);
298 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
299 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
301 assertThat(count($relevantDecisionsItem6), is(equalTo(1)));
302 assertThat(count($relevantDecisionsItem7), is(equalTo(1)));
304 assertThat($relevantDecisionsItem6, hasKeyInArray($rfForACE));
306 $clearingEvent = $relevantDecisionsItem6[$rfForACE];
307 $eventId = $clearingEvent->getEventId();
308 $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
310 $this->assertEquals(1, count($bulkHighlights));
313 $bulkHighlight = $bulkHighlights[0];
314 $this->assertEquals($licenseId, $bulkHighlight->getLicenseId());
315 $this->assertEquals(Highlight::BULK, $bulkHighlight->getType());
316 $this->assertEquals(3, $bulkHighlight->getStart());
317 $this->assertEquals(103, $bulkHighlight->getEnd());
319 $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
321 $this->assertEquals(1, count($bulkHighlights));
322 $this->assertEquals($bulkHighlight, $bulkHighlights[0]);
328 $this->setUpTables();
337 $refText =
"The GNU General Public License is copyleft license for software and other kinds of works.";
341 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
343 $this->assertGreaterThan($expected=0, $bulkId);
345 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
349 $this->assertEquals($retCode, 0,
"monk bulk failed: $output");
352 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
353 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
355 $this->assertEquals($expected=0, count($relevantDecisionsItem6));
356 $this->assertEquals($expected=0, count($relevantDecisionsItem7));
360 public function testRunMonkBulkScanWithAShortSearch()
362 $this->setUpTables();
371 $refText =
"The GNU";
373 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
375 $this->assertGreaterThan($expected=0, $bulkId);
378 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
382 $this->assertEquals($retCode, 0,
'monk bulk failed: '.$output);
385 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
386 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
388 assertThat(count($relevantDecisionsItem6),is(equalTo(1)));
389 assertThat(count($relevantDecisionsItem7),is(equalTo(1)));
391 assertThat($relevantDecisionsItem6,hasKeyInArray($rfForACE));
393 $clearingEvent = $relevantDecisionsItem6[$rfForACE];
394 $eventId = $clearingEvent->getEventId();
395 $bulkHighlights = $this->highlightDao->getHighlightBulk(6, $eventId);
397 $this->assertEquals(1, count($bulkHighlights));
400 $bulkHighlight = $bulkHighlights[0];
401 $this->assertEquals($licenseId, $bulkHighlight->getLicenseId());
402 $this->assertEquals(Highlight::BULK, $bulkHighlight->getType());
403 $this->assertEquals(3, $bulkHighlight->getStart());
404 $this->assertEquals(10, $bulkHighlight->getEnd());
406 $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
408 $this->assertEquals(1, count($bulkHighlights));
409 $this->assertEquals($bulkHighlight, $bulkHighlights[0]);
415 $this->setUpTables();
426 $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, array($licenseId => $removing), $refText);
428 $this->assertGreaterThan($expected=0, $bulkId);
431 list($output,$retCode) = $this->runBulkMonk($userId, $groupId, $jobId, $bulkId);
435 $this->assertEquals($retCode, 0,
'monk bulk failed: '.$output);
438 $relevantDecisionsItem6 = $this->clearingDao->getRelevantClearingEvents($bounds6, $groupId);
439 $relevantDecisionsItem7 = $this->clearingDao->getRelevantClearingEvents($bounds7, $groupId);
441 assertThat(count($relevantDecisionsItem6),is(equalTo(0)));
442 assertThat(count($relevantDecisionsItem7),is(equalTo(0)));
444 $bulkHighlights = $this->highlightDao->getHighlightBulk(6);
446 assertThat(count($bulkHighlights),is(equalTo(0)));
testRunMonkBulkScanWithBadSearchForDiff()
testRunTwoIndependentMonkBulkScans()
testRunMonkBulkScanWithAnEmptySearchText()
fo_dbManager * dbManager
fo_dbManager object