FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_cp2foss.php
1 <?php
2 /*
3  Copyright (C) 2012-2014 Hewlett-Packard Development Company, L.P.
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  */
18 
23 require_once("./test_common.php");
24 
28 class test_cp2foss extends \PHPUnit\Framework\TestCase {
29 
30  public $DB_NAME;
31  public $PG_CONN;
32  public $DB_COMMAND;
33 
34  // fossology_testconfig is the temporary system configuration directory
35  // created by the src/testing/db/create_test_database.php script.
36  // It is initialized via the Makefile and passed in via the
37  // FOSSOLOGY_TESTCONFIG environment variable.
38  public $fossology_testconfig;
39 
40  // scheduler_path is the absolute path to the scheduler binary
41  public $scheduler_path;
42 
43  // cp2foss_path is the absolute path to the cp2foss binary
44  public $cp2foss_path;
45 
46  /* initialization */
47 
48  // this method is run once for the entire test class, before any of the
49  // test methods are executed.
50  public static function setUpBeforeClass() {
51 
52  global $fossology_testconfig;
53  global $scheduler_path;
54  global $cp2foss_path;
55  global $PG_CONN;
56 
57  $fossology_testconfig = getenv('FOSSOLOGY_TESTCONFIG');
59  if (empty($fossology_testconfig)) $fossology_testconfig = "/usr/local/etc/fossology/";
60  fwrite(STDOUT, __METHOD__ . " got fossology_testconfig = '$fossology_testconfig'\n");
61 
62  $cp2foss_path = "cp2foss";
63 
64  /* locate the scheduler binary */
65  $scheduler_path = $fossology_testconfig . "/mods-enabled/scheduler/agent/fo_scheduler";
66  if (!is_executable($scheduler_path)) {
67  print "Error: Scheduler path '$scheduler_path' is not executable!\n";
68  exit(1);
69  }
70 
71  /* invoke the scheduler */
72  $scheduler_cmd = "$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
73  print "DEBUG: Starting scheduler with '$scheduler_cmd'\n";
74  exec($scheduler_cmd, $output, $return_var);
75  //print_r($output);
76  if ( $return_var != 0 ) {
77  print "Error: Could not start scheduler '$scheduler_path'\n";
78  print "$output\n";
79  exit(1);
80  }
81 
82  $PG_CONN = connect_to_DB($fossology_testconfig); // connect db
83  add_user("fossy", "fossy"); // add account fossy/fossy
84 
85  print "\nStarting functional test for cp2foss. \n";
86 
87  }
88 
99  global $fossology_testconfig;
100  global $cp2foss_path;
101  global $PG_CONN;
102 
103  fwrite(STDOUT, " ----> Running " . __METHOD__ . "\n");
104 
105  $test_dbh = $PG_CONN;
106 
107  $auth = "--username fossy --password fossy -c $fossology_testconfig -s ";
109  $out = "";
110  $pos = 0;
111  $command = "$cp2foss_path $auth ./test_cp2foss.php";
112  fwrite(STDOUT, "DEBUG: test_upload_from_server executing '$command'\n");
113  $last = exec("$command 2>&1", $out, $rtn);
114  $repo_string = "Uploading to folder: 'Software Repository'";
115  $repo_pos = strpos($out[1], $repo_string);
116  $output_msg_count = count($out);
117  print "DEBUG: \$this->assertGreaterThan(0, $repo_pos);\n";
118  $this->assertGreaterThan(0, $repo_pos);
119  print "DEBUG: \$this->assertEquals(4, $output_msg_count);\n";
120  $this->assertEquals(4, $output_msg_count);
121  $upload_id = 0;
123  if ($out && $out[3]) {
124  $upload_id = get_upload_id($out[3]);
125  print "DEBUG: Upload_id is $upload_id\n";
126  }
127  else {
128  print "DEBUG: Did not get an upload_id!\n";
129  $this->assertFalse(TRUE);
130  }
131  $agent_status = 0;
132  $agent_status = check_agent_status($test_dbh,"ununpack", $upload_id);
133  $this->assertEquals(1, $agent_status);
134 
136  $out = "";
137  $pos = 0;
138  $command = "$cp2foss_path $auth ./";
139  fwrite(STDOUT, "DEBUG: test_upload_from_server executing '$command'\n");
140  $last = exec("$command 2>&1", $out, $rtn);
141  $repo_string = "Uploading to folder: 'Software Repository'";
142  $repo_pos = strpos($out[1], $repo_string);
143  $output_msg_count = count($out);
144  $this->assertGreaterThan(0, $repo_pos);
145  $this->assertEquals(4, $output_msg_count);
146  $upload_id = 0;
148  if ($out && $out[3]) {
149  $upload_id = get_upload_id($out[3]);
150  } else $this->assertFalse(TRUE);
151  $agent_status = 0;
152  $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id);
153  $this->assertEquals(1, $agent_status);
154 
156  $out = "";
157  $pos = 0;
158  $upload_path = "upload_path";
159  $command = "$cp2foss_path $auth ./ -f $upload_path -d upload_des -q all -v";
160  fwrite(STDOUT, "DEBUG: Executing '$command'\n");
161  $last = exec("$command 2>&1", $out, $rtn);
162  $repo_string = "Uploading to folder: '/$upload_path'";
163  $repo_pos = strpos($out[7], $repo_string);
164  $output_msg_count = count($out);
165  print "DEBUG: \$this->assertGreaterThan(0, $repo_pos)\n";
166  $this->assertGreaterThan(0, $repo_pos);
167  $scheduled_agent_info_1 = "agent_pkgagent is queued to run on";
168  $scheduled_agent_info_2 = "agent_nomos is queued to run on";
169  $scheduled_agent_info_3 = "agent_monk is queued to run on";
170  $scheduled_agent_info_4 = "agent_mimetype is queued to run on";
171  $scheduled_agent_info_5 = "agent_copyright is queued to run on";
172  $pos = false;
173  $pos = strpos($out[$output_msg_count - 1], $scheduled_agent_info_1);
174  $this->assertEquals(0, $pos);
175  $pos = false;
176  $pos = strpos($out[$output_msg_count - 2], $scheduled_agent_info_2);
177  $this->assertEquals(0, $pos);
178  $pos = false;
179  $pos = strpos($out[$output_msg_count - 3], $scheduled_agent_info_3);
180  $this->assertEquals(0, $pos);
181  $pos = false;
182  $pos = strpos($out[$output_msg_count - 4], $scheduled_agent_info_4);
183  $this->assertEquals(0, $pos);
184  $pos = false;
185  $pos = strpos($out[$output_msg_count - 5], $scheduled_agent_info_5);
186  $this->assertEquals(0, $pos);
187  $upload_id = 0;
188 
190  if ($out && $out[11]) {
191  $upload_id = get_upload_id($out[11]);
192  } else $this->assertFalse(TRUE);
193  $agent_status = 0;
194  $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id);
195  $this->assertEquals(1, $agent_status);
196  $agent_status = 0;
197  $agent_status = check_agent_status($test_dbh, "copyright", $upload_id);
198  $this->assertEquals(1, $agent_status);
199  $agent_status = 0;
200  $agent_status = check_agent_status($test_dbh, "nomos", $upload_id);
201  $this->assertEquals(1, $agent_status);
202  $agent_status = 0;
203  $agent_status = check_agent_status($test_dbh, "mimetype", $upload_id);
204  $this->assertEquals(1, $agent_status);
205  $agent_status = 0;
206  $agent_status = check_agent_status($test_dbh, "pkgagent", $upload_id);
207  $this->assertEquals(1, $agent_status);
208 
211  $out = "";
212  $pos = 0;
213  $command = "$cp2foss_path $auth -q all -A -f test/exclude -n 'test exclue dir' -d 'test des exclude dir' -X .svn ./ -v";
214  fwrite(STDOUT, "DEBUG: Running $command\n");
215  $last = exec("$command 2>&1", $out, $rtn);
216  $upload_id = 0;
218  if ($out && $out[23]) {
219  $upload_id = get_upload_id($out[23]);
220  } else $this->assertFalse(TRUE);
221  $agent_status = 0;
222  $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id);
223  $this->assertEquals(1, $agent_status);
224 
225  pg_close($test_dbh);
226 
227  fwrite(STDOUT,"DEBUG: Done running " . __METHOD__ . "\n");
228  }
229 
230  // this method is run once for the entire test class, after all of the
231  // test methods are executed.
232  public static function tearDownAfterClass() {
233 
234  global $fossology_testconfig;
235  global $scheduler_path;
236 
237  // stop the scheduler
238  print "Stopping the scheduler\n";
239  $scheduler_cmd = "$scheduler_path -k -c $fossology_testconfig";
240  exec($scheduler_cmd, $output, $return_var);
241  if ( $return_var != 0 ) {
242  print "Error: Could not stop scheduler via '$scheduler_cmd'\n";
243  print "$output\n";
244 # exit(1);
245  }
246 
247  // time to drop the database
248 
249  print "End of functional tests for cp2foss \n";
250 
251  }
252 
253 }
254 
255 ?>
static setUpBeforeClass()
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
test_upload_from_server()
upload from server
test cli cp2foss