25 include_once(__DIR__.
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
26 include_once(__DIR__.
'/SchedulerTestRunnerCli.php');
35 public $assertCountBefore;
66 protected function setUp() : void
68 $this->testDb =
new TestPgDb(
"spdxtest");
69 $this->
dbManager = $this->testDb->getDbManager();
72 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
74 $this->agentDir = dirname(__DIR__, 4) .
'/build/src/spdx';
82 $this->testDb->fullDestruct();
92 $sysConf = $this->testDb->getFossSysConf();
94 $this->testInstaller->init();
95 $this->testInstaller->cpRepo();
96 $this->testInstaller->install($this->agentDir);
104 $this->testInstaller->uninstall($this->agentDir);
105 $this->testInstaller->rmRepo();
106 $this->testInstaller->clear();
114 $this->testDb->createPlainTables(array(),
true);
115 $this->testDb->createInheritedTables();
116 $this->
dbManager->queryOnce(
"CREATE TABLE copyright_ars () INHERITS (ars_master)");
118 $this->testDb->createSequences(array(
'agent_agent_pk_seq',
'pfile_pfile_pk_seq',
'upload_upload_pk_seq',
119 'nomos_ars_ars_pk_seq',
'license_file_fl_pk_seq',
'license_ref_rf_pk_seq',
120 'license_ref_bulk_lrb_pk_seq',
'clearing_decision_clearing_decision_pk_seq',
121 'clearing_event_clearing_event_pk_seq'));
122 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
123 'FileLicense_pkey',
'clearing_event_pkey'));
124 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_ref_bulk',
'license_set_bulk',
125 'clearing_event',
'clearing_decision',
'license_file',
'license_ref',
'highlight'));
127 $this->testDb->insertData(array(
'mimetype_ars',
'pkgagent_ars',
'ununpack_ars',
'decider_ars'),
true,__DIR__.
'/fo_report.sql');
128 $this->testDb->resetSequenceAsMaxOf(
'agent_agent_pk_seq',
'agent',
'agent_pk');
137 if (preg_match(
"/.*HEART: ([0-9]*).*/", $output, $matches)) {
138 return intval($matches[1]);
166 $this->
dbManager->queryOnce(
"ALTER TABLE uploadtree_a RENAME TO uploadtree_$uploadId", __METHOD__.
'.alterUploadtree');
167 $this->
dbManager->getSingleRow(
"UPDATE upload SET uploadtree_tablename=$1 WHERE upload_pk=$2",
168 array(
"uploadtree_$uploadId",$uploadId),__METHOD__.
'.alterUpload');
180 list($success,$output,$retCode) = $this->runnerCli->run($uploadId, $this->userId, $this->groupId, $jobId);
182 assertThat(
'cannot run runner', $success, equalTo(
true));
183 assertThat(
'report failed: "'.$output.
'"', $retCode, equalTo(0));
195 $row = $this->
dbManager->getSingleRow(
"SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = $1", array($jobId),
197 assertThat($row, hasKeyValuePair(
'upload_fk', $uploadId));
198 assertThat($row, hasKeyValuePair(
'job_fk', $jobId));
199 $filepath = $row[
'filepath'];
200 assertThat($filepath, endsWith(
'.rdf'));
201 $this->assertFileExists($filepath,
"RDF report does not exists.");
223 $copyrightStatement =
'Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved';
224 assertThat(file_get_contents($filepath), stringContainsInOrder($copyrightStatement));
226 $email =
'condor-admin@cs.wisc.edu';
227 assertThat(file_get_contents($filepath), not(stringContainsInOrder($email)));
229 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
243 $verification = exec(
"java -jar $toolJarFile Verify $filepath");
244 assertThat($verification,equalTo(
'This SPDX Document is valid.'));
263 $jarFileBasename =
'tools-java-'.$version.
'-jar-with-dependencies.jar';
264 $jarFile = __DIR__.
'/'.$jarFileBasename;
265 if (!file_exists($jarFile)) {
266 $zipFile = __DIR__ .
"/spdx-tools-java-$version.zip";
267 file_put_contents($zipFile, fopen(
"https://github.com/spdx/tools-java/releases/download/$tag/tools-java-$version.zip",
'r'));
268 $zip =
new ZipArchive;
269 if ($zip->open($zipFile) === TRUE) {
270 $zip->extractTo(__DIR__, [$jarFileBasename]);
275 $this->assertFileExists($jarFile,
'could not download SPDXTools');
286 exec(
'which java', $lines, $returnVar);
287 $this->assertEquals(0,$returnVar,
'java required for this test');
Handles scheduler interaction.
Tests for Spdx agent and scheduler interaction.
testSpdxForNormalUploadtreeTable()
Test spdx agent for RDF.
setUpTables()
Setup tables required for test.
setUpRepo()
Setup test repo.
testSpdxForSpecialUploadtreeTable()
Test spdx agent for RDF.
pullSpdxTools()
Pull SPDX toolkit from github if not found.
getReportFilepathFromJob($uploadId, $jobId)
Get the file path for report from DB.
getHeartCount($output)
Get the heart count from agent.
tearDown()
Teardown test db.
verifyRdf($filepath)
Use SPDX toolkit to verify RDF file format.
verifyJavaIsInstalled()
Verify if java is intalled on the system.
runJobFromJobque($uploadId, $jobId)
Run jobs from queue.
rmRepo()
Teardown test repo.
runAndTestReportRDF($uploadId=1)
Create RDF report and check it.
fo_dbManager * dbManager
fo_dbManager object
Namespace to hold test cases for spdx agent.