14 include_once(__DIR__.
'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
15 include_once(__DIR__.
'/SchedulerTestRunnerCli.php');
29 private $testInstaller;
33 protected function setUp() :
void
35 $this->testDb =
new TestPgDb(
"clixmltest");
36 $this->
dbManager = $this->testDb->getDbManager();
39 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
41 $this->agentDir = dirname(dirname(__DIR__));
44 protected function tearDown() :
void
46 $this->testDb->fullDestruct();
51 private function setUpRepo()
53 $sysConf = $this->testDb->getFossSysConf();
55 $this->testInstaller->init();
56 $this->testInstaller->cpRepo();
57 $this->testInstaller->install($this->agentDir);
60 private function rmRepo()
62 $this->testInstaller->uninstall($this->agentDir);
63 $this->testInstaller->rmRepo();
64 $this->testInstaller->clear();
67 private function setUpTables()
69 $this->testDb->createPlainTables(array(),
true);
70 $this->testDb->createInheritedTables();
71 $this->
dbManager->queryOnce(
"CREATE TABLE copyright_ars () INHERITS (ars_master)");
73 $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_decision_clearing_decision_pk_seq',
'clearing_event_clearing_event_pk_seq'));
74 $this->testDb->createConstraints(array(
'agent_pkey',
'pfile_pkey',
'upload_pkey_idx',
'FileLicense_pkey',
'clearing_event_pkey'));
75 $this->testDb->alterTables(array(
'agent',
'pfile',
'upload',
'ars_master',
'license_ref_bulk',
'license_set_bulk',
'clearing_event',
'clearing_decision',
'license_file',
'highlight'));
77 $this->testDb->insertData(array(
'mimetype_ars',
'pkgagent_ars',
'ununpack_ars',
'decider_ars'),
true,__DIR__.
'/fo_report.sql');
78 $this->testDb->resetSequenceAsMaxOf(
'agent_agent_pk_seq',
'agent',
'agent_pk');
81 private function getHeartCount($output)
84 if (preg_match(
"/.*HEART: ([0-9]*).*/", $output, $matches)) {
85 return intval($matches[1]);
95 $this->runAndTestReport();
101 $this->setUpTables();
105 $this->
dbManager->queryOnce(
"ALTER TABLE uploadtree_a RENAME TO uploadtree_$uploadId", __METHOD__.
'.alterUploadtree');
106 $this->
dbManager->getSingleRow(
"UPDATE upload SET uploadtree_tablename=$1 WHERE upload_pk=$2",
107 array(
"uploadtree_$uploadId",$uploadId),__METHOD__.
'.alterUpload');
109 $this->runAndTestReport($uploadId);
112 public function runAndTestReport($uploadId=1)
114 list($success,$output,$retCode) = $this->runnerCli->run($uploadId, $this->userId, $this->groupId, $jobId=7);
116 assertThat(
'cannot run runner', $success, equalTo(
true));
117 assertThat(
'report failed: "'.$output.
'"', $retCode, equalTo(0));
118 assertThat($this->getHeartCount($output), greaterThan(0));
120 $row = $this->
dbManager->getSingleRow(
"SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = $1", array($jobId),
"reportFileName");
121 assertThat($row, hasKeyValuePair(
'upload_fk', $uploadId));
122 assertThat($row, hasKeyValuePair(
'job_fk', $jobId));
123 $filepath = $row[
'filepath'];
124 assertThat($filepath, endsWith(
'.xml'));
125 assertThat(file_exists($filepath),equalTo(
true));
127 $licenseNameTest =
'Condor/condor-1.1';
128 assertThat(file_get_contents($filepath), stringContainsInOrder($licenseNameTest));
130 $licenseTextTest =
'Here is an alternative license text';
131 assertThat(file_get_contents($filepath), stringContainsInOrder($licenseTextTest));
133 $licenseNameNotTest =
'LGPL-2.1+';
134 assertThat(file_get_contents($filepath), not(stringContainsInOrder($licenseNameNotTest)));
136 $copyrightStatement =
'Copyright (c) 1999 University of Chicago and The University of Southern California';
137 assertThat(file_get_contents($filepath), stringContainsInOrder($copyrightStatement));
139 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
testReportForSpecialUploadtreeTable()
testReportForNormalUploadtreeTable()
fo_dbManager * dbManager
fo_dbManager object
list_t type structure used to keep various lists. (e.g. there are multiple lists).