FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
schedulerTest.php
Go to the documentation of this file.
1 <?php
2 /*
3 Copyright (C) 2015, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
28 namespace Fossology\Report\Test;
29 
33 
34 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
35 include_once(__DIR__.'/SchedulerTestRunnerCli.php');
36 
41 class SchedulerTest extends \PHPUnit\Framework\TestCase
42 {
46  private $userId = 2;
50  private $groupId = 2;
51 
55  private $testDb;
59  private $dbManager;
63  private $testInstaller;
67  private $runnerCli;
68 
72  public function setUp()
73  {
74  $this->testDb = new TestPgDb("report".time());
75  $this->dbManager = $this->testDb->getDbManager();
76 
77  $this->runnerCli = new SchedulerTestRunnerCli($this->testDb);
78  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
79  }
80 
84  public function tearDown()
85  {
86  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
87  // $this->testDb->fullDestruct();
88  $this->testDb = null;
89  $this->dbManager = null;
90  }
91 
95  private function setUpRepo()
96  {
97  $sysConf = $this->testDb->getFossSysConf();
98  $this->testInstaller = new TestInstaller($sysConf);
99  $this->testInstaller->init();
100  $this->testInstaller->cpRepo();
101  }
102 
106  private function rmRepo()
107  {
108  $this->testInstaller->rmRepo();
109  $this->testInstaller->clear();
110  }
111 
115  private function setUpTables()
116  {
117  $this->testDb->createSequences(array(),true);
118  $this->testDb->createPlainTables(array(),true);
119  $this->testDb->createInheritedTables();
120  $this->testDb->createInheritedArsTables(array('copyright','monk','nomos'));
121  $this->testDb->createConstraints(array('agent_pkey','pfile_pkey','upload_pkey_idx',
122  'FileLicense_pkey','clearing_event_pkey'),false);
123  $this->testDb->alterTables(array('agent','pfile','upload','ars_master',
124  'license_ref_bulk','clearing_event','clearing_decision','license_file','highlight'),false);
125 
126  $this->testDb->insertData(array('mimetype_ars','pkgagent_ars','ununpack_ars','decider_ars'),true,__DIR__.'/fo_report.sql');
127  // $this->testDb->insertData_license_ref();
128  $this->testDb->resetSequenceAsMaxOf('agent_agent_pk_seq', 'agent', 'agent_pk');
129  }
130 
134  private function getHeartCount($output)
135  {
136  $matches = array();
137  if (preg_match("/.*HEART: ([0-9]*).*/", $output, $matches)) {
138  return intval($matches[1]);
139  } else {
140  return -1;
141  }
142  }
143 
153  public function testReport()
154  {
155  $this->setUpTables();
156  $this->setUpRepo();
157 
158  list($success,$output,$retCode) = $this->runnerCli->run($uploadId=1, $this->userId, $this->groupId, $jobId=7);
159 
160  assertThat('cannot run runner', $success, equalTo(true));
161  assertThat( 'report failed: "'.$output.'"', $retCode, equalTo(0));
162  assertThat($this->getHeartCount($output), greaterThan(0));
163 
164  $row = $this->dbManager->getSingleRow("SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = $1", array($jobId), "reportFileName");
165  assertThat($row, hasKeyValuePair('upload_fk', $uploadId));
166  assertThat($row, hasKeyValuePair('job_fk', $jobId));
167  $filepath = $row['filepath'];
168  // $comparisionFile = __DIR__.'/ReportTestfiles.tar_clearing_report_Mon_May_04_05_2015_11_53_18.docx';
169  // assertThat(is_file($comparisionFile),equalTo(true));
170  // assertThat(filesize($filepath), closeTo(filesize($comparisionFile),5));
171 
172  $this->rmRepo();
173  }
174 }
setUpTables()
Setup tables required by the agent.
getHeartCount($output)
Get the heart count from agent.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
Namespace for report related tests.
Test for unified report.