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: © 2024 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
12 require_once "SchedulerTestRunnerCli.php";
13 require_once "SchedulerTestRunnerScheduler.php";
14 
26 use Monolog\Logger;
27 
32 class CompatibilityScheduledTest extends \PHPUnit\Framework\TestCase
33 {
34 
38  private $testDb;
42  private $dbManager;
46  private $agentDao;
50  private $licenseDao;
54  private $testInstaller;
58  private $uploadDao;
62  private $uploadPermDao;
66  private $compatibilityDao;
70  private $cliRunner;
74  private $schedulerRunner;
78  private $logger;
79 
84  protected function setUp() : void
85  {
86  $this->testDb = new TestPgDb("compSched" . time());
87  $this->dbManager = $this->testDb->getDbManager();
88 
89  $this->logger = new Logger("CompatibilitySchedulerTest");
90 
91  $this->agentDao = new AgentDao($this->dbManager, $this->logger);
92  $this->licenseDao = new LicenseDao($this->dbManager);
93  $this->uploadPermDao = \Mockery::mock(UploadPermissionDao::class);
94  $this->uploadDao = new UploadDao($this->dbManager, $this->logger,
95  $this->uploadPermDao);
96 
97  $this->cliRunner = new SchedulerTestRunnerCli($this->testDb);
98  $this->schedulerRunner = new SchedulerTestRunnerScheduler($this->testDb);
99  }
100 
105  protected function tearDown() : void
106  {
107  $this->testDb->fullDestruct();
108  $this->testDb = null;
109  $this->dbManager = null;
110  $this->licenseDao = null;
111  }
112 
116  private function setUpRepo()
117  {
118  $sysConf = $this->testDb->getFossSysConf();
119  $this->testInstaller = new TestInstaller($sysConf);
120  $this->testInstaller->init();
121  $this->testInstaller->cpRepo();
122  }
123 
127  private function rmRepo()
128  {
129  $this->testInstaller->rmRepo();
130  $this->testInstaller->clear();
131  }
132 
136  private function setUpTables()
137  {
138  $this->testDb->createPlainTables(
139  array(
140  'agent',
141  'uploadtree',
142  'upload',
143  'pfile',
144  'users',
145  'groups',
146  'ars_master',
147  'license_ref',
148  'license_file',
149  'comp_result',
150  'license_rules',
151  'upload_clearing_license'
152  ));
153  $this->testDb->createInheritedTables(
154  array(
155  'license_candidate',
156  'nomos_ars',
157  'monk_ars'
158  ));
159  $this->testDb->createSequences(
160  array(
161  'agent_agent_pk_seq',
162  'upload_upload_pk_seq',
163  'pfile_pfile_pk_seq',
164  'users_user_pk_seq',
165  'group_group_pk_seq',
166  'nomos_ars_ars_pk_seq',
167  'license_ref_rf_pk_seq',
168  'license_file_fl_pk_seq',
169  'license_rules_lr_pk_seq'
170  ));
171  $this->testDb->createConstraints(
172  array(
173  'agent_pkey',
174  'upload_pkey_idx',
175  'pfile_pkey',
176  'user_pkey',
177  'license_file_pkey',
178  'license_rules_pkey'
179  ));
180  $this->testDb->alterTables(
181  array(
182  'agent',
183  'pfile',
184  'upload',
185  'ars_master',
186  'users',
187  'groups',
188  'license_ref',
189  'license_file',
190  'license_rules'
191  ));
192  $this->testDb->createInheritedTables(array(
193  'uploadtree_a'
194  ));
195 
196  $this->testDb->insertData(
197  array(
198  'agent',
199  'upload',
200  'pfile',
201  'uploadtree_a',
202  'users',
203  'license_ref',
204  'license_file',
205  'license_rules',
206  'nomos_ars',
207  'monk_ars',
208  'upload_clearing_license'
209  ), false);
210 
211  $this->testDb->getDbManager()->getSingleRow(
212  "UPDATE ars_master SET upload_fk = $1 WHERE ars_pk = $2",
213  [3, 10], "ars_fix"
214  );
215  $this->testDb->getDbManager()->getSingleRow(
216  "UPDATE ars_master SET upload_fk = $1 WHERE ars_pk = $2",
217  [3, 12], "ars_fix"
218  );
219  $this->testDb->getDbManager()->getSingleRow(
220  "SELECT setval('agent_agent_pk_seq', 300)", [], "agent_seq"
221  );
222  }
223 
234  public function testRun()
235  {
236  $this->setUpTables();
237  $this->setUpRepo();
238 
239  $this->compatibilityDao = new CompatibilityDao($this->dbManager, $this->logger,
240  $this->licenseDao, $this->agentDao);
241 
242  $uploadId = 3;
243  list ($success, $output, $retCode) = $this->schedulerRunner->run($uploadId);
244  $this->rmRepo();
245  $this->assertTrue($success, 'running compatibility failed');
246  $this->assertEquals($retCode, 0, "compatibility failed ($retCode): $output");
247 
248  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
249 
250  // Compare LicenseB and LicenseD which are incompatible by id
251  $this->assertFalse($this->compatibilityDao->getCompatibilityForFile(
252  $this->uploadDao->getItemTreeBounds(40, $uploadTreeTableName),
253  $this->licenseDao->getLicenseById(202)->getShortName())
254  );
255  $this->assertFalse($this->compatibilityDao->getCompatibilityForFile(
256  $this->uploadDao->getItemTreeBounds(40, $uploadTreeTableName),
257  $this->licenseDao->getLicenseById(498)->getShortName())
258  );
259 
260  // Compare LicenseD and LicenseG which are compatible by type
261  $this->assertTrue($this->compatibilityDao->getCompatibilityForFile(
262  $this->uploadDao->getItemTreeBounds(38, $uploadTreeTableName),
263  $this->licenseDao->getLicenseById(498)->getShortName())
264  );
265 
266  // Compare LicenseD and LicenseF which are compatible by type
267  $this->assertTrue($this->compatibilityDao->getCompatibilityForFile(
268  $this->uploadDao->getItemTreeBounds(42, $uploadTreeTableName),
269  $this->licenseDao->getLicenseById(544)->getShortName())
270  );
271  }
272 }
Functional test cases for compatibility agent using scheduler.
tearDown()
Destruct the objects initialized during setUp()
rmRepo()
Remove the test repo.
setUp()
Setup the test cases and initialize the objects.
setUpTables()
Setup tables required by copyright agent.
setUpRepo()
Setup test repo mimicking install.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16