FOSSology  4.4.0
Open Source License Compliance by Open Source Software
schedulerTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014-2015,2022, Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
20 use Monolog\Logger;
21 
22 if (!function_exists('Traceback_uri'))
23 {
24  function Traceback_uri(){
25  return 'Traceback_uri_if_desired';
26  }
27 }
28 
33 class schedulerTest extends \PHPUnit\Framework\TestCase
34 {
38  private $testDb;
42  private $testInstaller;
43 
47  private $dbManager;
51  private $licenseDao;
55  private $uploadDao;
59  private $uploadPermDao;
63  private $copyrightDao;
64 
69  protected function setUp() : void
70  {
71  $this->testDb = new TestPgDb("copyrightSched".time());
72  $this->dbManager = $this->testDb->getDbManager();
73 
74  $logger = new Logger("CopyrightSchedulerTest");
75 
76  $this->licenseDao = new LicenseDao($this->dbManager);
77  $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
78  $this->uploadDao = new UploadDao($this->dbManager, $logger, $this->uploadPermDao);
79  $this->copyrightDao = new CopyrightDao($this->dbManager, $this->uploadDao);
80  }
81 
86  protected function tearDown() : void
87  {
88  $this->testDb->fullDestruct();
89  $this->testDb = null;
90  $this->dbManager = null;
91  $this->licenseDao = null;
92  }
93 
104  private function runCopyright($uploadId)
105  {
106  $sysConf = $this->testDb->getFossSysConf();
107 
108  $agentName = "copyright";
109 
110  $agentDir = dirname(__DIR__, 4) . '/build/src/copyright';
111  $execDir = "$agentDir/agent";
112  system("install -D $agentDir/VERSION-copyright $sysConf/mods-enabled/$agentName/VERSION");
113  system("install -D $agentDir/agent/copyright.conf $sysConf/mods-enabled/$agentName/agent/copyright.conf");
114  $pCmd = "echo $uploadId | $execDir/$agentName -c $sysConf --scheduler_start";
115  $pipeFd = popen($pCmd, "r");
116  $this->assertTrue($pipeFd !== false, 'running copyright failed');
117 
118  $output = "";
119  while (($buffer = fgets($pipeFd, 4096)) !== false) {
120  $output .= $buffer;
121  }
122  $retCode = pclose($pipeFd);
123 
124  unlink("$sysConf/mods-enabled/$agentName/VERSION");
125  unlink("$sysConf/mods-enabled/$agentName/agent/copyright.conf");
126  rmdir("$sysConf/mods-enabled/$agentName/agent/");
127  rmdir("$sysConf/mods-enabled/$agentName");
128  rmdir("$sysConf/mods-enabled");
129  unlink($sysConf."/fossology.conf");
130 
131  $this->assertEquals($retCode, 0, "copyright failed ($retCode): $output [$pCmd]");
132  return $output;
133  }
134 
138  private function setUpRepo()
139  {
140  $sysConf = $this->testDb->getFossSysConf();
141 
142  $this->testInstaller = new TestInstaller($sysConf);
143  $this->testInstaller->init();
144  $this->testInstaller->cpRepo();
145  }
146 
150  private function rmRepo()
151  {
152  $sysConf = $this->testDb->getFossSysConf();
153  system("rm $sysConf/repo -rf");
154  }
155 
159  private function setUpTables()
160  {
161  $this->testDb->createPlainTables(array('agent','uploadtree','upload','pfile','users','bucketpool','mimetype','ars_master','author','copyright_event'));
162  $this->testDb->createSequences(array('agent_agent_pk_seq','upload_upload_pk_seq','pfile_pfile_pk_seq','users_user_pk_seq','nomos_ars_ars_pk_seq'));
163  $this->testDb->createConstraints(array('agent_pkey','upload_pkey_idx','pfile_pkey','user_pkey'));
164  $this->testDb->alterTables(array('agent','pfile','upload','ars_master','users'));
165  $this->testDb->createInheritedTables(array('uploadtree_a'));
166 
167  $this->testDb->insertData(array('upload','pfile','uploadtree_a','bucketpool','mimetype','users'), false);
168  }
169 
178  public function testRun()
179  {
180  $this->setUpTables();
181  $this->setUpRepo();
182  $output = $this->runCopyright($uploadId=1);
183  $this->rmRepo();
184 
185  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
186  $matches = $this->copyrightDao->getAllEntries("copyright", $uploadId, $uploadTreeTableName);
187  $this->assertGreaterThan($expected=5, count($matches), $output);
188  }
189 
190 }
testRun()
Run the test.
runCopyright($uploadId)
Run copyright on a given upload id.
setUp()
Setup the test cases and initialize the objects.
tearDown()
Destruct the objects initialized during setUp()
rmRepo()
Remove the test repo.
setUpRepo()
Setup test repo mimicking install.
setUpTables()
Setup tables required by copyright agent.
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16