12 require_once
"SchedulerTestRunnerCli.php";
13 require_once
"SchedulerTestRunnerScheduler.php";
47 private $testInstaller;
55 private $uploadPermDao;
63 private $schedulerRunner;
67 private $regressionFile;
73 protected function setUp() : void
75 $this->regressionFile = __DIR__ . DIRECTORY_SEPARATOR .
"regexTest.json";
77 $this->testDb =
new TestPgDb(
"ojoSched" . time());
78 $this->
dbManager = $this->testDb->getDbManager();
80 $logger =
new Logger(
"OjoSchedulerTest");
83 $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
85 $this->uploadPermDao);
97 $this->testDb->fullDestruct();
100 $this->licenseDao =
null;
108 $sysConf = $this->testDb->getFossSysConf();
110 $this->testInstaller->init();
111 $this->testInstaller->cpRepo();
119 $this->testInstaller->rmRepo();
120 $this->testInstaller->clear();
128 $this->testDb->createPlainTables(
141 $this->testDb->createInheritedTables(
145 $this->testDb->createSequences(
147 'agent_agent_pk_seq',
148 'upload_upload_pk_seq',
149 'pfile_pfile_pk_seq',
151 'group_group_pk_seq',
152 'nomos_ars_ars_pk_seq',
153 'license_ref_rf_pk_seq',
154 'license_file_fl_pk_seq',
155 'license_file_fl_pk_seq'
157 $this->testDb->createConstraints(
165 $this->testDb->alterTables(
176 $this->testDb->createInheritedTables(array(
180 $this->testDb->insertData(
198 foreach ($resultArray as $result) {
199 if (strcmp($result[
"license"], $licenseName) === 0) {
222 $leftFile = basename($left[
"file"]);
223 $rightFile = basename($right[
"file"]);
224 if (strcmp($leftFile, $rightFile) !== 0) {
225 return strcmp($leftFile, $rightFile);
227 if ($left[
"results"] ===
null) {
228 if ($right[
"results"] ===
null) {
233 if ($right[
"results"] ===
null) {
236 if (count($left[
"results"]) !== count($right[
"results"])) {
237 return count($left[
"results"]) - count($right[
"results"]);
239 foreach ($left[
"results"] as $key => $result) {
240 if (strcmp($result[
"license"], $right[
"results"][$key][
"license"]) !== 0) {
241 return strcmp($result[
"license"], $right[$key][
"license"]);
255 return strcmp($left[
"file"], $right[
"file"]);
272 list ($success, $output, $retCode) = $this->schedulerRunner->run($uploadId);
274 $this->assertTrue($success,
'running ojo failed');
275 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
277 $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
278 $uploadParent = $this->uploadDao->getItemTreeBounds(460, $uploadTreeTableName);
279 $licenseMatches = $this->licenseDao->getLicensesPerFileNameForAgentId(
282 $this->assertGreaterThan(8, count($licenseMatches), $output);
283 $this->assertContains(
"Classpath-exception-2.0",
284 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_WITH_Classpath-exception-2.0"][
"scanResults"]);
285 $this->assertContains(
"GPL-2.0-only",
286 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_WITH_Classpath-exception-2.0"][
"scanResults"]);
288 $this->assertContains(
"GPL-2.0-only",
289 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_OR_MIT"][
"scanResults"]);
290 $this->assertContains(
"MIT",
291 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_OR_MIT"][
"scanResults"]);
293 $this->assertContains(
"GPL-2.0-or-later",
294 $licenseMatches[
"spdx.tar/spdx/GPL-2.0-or-later"][
"scanResults"]);
296 $this->assertContains(
"GPL-2.0-only",
297 $licenseMatches[
"spdx.tar/spdx/GPL-2.0-only"][
"scanResults"]);
299 $this->assertContains(
"LGPL-2.1-or-later",
300 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
301 $this->assertContains(
"GPL-2.0-only",
302 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
303 $this->assertContains(
"MIT",
304 $licenseMatches[
"spdx.tar/spdx/GPL-2.0_AND_LGPL-2.1-or-later_OR_MIT"][
"scanResults"]);
306 $this->assertContains(
"GPL-2.0-or-later",
307 $licenseMatches[
"spdx.tar/spdx/GPL-2.0+"][
"scanResults"]);
309 $this->assertContains(
"GPL-2.0-only",
310 $licenseMatches[
"spdx.tar/spdx/GPL-2.0"][
"scanResults"]);
322 $testFile = dirname(__DIR__, 3).
"/nomos/agent_tests/testdata/NomosTestfiles/SPDX/MPL-2.0_AND_BSD-2-Clause_AND_MIT_OR_Apache-2.0.txt";
324 $args =
"--json $testFile";
325 list ($success, $output, $retCode) = $this->cliRunner->run($args);
326 $this->assertTrue($success,
'running ojo failed');
327 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
329 $this->assertJson($output);
330 $result = json_decode($output,
true);
331 $resultArray = $result[0][
"results"];
333 $this->assertEquals($testFile, $result[0][
"file"]);
335 "MPL-2.0-no-copyleft-exception"));
355 $testDir = dirname(__DIR__, 3).
"/nomos/agent_tests/testdata/NomosTestfiles/SPDX";
357 $args =
"--json --directory $testDir";
358 list ($success, $output, $retCode) = $this->cliRunner->run($args);
359 $this->assertTrue($success,
'running ojo failed');
360 $this->assertEquals($retCode, 0,
"ojo failed ($retCode): $output");
361 $this->assertJson($output);
364 $jsonFromFile = json_decode(file_get_contents($this->regressionFile),
true);
366 $jsonFromOutput = json_decode($output,
true);
369 usort($jsonFromFile, array(
'OjoScheduledTest',
'compareMatchesFiles'));
370 usort($jsonFromOutput, array(
'OjoScheduledTest',
'compareMatchesFiles'));
373 $jsonDiff = array_udiff($jsonFromFile, $jsonFromOutput,
374 array(
'OjoScheduledTest',
'compareMatches'));
376 $outputDiff =
"JSON does not match regression test file.\n";
377 $outputDiff .=
"Following are the results not in regression test file.\n";
378 $outputDiff .= print_r($jsonDiff,
true);
380 $this->assertEquals(0, count($jsonDiff), $outputDiff);
Handles scheduler interaction.
Handles scheduler interaction.
Functional test cases for ojo agent using scheduler.
resultArrayContainsLicense($resultArray, $licenseName)
compareMatches($left, $right)
Compare two matches from OJO (slow)
setUpRepo()
Setup test repo mimicking install.
rmRepo()
Remove the test repo.
setUp()
Setup the test cases and initialize the objects.
compareMatchesFiles($left, $right)
setUpTables()
Setup tables required by copyright agent.
testCli()
Run the test for CLI.
regressionTest()
Run a regression test for OJO.
tearDown()
Destruct the objects initialized during setUp()
fo_dbManager * dbManager
fo_dbManager object