20 require_once
"./SchedulerTestRunnerCli.php";
21 require_once
"./SchedulerTestRunnerScheduler.php";
55 private $testInstaller;
63 private $uploadPermDao;
71 private $schedulerRunner;
75 private $regressionFile;
83 $this->regressionFile =
"regexTest.json";
85 $this->testDb =
new TestPgDb(
"ojoSched" . time());
86 $this->
dbManager = $this->testDb->getDbManager();
88 $logger =
new Logger(
"OjoSchedulerTest");
91 $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
93 $this->uploadPermDao);
105 $this->testDb->fullDestruct();
106 $this->testDb = null;
108 $this->licenseDao = null;
116 $sysConf = $this->testDb->getFossSysConf();
118 $this->testInstaller->init();
119 $this->testInstaller->cpRepo();
127 $this->testInstaller->rmRepo();
128 $this->testInstaller->clear();
136 $this->testDb->createPlainTables(
148 $this->testDb->createSequences(
150 'agent_agent_pk_seq',
151 'upload_upload_pk_seq',
152 'pfile_pfile_pk_seq',
154 'nomos_ars_ars_pk_seq',
155 'license_ref_rf_pk_seq',
156 'license_file_fl_pk_seq',
157 'license_file_fl_pk_seq' 159 $this->testDb->createConstraints(
167 $this->testDb->alterTables(
177 $this->testDb->createInheritedTables(array(
181 $this->testDb->insertData(
199 foreach ($resultArray as $result) {
200 if (strcmp($result[
"license"], $licenseName) === 0) {
223 if (strcmp($left[
"file"], $right[
"file"]) !== 0) {
224 return strcmp($left[
"file"], $right[
"file"]);
226 if ($left[
"results"] === null) {
227 if ($right[
"results"] === null) {
232 if ($right[
"results"] === null) {
235 if (count($left[
"results"]) !== count($right[
"results"])) {
236 return count($left[
"results"]) - count($right[
"results"]);
238 foreach ($left[
"results"] as $key => $result) {
239 if (strcmp($result[
"license"], $right[
"results"][$key][
"license"]) !== 0) {
240 return strcmp($result[
"license"], $right[$key][
"license"]);
254 return strcmp($left[
"file"], $right[
"file"]);
271 list ($success, $output, $retCode) = $this->schedulerRunner->run($uploadId);
273 $this->assertTrue($success,
'running ojo failed');
274 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
276 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
277 $uploadParent = $this->uploadDao->getItemTreeBounds(460, $uploadTreeTableName);
278 $licenseMatches = $this->licenseDao->getLicensesPerFileNameForAgentId(
281 $this->assertGreaterThan(8, count($licenseMatches), $output);
282 $this->assertContains(
"Classpath-exception-2.0",
283 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_WITH_Classpath-exception-2.0"][
"scanResults"]);
284 $this->assertContains(
"GPL-2.0-only",
285 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_WITH_Classpath-exception-2.0"][
"scanResults"]);
287 $this->assertContains(
"GPL-2.0-only",
288 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_OR_MIT"][
"scanResults"]);
289 $this->assertContains(
"MIT",
290 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_OR_MIT"][
"scanResults"]);
292 $this->assertContains(
"GPL-2.0-or-later",
293 $licenseMatches[
"spdx.tar/spdx/GPL-2.0-or-later"][
"scanResults"]);
295 $this->assertContains(
"GPL-2.0-only",
296 $licenseMatches[
"spdx.tar/spdx/GPL-2.0-only"][
"scanResults"]);
298 $this->assertContains(
"LGPL-2.1-or-later",
299 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
300 $this->assertContains(
"GPL-2.0-only",
301 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
302 $this->assertContains(
"MIT",
303 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
305 $this->assertContains(
"GPL-2.0-or-later",
306 $licenseMatches[
"spdx.tar/spdx/GPL-2.0+"][
"scanResults"]);
308 $this->assertContains(
"GPL-2.0-only",
309 $licenseMatches[
"spdx.tar/spdx/GPL-2.0"][
"scanResults"]);
321 $testFile =
"../../../nomos/agent_tests/testdata/NomosTestfiles/SPDX/MPL-2.0_AND_BSD-2-Clause_AND_MIT_OR_Apache-2.0.txt";
323 $args =
"--json $testFile";
324 list ($success, $output, $retCode) = $this->cliRunner->run($args);
325 $this->assertTrue($success,
'running ojo failed');
326 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
328 $this->assertJson($output);
329 $result = json_decode($output,
true);
330 $resultArray = $result[0][
"results"];
332 $this->assertEquals($testFile, $result[0][
"file"]);
334 "MPL-2.0-no-copyleft-exception"));
354 $testDir =
"../../../nomos/agent_tests/testdata/NomosTestfiles/SPDX";
356 $args =
"--json --directory $testDir";
357 list ($success, $output, $retCode) = $this->cliRunner->run($args);
358 $this->assertTrue($success,
'running ojo failed');
359 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
360 $this->assertJson($output);
363 $jsonFromFile = json_decode(file_get_contents($this->regressionFile),
true);
365 $jsonFromOutput = json_decode($output,
true);
368 usort($jsonFromFile, array(
'OjoScheduledTest',
'compareMatchesFiles'));
369 usort($jsonFromOutput, array(
'OjoScheduledTest',
'compareMatchesFiles'));
372 $jsonDiff = array_udiff($jsonFromFile, $jsonFromOutput,
373 array(
'OjoScheduledTest',
'compareMatches'));
375 $outputDiff =
"JSON does not match regression test file.\n";
376 $outputDiff .=
"Following are the results not in regression test file.\n";
377 $outputDiff .= print_r($jsonDiff,
true);
379 $this->assertEquals(0, count($jsonDiff), $outputDiff);
Handles scheduler interaction.
setUpTables()
Setup tables required by copyright agent.
setUp()
Setup the test cases and initialize the objects.
resultArrayContainsLicense($resultArray, $licenseName)
testCli()
Run the test for CLI.
compareMatches($left, $right)
Compare two matches from OJO (slow)
Functional test cases for ojo agent using scheduler.
tearDown()
Destruct the objects initialized during setUp()
compareMatchesFiles($left, $right)
regressionTest()
Run a regression test for OJO.
rmRepo()
Remove the test repo.
fo_dbManager * dbManager
fo_dbManager object
setUpRepo()
Setup test repo mimicking install.
Handles scheduler interaction.