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: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
17 namespace Fossology\Report\Test;
18 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 include_once(__DIR__.'/SchedulerTestRunnerCli.php');
25 
30 class SchedulerTest extends \PHPUnit\Framework\TestCase
31 {
35  private $userId = 2;
39  private $groupId = 2;
40 
44  private $testDb;
48  private $dbManager;
52  private $testInstaller;
56  private $runnerCli;
57 
61  public function setUp() : void
62  {
63  $this->testDb = new TestPgDb("report".time());
64  $this->dbManager = $this->testDb->getDbManager();
65 
66  $this->runnerCli = new SchedulerTestRunnerCli($this->testDb);
67  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
68  }
69 
73  public function tearDown() : void
74  {
75  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
76  // $this->testDb->fullDestruct();
77  $this->testDb = null;
78  $this->dbManager = null;
79  }
80 
84  private function setUpRepo()
85  {
86  $sysConf = $this->testDb->getFossSysConf();
87  $this->testInstaller = new TestInstaller($sysConf);
88  $this->testInstaller->init();
89  $this->testInstaller->cpRepo();
90  }
91 
95  private function rmRepo()
96  {
97  $this->testInstaller->rmRepo();
98  $this->testInstaller->clear();
99  }
100 
104  private function setUpTables()
105  {
106  $this->testDb->createSequences(array(),true);
107  $this->testDb->createPlainTables(array(),true);
108  $this->testDb->createInheritedTables();
109  $this->testDb->createInheritedArsTables(array('copyright','monk','nomos'));
110  $this->testDb->createConstraints(array('agent_pkey','pfile_pkey','upload_pkey_idx',
111  'FileLicense_pkey','clearing_event_pkey'),false);
112  $this->testDb->alterTables(array('agent','pfile','upload','ars_master',
113  'license_ref_bulk','clearing_event','clearing_decision','license_file','highlight'),false);
114 
115  $this->testDb->insertData(array('mimetype_ars','pkgagent_ars','ununpack_ars','decider_ars'),true,__DIR__.'/fo_report.sql');
116  // $this->testDb->insertData_license_ref();
117  $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
118  }
119 
123  private function getHeartCount($output)
124  {
125  $matches = array();
126  if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches)) {
127  return intval($matches[1]);
128  } else {
129  return -1;
130  }
131  }
132 
142  public function testReport()
143  {
144  $this->setUpTables();
145  $this->setUpRepo();
146 
147  list($success,$output,$retCode) = $this->runnerCli->run($uploadId=1, $this->userId, $this->groupId, $jobId=7);
148 
149  assertThat('cannot run runner', $success, equalTo(true));
150  assertThat( 'report failed: "'.$output.'"', $retCode, equalTo(0));
151  assertThat($this->getHeartCount($output), greaterThan(0));
152 
153  $row = $this->dbManager->getSingleRow("SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = $1", array($jobId), "reportFileName");
154  assertThat($row, hasKeyValuePair('upload_fk', $uploadId));
155  assertThat($row, hasKeyValuePair('job_fk', $jobId));
156  $filepath = $row['filepath'];
157  // $comparisionFile = __DIR__.'/ReportTestfiles.tar_clearing_report_Mon_May_04_05_2015_11_53_18.docx';
158  // assertThat(is_file($comparisionFile),equalTo(true));
159  // assertThat(filesize($filepath), closeTo(filesize($comparisionFile),5));
160 
161  $this->rmRepo();
162  }
163 }
setUpTables()
Setup tables required by the agent.
getHeartCount($output)
Get the heart count from agent.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Namespace for report related tests.
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308