25 include_once(__DIR__.
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
26 include_once(__DIR__.
'/SchedulerTestRunnerCli.php');
63 protected function setUp() : void
65 $this->testDb =
new TestPgDb(
"spdx2test");
66 $this->
dbManager = $this->testDb->getDbManager();
69 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
71 $this->agentDir = dirname(__DIR__, 4) .
'/build/src/spdx2';
79 $this->testDb->fullDestruct();
89 $sysConf = $this->testDb->getFossSysConf();
91 $this->testInstaller->init();
92 $this->testInstaller->cpRepo();
93 $this->testInstaller->install($this->agentDir);
101 $this->testInstaller->uninstall($this->agentDir);
102 $this->testInstaller->rmRepo();
103 $this->testInstaller->clear();
111 $this->testDb->createPlainTables(array(),
true);
112 $this->testDb->createInheritedTables();
113 $this->
dbManager->queryOnce(
"CREATE TABLE copyright_ars () INHERITS (ars_master)");
115 $this->testDb->createSequences(array(
'agent_agent_pk_seq',
'pfile_pfile_pk_seq',
'upload_upload_pk_seq',
116 'nomos_ars_ars_pk_seq',
'license_file_fl_pk_seq',
'license_ref_rf_pk_seq',
117 'license_ref_bulk_lrb_pk_seq',
'clearing_decision_clearing_decision_pk_seq',
118 'clearing_event_clearing_event_pk_seq'));
119 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
120 'FileLicense_pkey',
'clearing_event_pkey'));
121 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_ref_bulk',
'license_set_bulk',
122 'clearing_event',
'clearing_decision',
'license_file',
'license_ref',
'highlight'));
124 $this->testDb->insertData(array(
'mimetype_ars',
'pkgagent_ars',
'ununpack_ars',
'decider_ars'),
true,__DIR__.
'/fo_report.sql');
125 $this->testDb->resetSequenceAsMaxOf(
'agent_agent_pk_seq',
'agent',
'agent_pk');
134 if (preg_match(
"/.*HEART: ([0-9]*).*/", $output, $matches)) {
135 return intval($matches[1]);
163 $this->
dbManager->queryOnce(
"ALTER TABLE uploadtree_a RENAME TO uploadtree_$uploadId", __METHOD__.
'.alterUploadtree');
164 $this->
dbManager->getSingleRow(
"UPDATE upload SET uploadtree_tablename=$1 WHERE upload_pk=$2",
165 array(
"uploadtree_$uploadId",$uploadId),__METHOD__.
'.alterUpload');
177 list($success,$output,$retCode) = $this->runnerCli->run($uploadId, $this->userId, $this->groupId, $jobId);
179 assertThat(
'cannot run runner', $success, equalTo(
true));
180 assertThat(
'report failed: "'.$output.
'"', $retCode, equalTo(0));
192 $row = $this->
dbManager->getSingleRow(
"SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = $1", array($jobId),
194 assertThat($row, hasKeyValuePair(
'upload_fk', $uploadId));
195 assertThat($row, hasKeyValuePair(
'job_fk', $jobId));
196 $filepath = $row[
'filepath'];
197 assertThat($filepath, endsWith(
'.rdf'));
198 $this->assertFileExists($filepath,
"RDF report does not exists.");
220 $copyrightStatement =
'Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved';
221 assertThat(file_get_contents($filepath), stringContainsInOrder($copyrightStatement));
223 $email =
'condor-admin@cs.wisc.edu';
224 assertThat(file_get_contents($filepath), not(stringContainsInOrder($email)));
226 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
240 $verification = exec(
"java -jar $toolJarFile Verify $filepath");
241 assertThat($verification,equalTo(
'This SPDX Document is valid.'));
260 $jarFileBasename =
'tools-java-'.$version.
'-jar-with-dependencies.jar';
261 $jarFile = __DIR__.
'/'.$jarFileBasename;
262 if (!file_exists($jarFile)) {
263 $zipFile = __DIR__ .
"/spdx-tools-java-$version.zip";
264 file_put_contents($zipFile, fopen(
"https://github.com/spdx/tools-java/releases/download/$tag/tools-java-$version.zip",
'r'));
265 $zip =
new ZipArchive;
266 if ($zip->open($zipFile) === TRUE) {
267 $zip->extractTo(__DIR__, [$jarFileBasename]);
272 $this->assertFileExists($jarFile,
'could not download SPDXTools');
283 exec(
'which java', $lines, $returnVar);
284 $this->assertEquals(0,$returnVar,
'java required for this test');
Handles scheduler interaction.
Tests for SPDX2 agent and scheduler interaction.
setUpRepo()
Setup test repo.
testSpdxForSpecialUploadtreeTable()
Test SPDX2 agent for RDF.
verifyJavaIsInstalled()
Verify if java is intalled on the system.
setUpTables()
Setup tables required for test.
verifyRdf($filepath)
Use SPDX toolkit to verify RDF file format.
pullSpdxTools()
Pull SPDX toolkit from github if not found.
runAndTestReportRDF($uploadId=1)
Create RDF report and check it.
runJobFromJobque($uploadId, $jobId)
Run jobs from queue.
tearDown()
Teardown test db.
testSpdxForNormalUploadtreeTable()
Test SPDX2 agent for RDF.
rmRepo()
Teardown test repo.
getHeartCount($output)
Get the heart count from agent.
getReportFilepathFromJob($uploadId, $jobId)
Get the file path for report from DB.
fo_dbManager * dbManager
fo_dbManager object
Namespace to hold test cases for SPDX2 agent.