Commit 0c8a11ef5f762cf9e3ad633690859ebb49c37d44

Authored by Benjamin Renard
1 parent 61193896

Tests suits for WebServices (#6535)

php/WebServices/Tests/Base/TestAbstract.php 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +<?php
  2 +
  3 +abstract class TestAbstract
  4 +{
  5 + abstract public function getAPI();
  6 +
  7 + abstract public function getParams();
  8 +
  9 + abstract public function getDescription();
  10 +
  11 + abstract protected function checkRESTResult($result);
  12 +
  13 + abstract protected function checkSOAPResult($result);
  14 +
  15 + protected function needRESTAuth() {
  16 + return FALSE;
  17 + }
  18 +
  19 + public function getWSTypes() {
  20 + return array("REST", "SOAP");
  21 + }
  22 +
  23 + public function runREST($base_url) {
  24 + $params = $this->getParams();
  25 + if ($this->needRESTAuth()) {
  26 + $url = $base_url . '/php/rest/auth.php';
  27 + $curl = curl_init();
  28 + curl_setopt($curl, CURLOPT_URL, $url);
  29 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  30 + $token = curl_exec($curl);
  31 + if (curl_errno($curl) || empty($token)) {
  32 + echo "[ERROR] Cannot retrieve REST token".PHP_EOL;
  33 + return array(
  34 + 'success' => FALSE,
  35 + 'message' => "Cannot retrieve REST token",
  36 + );
  37 + }
  38 + curl_close($curl);
  39 + $params['token'] = $token;
  40 + }
  41 +
  42 + $url = $base_url . '/php/rest/' . $this->getAPI() . '.php';
  43 + if (!empty($params)) {
  44 + $url .= "?" . http_build_query($params);
  45 + }
  46 + $curl = curl_init();
  47 + //ProxyUtils::addProxyForCurl($curl);
  48 + curl_setopt($curl, CURLOPT_URL, $url);
  49 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  50 + $result = curl_exec($curl);
  51 + if (curl_errno($curl)) {
  52 + return array(
  53 + 'success' => FALSE,
  54 + 'message' => 'Request error: '.curl_error($curl),
  55 + );
  56 + }
  57 + $exec_time = curl_getinfo($curl, CURLINFO_TOTAL_TIME);
  58 + curl_close($curl);
  59 + return $this->checkRESTResult($result);
  60 + }
  61 +
  62 + public function runSOAP($base_url) {
  63 + $wsdl_url = $base_url . '/help/Methods_AMDA.xml';
  64 + try {
  65 + $client = new SoapClient($wsdl_url, array(
  66 + //'proxy_host' => "localhost",
  67 + //'proxy_port' => 8080,
  68 + //'proxy_login' => "some_name",
  69 + //'proxy_password' => "some_password"
  70 + ));
  71 + $result = $client->__soapCall($this->getAPI(), array($this->getParams()));
  72 + }
  73 + catch (SoapFault $exception) {
  74 + return array(
  75 + 'success' => FALSE,
  76 + 'message' => 'SOAP error: '.$exception->getMessage(),
  77 + );
  78 + }
  79 + return $this->checkSOAPResult($result);
  80 + }
  81 +}
  82 +
  83 +?>
... ...
php/WebServices/Tests/Base/TestDownloadBase.php 0 → 100644
... ... @@ -0,0 +1,134 @@
  1 +<?php
  2 +
  3 +require_once "TestAbstract.php";
  4 +
  5 +abstract class TestDownloadBase extends TestAbstract
  6 +{
  7 + abstract protected function checkResultInfo($info);
  8 +
  9 + protected function checkRESTResult($result) {
  10 + if (empty($result)) {
  11 + return array(
  12 + 'success' => FALSE,
  13 + 'message' => 'Empty result',
  14 + );
  15 + }
  16 + $json_res = json_decode($result);
  17 + if (!$json_res) {
  18 + return array(
  19 + 'success' => FALSE,
  20 + 'message' => 'Result is not in JSON format',
  21 + );
  22 + }
  23 + $info = $this->getResultInfo($json_res);
  24 + if (!$info['success']) {
  25 + return $info;
  26 + }
  27 + return $this->checkResultInfo($info);
  28 + }
  29 +
  30 + protected function checkSOAPResult($result) {
  31 + $info = $this->getResultInfo($result);
  32 + if (!$info['success']) {
  33 + return $info;
  34 + }
  35 + return $this->checkResultInfo($info);
  36 + }
  37 +
  38 + private function gz_get_contents($path) {
  39 + $gzip = file_get_contents($path);
  40 + $rest = substr($gzip, -4);
  41 + $unpacked = unpack("V", $rest);
  42 + $uncompressedSize = end($unpacked);
  43 +
  44 + // read the gzipped content, specifying the exact length
  45 + $handle = gzopen($path, "rb");
  46 + $contents = gzread($handle, $uncompressedSize);
  47 + gzclose($handle);
  48 +
  49 + return $contents;
  50 + }
  51 +
  52 + private function isCompressed($path) {
  53 + return (substr($path, -3) == ".gz");
  54 + }
  55 +
  56 + private function isVOTable($path, $compressed) {
  57 + if ($compressed) {
  58 + $path = substr($path, 0, strlen($path)-3);
  59 + }
  60 + return (substr($path, -4) == ".vot");
  61 + }
  62 +
  63 + private function getResultInfo($obj) {
  64 + if (empty($obj) || empty($obj->status)) {
  65 + return array(
  66 + 'success' => FALSE,
  67 + 'message' => 'Bad result format',
  68 + );
  69 + }
  70 +
  71 + if ($obj->status != 'done') {
  72 + return array(
  73 + 'success' => FALSE,
  74 + 'message' => 'Status is not done ('.$obj->status.')',
  75 + );
  76 + }
  77 +
  78 + if (empty($obj->dataFileURLs)) {
  79 + return array(
  80 + 'success' => FALSE,
  81 + 'message' => 'Missing data file URL in result',
  82 + );
  83 + }
  84 +
  85 + $result = array(
  86 + 'success' => TRUE,
  87 + );
  88 +
  89 + $result['compressed'] = $this->isCompressed($obj->dataFileURLs);
  90 +
  91 + if ($result['compressed']) {
  92 + $data = $this->gz_get_contents($obj->dataFileURLs);
  93 + }
  94 + else {
  95 + $data = file_get_contents($obj->dataFileURLs);
  96 + }
  97 + if (!$data) {
  98 + return array(
  99 + 'success' => FALSE,
  100 + 'message' => 'Cannot load data result file',
  101 + );
  102 + }
  103 +
  104 + $result['isVOTable'] = $this->isVOTable($obj->dataFileURLs, $result['compressed']);
  105 +
  106 + $request_info = array();
  107 +
  108 + foreach (explode(PHP_EOL, $data) as $line) {
  109 + $pattern = $result['isVOTable'] ? "REQUEST_" : "# REQUEST_";
  110 + if (strpos($line, $pattern) === 0) {
  111 + $sep_pos = strpos($line, ":");
  112 + if ($result['isVOTable'])
  113 + $key = trim(substr($line, 0, $sep_pos));
  114 + else
  115 + $key = trim(substr($line, 2, $sep_pos-2));
  116 + $value = trim(substr($line, $sep_pos+1));
  117 + $request_info[$key] = $value;
  118 + }
  119 + }
  120 +
  121 + $result['parameters'] = array();
  122 + if (!empty($request_info['REQUEST_OUTPUT_PARAMS'])) {
  123 + $result['parameters'] = explode(',',$request_info['REQUEST_OUTPUT_PARAMS']);
  124 + }
  125 +
  126 + $result['structure'] = !empty($request_info['REQUEST_STRUCTURE']) ? $request_info['REQUEST_STRUCTURE'] : '';
  127 + $result['timeFormat'] = !empty($request_info['REQUEST_TIME_FORMAT']) ? $request_info['REQUEST_TIME_FORMAT'] : '';
  128 + $result['sampling'] = !empty($request_info['REQUEST_TIME_RESOLUTION']) ? doubleval($request_info['REQUEST_TIME_RESOLUTION']) : NULL;
  129 +
  130 + return $result;
  131 + }
  132 +}
  133 +
  134 +?>
... ...
php/WebServices/Tests/Base/TestsSuite.php 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +<?php
  2 +
  3 +function cmpTest($a, $b) {
  4 + if ($a == $b) {
  5 + return 0;
  6 + }
  7 +
  8 + list($prefix_a, $number_a) = sscanf($a, "%[A-Za-z]_%[0-9]");
  9 + list($prefix_b, $number_b) = sscanf($b, "%[A-Za-z]_%[0-9]");
  10 +
  11 + if (empty($number_a)) {
  12 + return -1;
  13 + }
  14 + else if (empty($number_b)) {
  15 + return 1;
  16 + }
  17 +
  18 + return (intval($number_a) < intval($number_b)) ? -1 : 1;
  19 +}
  20 +
  21 +class TestsSuite {
  22 + private $tests = NULL;
  23 +
  24 + function __construct() {
  25 + $this->tests = array();
  26 + }
  27 +
  28 + public function init($tests_path) {
  29 + $this->tests = array();
  30 + $files = array_diff(scandir($tests_path), array('.', '..'));
  31 + foreach ($files as $file) {
  32 + $name = basename($file, ".php");
  33 + require_once($tests_path."/".$file);
  34 + $this->tests[$name] = new $name();
  35 + }
  36 + uksort($this->tests, "cmpTest");
  37 + }
  38 +
  39 + public function getDescriptions() {
  40 + return $this->run(TRUE);
  41 + }
  42 +
  43 + public function run($descriptionsOnly = FALSE) {
  44 + $results = array();
  45 + foreach ($this->tests as $name => $test) {
  46 + $res = array();
  47 + foreach ($test->getWSTypes() as $ws_type) {
  48 + $res = array(
  49 + "name" => $name,
  50 + "description" => $test->getDescription(),
  51 + "type" => $ws_type,
  52 + "api" => $test->getAPI(),
  53 + "params" => $test->getParams(),
  54 + "status" => NULL,
  55 + );
  56 + if (!$descriptionsOnly) {
  57 + $runFunc = "run".$ws_type;
  58 + $res["status"] = $test->$runFunc(BASE_URL);
  59 + }
  60 + $results[] = $res;
  61 + }
  62 +
  63 + }
  64 + return $results;
  65 + }
  66 +}
  67 +
  68 +?>
... ...
php/WebServices/Tests/Suite/TestGetDataset_10.php 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetDataset_10 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getDataset";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "datasetID" => "mex-els-all",
  20 + );
  21 + }
  22 +
  23 + public function getDescription() {
  24 + return "Get mex-els-all data. No sampling.";
  25 + }
  26 +
  27 + protected function checkResultInfo($info) {
  28 + if ($info['structure'] != 'all-in-one-file-refparam') {
  29 + return array(
  30 + 'success' => FALSE,
  31 + 'message' => 'Bad file structure ('.$info['structure'].')',
  32 + );
  33 + }
  34 + if ($info['timeFormat'] != 'ISO 8601') {
  35 + return array(
  36 + 'success' => FALSE,
  37 + 'message' => 'Bad time format ('.$info['timeFormat'].')',
  38 + );
  39 + }
  40 + if (!in_array('mex_els_spec_0', $info['parameters'])) {
  41 + return array(
  42 + 'success' => FALSE,
  43 + 'message' => 'Missing mex_els_spec_0 in result file',
  44 + );
  45 + }
  46 + if (!in_array('mex_els_spec_sum', $info['parameters'])) {
  47 + return array(
  48 + 'success' => FALSE,
  49 + 'message' => 'Missing mex_els_spec_sum in result file',
  50 + );
  51 + }
  52 + return array(
  53 + 'success' => TRUE,
  54 + );
  55 + }
  56 +}
  57 +
  58 +?>
... ...
php/WebServices/Tests/Suite/TestGetDataset_11.php 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetDataset_11 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getDataset";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "datasetID" => "mex-els-all",
  20 + "sampling" => 60,
  21 + );
  22 + }
  23 +
  24 + public function getDescription() {
  25 + return "Get mex-els-all data. Sampling 60s.";
  26 + }
  27 +
  28 + protected function checkResultInfo($info) {
  29 + if ($info['structure'] != 'all-in-one-file') {
  30 + return array(
  31 + 'success' => FALSE,
  32 + 'message' => 'Bad file structure ('.$info['structure'].')',
  33 + );
  34 + }
  35 + if ($info['timeFormat'] != 'ISO 8601') {
  36 + return array(
  37 + 'success' => FALSE,
  38 + 'message' => 'Bad time format ('.$info['timeFormat'].')',
  39 + );
  40 + }
  41 + if (!isset($info['sampling'])) {
  42 + return array(
  43 + 'success' => FALSE,
  44 + 'message' => 'Missing sampling time',
  45 + );
  46 + }
  47 + else if ($info['sampling'] != 60) {
  48 + return array(
  49 + 'success' => FALSE,
  50 + 'message' => 'Bad sampling time ('.$info['sampling'].')',
  51 + );
  52 + }
  53 + if (!in_array('mex_els_spec_0', $info['parameters'])) {
  54 + return array(
  55 + 'success' => FALSE,
  56 + 'message' => 'Missing mex_els_spec_0 in result file',
  57 + );
  58 + }
  59 + if (!in_array('mex_els_spec_sum', $info['parameters'])) {
  60 + return array(
  61 + 'success' => FALSE,
  62 + 'message' => 'Missing mex_els_spec_sum in result file',
  63 + );
  64 + }
  65 + return array(
  66 + 'success' => TRUE,
  67 + );
  68 + }
  69 +}
  70 +
  71 +?>
... ...
php/WebServices/Tests/Suite/TestGetDataset_12.php 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetDataset_12 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getDataset";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "datasetID" => "mex-els-all",
  20 + "sampling" => 60,
  21 + "timeFormat" => "UNIXTIME",
  22 + );
  23 + }
  24 +
  25 + public function getDescription() {
  26 + return "Get mex-els-all data. Sampling 60s. TimeFormat UNIXTIME";
  27 + }
  28 +
  29 + protected function checkResultInfo($info) {
  30 + if ($info['timeFormat'] != 'Seconds from 1970, milliseconds') {
  31 + return array(
  32 + 'success' => FALSE,
  33 + 'message' => 'Bad time format ('.$info['timeFormat'].')',
  34 + );
  35 + }
  36 + return array(
  37 + 'success' => TRUE,
  38 + );
  39 + }
  40 +}
  41 +
  42 +?>
... ...
php/WebServices/Tests/Suite/TestGetDataset_13.php 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetDataset_13 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getDataset";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "datasetID" => "mex-els-all",
  20 + "sampling" => 60,
  21 + "gzip" => 1,
  22 + );
  23 + }
  24 +
  25 + public function getDescription() {
  26 + return "Get mex-els-all data. Sampling 60s. Compressed result";
  27 + }
  28 +
  29 + protected function checkResultInfo($info) {
  30 + if (!$info['compressed']) {
  31 + return array(
  32 + 'success' => FALSE,
  33 + 'message' => 'Result file is not compressed',
  34 + );
  35 + }
  36 + return array(
  37 + 'success' => TRUE,
  38 + );
  39 + }
  40 +}
  41 +
  42 +?>
... ...
php/WebServices/Tests/Suite/TestGetDataset_14.php 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetDataset_14 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getDataset";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "datasetID" => "mex-els-all",
  20 + "sampling" => 60,
  21 + "outputFormat" => "VOTable",
  22 + );
  23 + }
  24 +
  25 + public function getDescription() {
  26 + return "Get mex-els-all data. Sampling 60s. VOTable";
  27 + }
  28 +
  29 + protected function checkResultInfo($info) {
  30 + if (!$info['isVOTable']) {
  31 + return array(
  32 + 'success' => FALSE,
  33 + 'message' => 'Result file not in VOTable format',
  34 + );
  35 + }
  36 + return array(
  37 + 'success' => TRUE,
  38 + );
  39 + }
  40 +}
  41 +
  42 +?>
... ...
php/WebServices/Tests/Suite/TestGetObsDataTree_40.php 0 → 100644
... ... @@ -0,0 +1,99 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestAbstract.php";
  4 +
  5 +class TestGetObsDataTree_40 extends TestAbstract
  6 +{
  7 + public function getAPI() {
  8 + return "getObsDataTree";
  9 + }
  10 +
  11 + public function getParams() {
  12 + return array();
  13 + }
  14 +
  15 + public function getDescription() {
  16 + return "Provides the hierarchy of public access data in AMDA.";
  17 + }
  18 +
  19 + protected function checkRESTResult($result) {
  20 + if (empty($result)) {
  21 + return array(
  22 + 'success' => FALSE,
  23 + 'message' => 'Empty result',
  24 + );
  25 + }
  26 + $doc = new DOMDocument();
  27 + if (!$doc->loadXML($result)) {
  28 + return array(
  29 + 'success' => FALSE,
  30 + 'message' => 'Result is not in XML format',
  31 + );
  32 + }
  33 + $nodes = $doc->getElementsByTagName('LocalDataBaseParameters');
  34 + if ($nodes->count() == 0) {
  35 + return array(
  36 + 'success' => FALSE,
  37 + 'message' => 'Cannot retrieve LocalDataBaseParameters node',
  38 + );
  39 + }
  40 + $xml_url = $nodes->item(0)->nodeValue;
  41 + if (empty($xml_url)) {
  42 + return array(
  43 + 'success' => FALSE,
  44 + 'message' => 'Cannot retrieve XML file path',
  45 + );
  46 + }
  47 + return $this->checkObsDataTree($xml_url);
  48 + }
  49 +
  50 + protected function checkSOAPResult($result) {
  51 + if (empty($result)) {
  52 + return array(
  53 + 'success' => FALSE,
  54 + 'message' => 'Empty result',
  55 + );
  56 + }
  57 + if (empty($result->success)) {
  58 + return array(
  59 + 'success' => FALSE,
  60 + 'message' => 'Error in request',
  61 + );
  62 + }
  63 + if (empty($result->WorkSpace) || empty($result->WorkSpace->LocalDataBaseParameters)) {
  64 + return array(
  65 + 'success' => FALSE,
  66 + 'message' => 'Cannot retrieve XML file path',
  67 + );
  68 + }
  69 + return $this->checkObsDataTree($result->WorkSpace->LocalDataBaseParameters);
  70 + }
  71 +
  72 + private function checkObsDataTree($xml_path) {
  73 + $data = file_get_contents($xml_path);
  74 + if (!$data) {
  75 + return array(
  76 + 'success' => FALSE,
  77 + 'message' => 'Cannot load tree XML file',
  78 + );
  79 + }
  80 + $doc = new DOMDocument();
  81 + if (!@$doc->loadXML($data)) {
  82 + return array(
  83 + 'success' => FALSE,
  84 + 'message' => 'Local tree is not in XML format',
  85 + );
  86 + }
  87 + if ($doc->documentElement->nodeName != 'dataRoot') {
  88 + return array(
  89 + 'success' => FALSE,
  90 + 'message' => 'Cannot retrieve dataRoot node in tree file',
  91 + );
  92 + }
  93 + return array(
  94 + 'success' => TRUE,
  95 + );
  96 + }
  97 +}
  98 +
  99 +?>
... ...
php/WebServices/Tests/Suite/TestGetOrbites_20.php 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetOrbites_20 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getOrbites";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "spacecraft" => "cluster1",
  20 + "coordinateSystem" => "GSE",
  21 + "units" => "km",
  22 + );
  23 + }
  24 +
  25 + public function getDescription() {
  26 + return "Get Cluster 1 orbit in GSE. No sampling.";
  27 + }
  28 +
  29 + protected function checkResultInfo($info) {
  30 + if ($info['structure'] != 'one-file-per-parameter-per-interval') {
  31 + return array(
  32 + 'success' => FALSE,
  33 + 'message' => 'Bad file structure ('.$info['structure'].')',
  34 + );
  35 + }
  36 + if (isset($info['sampling'])) {
  37 + return array(
  38 + 'success' => FALSE,
  39 + 'message' => 'A sampling time has been applied in result file',
  40 + );
  41 + }
  42 + if (!in_array('c1_xyz_gse_km', $info['parameters'])) {
  43 + return array(
  44 + 'success' => FALSE,
  45 + 'message' => 'Missing c1_xyz_gse_km in result file',
  46 + );
  47 + }
  48 + return array(
  49 + 'success' => TRUE,
  50 + );
  51 + }
  52 +}
  53 +
  54 +?>
... ...
php/WebServices/Tests/Suite/TestGetOrbites_21.php 0 → 100644
... ... @@ -0,0 +1,55 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetOrbites_21 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getOrbites";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "spacecraft" => "cluster1",
  20 + "coordinateSystem" => "GSE",
  21 + "units" => "km",
  22 + "sampling" => "100"
  23 + );
  24 + }
  25 +
  26 + public function getDescription() {
  27 + return "Get Cluster 1 orbit in GSE. Sampling 100s.";
  28 + }
  29 +
  30 + protected function checkResultInfo($info) {
  31 + if (!in_array('c1_xyz_gse_km', $info['parameters'])) {
  32 + return array(
  33 + 'success' => FALSE,
  34 + 'message' => 'Missing c1_xyz_gse_km in result file',
  35 + );
  36 + }
  37 + if (!isset($info['sampling'])) {
  38 + return array(
  39 + 'success' => FALSE,
  40 + 'message' => 'Missing sampling time',
  41 + );
  42 + }
  43 + else if ($info['sampling'] != 100) {
  44 + return array(
  45 + 'success' => FALSE,
  46 + 'message' => 'Bad sampling time ('.$info['sampling'].')',
  47 + );
  48 + }
  49 + return array(
  50 + 'success' => TRUE,
  51 + );
  52 + }
  53 +}
  54 +
  55 +?>
... ...
php/WebServices/Tests/Suite/TestGetParameter_30.php 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetParameter_30 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getParameter";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "parameterID" => "imf",
  20 + );
  21 + }
  22 +
  23 + public function getDescription() {
  24 + return "Get imf data. No sampling.";
  25 + }
  26 +
  27 + protected function checkResultInfo($info) {
  28 + if ($info['structure'] != 'one-file-per-parameter-per-interval') {
  29 + return array(
  30 + 'success' => FALSE,
  31 + 'message' => 'Bad file structure ('.$info['structure'].')',
  32 + );
  33 + }
  34 + if (isset($info['sampling'])) {
  35 + return array(
  36 + 'success' => FALSE,
  37 + 'message' => 'A sampling time has been applied in result file',
  38 + );
  39 + }
  40 + if ($info['timeFormat'] != 'ISO 8601') {
  41 + return array(
  42 + 'success' => FALSE,
  43 + 'message' => 'Bad time format ('.$info['timeFormat'].')',
  44 + );
  45 + }
  46 + if (!in_array('imf', $info['parameters'])) {
  47 + return array(
  48 + 'success' => FALSE,
  49 + 'message' => 'Missing imf in result file',
  50 + );
  51 + }
  52 + return array(
  53 + 'success' => TRUE,
  54 + );
  55 + }
  56 +}
  57 +
  58 +?>
... ...
php/WebServices/Tests/Suite/TestGetParameter_31.php 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetParameter_31 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getParameter";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "parameterID" => "imf",
  20 + "sampling" => 60,
  21 + "timeFormat" => 'UNIXTIME',
  22 + "gzip" => 1,
  23 + "outputFormat" => "VOTable",
  24 + );
  25 + }
  26 +
  27 + public function getDescription() {
  28 + return "Get imf data. Sampling time 60s. Unix time. VOTable. Compressed";
  29 + }
  30 +
  31 + protected function checkResultInfo($info) {
  32 + if ($info['structure'] != 'all-in-one-file') {
  33 + return array(
  34 + 'success' => FALSE,
  35 + 'message' => 'Bad file structure ('.$info['structure'].')',
  36 + );
  37 + }
  38 + if (!isset($info['sampling'])) {
  39 + return array(
  40 + 'success' => FALSE,
  41 + 'message' => 'Missing sampling time',
  42 + );
  43 + }
  44 + else if ($info['sampling'] != 60) {
  45 + return array(
  46 + 'success' => FALSE,
  47 + 'message' => 'Bad sampling time ('.$info['sampling'].')',
  48 + );
  49 + }
  50 + if ($info['timeFormat'] != 'Seconds from 1970, milliseconds') {
  51 + return array(
  52 + 'success' => FALSE,
  53 + 'message' => 'Bad time format ('.$info['timeFormat'].')',
  54 + );
  55 + }
  56 + if (!$info['compressed']) {
  57 + return array(
  58 + 'success' => FALSE,
  59 + 'message' => 'Result file is not compressed',
  60 + );
  61 + }
  62 + if (!$info['isVOTable']) {
  63 + return array(
  64 + 'success' => FALSE,
  65 + 'message' => 'Result file not in VOTable format'
  66 + );
  67 + }
  68 + if (!in_array('imf', $info['parameters'])) {
  69 + return array(
  70 + 'success' => FALSE,
  71 + 'message' => 'Missing imf in result file',
  72 + );
  73 + }
  74 + return array(
  75 + 'success' => TRUE,
  76 + );
  77 + }
  78 +}
  79 +
  80 +?>
... ...
php/WebServices/Tests/Suite/TestGetParameter_32.php 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetParameter_32 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getParameter";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "parameterID" => "imf,mex_els_spec_sum",
  20 + );
  21 + }
  22 +
  23 + public function getDescription() {
  24 + return "Get imf data. Sampling time 60s. Unix time. VOTable. Compressed";
  25 + }
  26 +
  27 + protected function checkResultInfo($info) {
  28 + if ($info['structure'] != 'all-in-one-file-refparam') {
  29 + return array(
  30 + 'success' => FALSE,
  31 + 'message' => 'Bad file structure ('.$info['structure'].')',
  32 + );
  33 + }
  34 + if (!in_array('imf', $info['parameters'])) {
  35 + return array(
  36 + 'success' => FALSE,
  37 + 'message' => 'Missing imf in result file',
  38 + );
  39 + }
  40 + if (!in_array('mex_els_spec_sum', $info['parameters'])) {
  41 + return array(
  42 + 'success' => FALSE,
  43 + 'message' => 'Missing mex_els_spec_sum in result file',
  44 + );
  45 + }
  46 + return array(
  47 + 'success' => TRUE,
  48 + );
  49 + }
  50 +}
  51 +
  52 +?>
... ...
php/WebServices/Tests/Suite/TestGetParameter_33.php 0 → 100644
... ... @@ -0,0 +1,65 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestDownloadBase.php";
  4 +
  5 +class TestGetParameter_33 extends TestDownloadBase
  6 +{
  7 + public function getAPI() {
  8 + return "getParameter";
  9 + }
  10 +
  11 + protected function needRESTAuth() {
  12 + return TRUE;
  13 + }
  14 +
  15 + public function getParams() {
  16 + return array(
  17 + "startTime" => "2008-01-01T00:00:00",
  18 + "stopTime" => "2008-01-01T01:00:00",
  19 + "parameterID" => "imf,mex_els_spec_sum",
  20 + "sampling" => 60,
  21 + );
  22 + }
  23 +
  24 + public function getDescription() {
  25 + return "Get imf data. Sampling time 60s. Unix time. VOTable. Compressed";
  26 + }
  27 +
  28 + protected function checkResultInfo($info) {
  29 + if ($info['structure'] != 'all-in-one-file') {
  30 + return array(
  31 + 'success' => FALSE,
  32 + 'message' => 'Bad file structure ('.$info['structure'].')',
  33 + );
  34 + }
  35 + if (!isset($info['sampling'])) {
  36 + return array(
  37 + 'success' => FALSE,
  38 + 'message' => 'Missing sampling time',
  39 + );
  40 + }
  41 + else if ($info['sampling'] != 60) {
  42 + return array(
  43 + 'success' => FALSE,
  44 + 'message' => 'Bad sampling time ('.$info['sampling'].')',
  45 + );
  46 + }
  47 + if (!in_array('imf', $info['parameters'])) {
  48 + return array(
  49 + 'success' => FALSE,
  50 + 'message' => 'Missing imf in result file',
  51 + );
  52 + }
  53 + if (!in_array('mex_els_spec_sum', $info['parameters'])) {
  54 + return array(
  55 + 'success' => FALSE,
  56 + 'message' => 'Missing mex_els_spec_sum in result file',
  57 + );
  58 + }
  59 + return array(
  60 + 'success' => TRUE,
  61 + );
  62 + }
  63 +}
  64 +
  65 +?>
... ...
php/WebServices/Tests/Suite/TestIsAlive_01.php 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +<?php
  2 +
  3 +require_once "Base/TestAbstract.php";
  4 +
  5 +class TestIsAlive_01 extends TestAbstract
  6 +{
  7 + public function getAPI() {
  8 + return "isAlive";
  9 + }
  10 +
  11 + public function getParams() {
  12 + return array();
  13 + }
  14 +
  15 + public function getDescription() {
  16 + return "Used to check whether AMDA services are available or not.";
  17 + }
  18 +
  19 + protected function checkRESTResult($result) {
  20 + //if (empty($result)) {
  21 + return array(
  22 + 'success' => FALSE,
  23 + 'message' => 'Empty result',
  24 + );
  25 + //}
  26 + $json_res = json_decode($result, TRUE);
  27 + if (!$json_res) {
  28 + return array(
  29 + 'success' => FALSE,
  30 + 'message' => 'Result is not in JSON format',
  31 + );
  32 + }
  33 + if (empty($json_res['alive'])) {
  34 + return array(
  35 + 'success' => FALSE,
  36 + 'message' => 'Service is not alive',
  37 + );
  38 + }
  39 + return array(
  40 + 'success' => TRUE,
  41 + );
  42 + }
  43 +
  44 + protected function checkSOAPResult($result) {
  45 + if ($result) {
  46 + return array(
  47 + 'success' => TRUE,
  48 + );
  49 + }
  50 + return array(
  51 + 'success' => FALSE,
  52 + 'message' => 'Service is not alive',
  53 + );
  54 + }
  55 +}
  56 +
  57 +?>
... ...
php/WebServices/Tests/testWebServer.php deleted
... ... @@ -1,172 +0,0 @@
1   -<?php
2   -
3   -require_once("../Client/WSClientSOAP.php");
4   -//require_once("../Client/WSClientREST.php");
5   -
6   -function runSuiteTests($client)
7   -{
8   - //Test isAlive function
9   - $res = $client->isAlive();
10   - if (!isset($res) || ($res != true))
11   - echo "[ERROR] - Error during call of isAlive function".PHP_EOL;
12   - else
13   - echo "[OK] - isAlive".PHP_EOL;
14   -
15   - //Test getTimeTablesList function without userID & password
16   -// $res = $client->getTimeTablesList();
17   -// if (!isset($res) || !$res->success)
18   -// echo "[ERROR] - Error during call of getTimeTablesList function - Test 1".PHP_EOL;
19   -// else
20   -// echo "[OK] - getTimeTablesList - Test 1 - ".$res->TimeTablesList.PHP_EOL;
21   -
22   - //Test getTimeTablesList function with userID & password
23   - $res = $client->getTimeTablesList(dduser, ddpass);
24   - if (!isset($res) || !$res->success)
25   - echo "[ERROR] - Error during call of getTimeTablesList function - Test 2".PHP_EOL;
26   - else
27   - echo "[OK] - getTimeTablesList - Test 2 - ".$res->TimeTablesList.PHP_EOL;
28   -
29   - //Test getTimeTable function without userID & password
30   -// $res = $client->getTimeTable("sharedtt_0");
31   -// if (!isset($res) || !$res->success)
32   -// echo "[ERROR] - Error during call of getTimeTable function - Test 1".PHP_EOL;
33   -// else
34   -// echo "[OK] - getTimeTable - Test 1 - ".$res->ttFileURL.PHP_EOL;
35   -
36   - //Test getTimeTable function with userID & password
37   - $res = $client->getTimeTable("tt_0", dduser, ddpass);
38   - if (!isset($res) || !$res->success)
39   - echo "[ERROR] - Error during call of getTimeTable function - Test 2".PHP_EOL;
40   - else
41   - echo "[OK] - getTimeTable - Test 2 - ".$res->ttFileURL.PHP_EOL;
42   -
43   - //Test getParameterList function for impex user
44   -// $res = $client->getParameterList("impex");
45   -// if (!isset($res) || !$res->success)
46   -// echo "[ERROR] - Error during call of getParameterList function - Test 1".PHP_EOL;
47   -// else
48   -// echo "[OK] - getParameterList - Test 1 - ".$res->ParameterList->LocalDataBaseParameters.PHP_EOL;
49   -
50   - //Test getParameterList function with userID & password
51   - $res = $client->getParameterList(dduser, ddpass);
52   - if (!isset($res) || !$res->success)
53   - echo "[ERROR] - Error during call of getParameterList function - Test 2".PHP_EOL;
54   - else
55   - {
56   - echo "[OK] - getParameterList - Test 2 :".PHP_EOL;
57   - echo " - UserDefinedParameters : ".$res->ParameterList->UserDefinedParameters.PHP_EOL;
58   - echo " - LocalDataBaseParameters : ".$res->ParameterList->LocalDataBaseParameters.PHP_EOL;
59   - }
60   -
61   - //Test getObsDataTree function
62   - $res = $client->getObsDataTree();
63   - if (!isset($res) || !$res->success)
64   - echo "[ERROR] - Error during call of getObsDataTree function".PHP_EOL;
65   - else
66   - echo "[OK] - getObsDataTree - Test 1 - ".$res->WorkSpace->LocalDataBaseParameters.PHP_EOL;
67   -
68   - //Test getParameter function
69   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 0, "", "", WSOutputFileFormat::ASCII);
70   - if (!isset($res) || !$res->success)
71   - echo "[ERROR] - Error during call of getParameter function - Test 1".PHP_EOL;
72   - else
73   - echo "[OK] - getParameter - Test 1 - ".$res->dataFileURLs.PHP_EOL;
74   -
75   - //Test getParameter function
76   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 3600, "", "", WSOutputFileFormat::ASCII);
77   - if (!isset($res) || !$res->success)
78   - echo "[ERROR] - Error during call of getParameter function - Test 2".PHP_EOL;
79   - else
80   - echo "[OK] - getParameter - Test 2 - ".$res->dataFileURLs.PHP_EOL;
81   -
82   - //Test getParameter function
83   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 0, "", "", WSOutputFileFormat::VOTABLE);
84   - if (!isset($res) || !$res->success)
85   - echo "[ERROR] - Error during call of getParameter function - Test 3".PHP_EOL;
86   - else
87   - echo "[OK] - getParameter - Test 3 - ".$res->dataFileURLs.PHP_EOL;
88   -
89   - //Test getParameter function
90   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 3600, "", "", WSOutputFileFormat::VOTABLE);
91   - if (!isset($res) || !$res->success)
92   - echo "[ERROR] - Error during call of getParameter function - Test 4".PHP_EOL;
93   - else
94   - echo "[OK] - getParameter - Test 4 - ".$res->dataFileURLs.PHP_EOL;
95   -
96   - //Test getParameter function
97   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 0, "", "", WSOutputFileFormat::ASCII, WSOutputTimeFormat::TIMESTAMP);
98   - if (!isset($res) || !$res->success)
99   - echo "[ERROR] - Error during call of getParameter function - Test 5".PHP_EOL;
100   - else
101   - echo "[OK] - getParameter - Test 5 - ".$res->dataFileURLs.PHP_EOL;
102   -
103   - //Test getParameter function
104   - $res = $client->getParameter("2008-01-01T00:00:00", "2008-01-02T00:00:00", "imf", 0, "", "", WSOutputFileFormat::VOTABLE, WSOutputTimeFormat::ISO, 1);
105   - if (!isset($res) || !$res->success)
106   - echo "[ERROR] - Error during call of getParameter function - Test 6".PHP_EOL;
107   - else
108   - echo "[OK] - getParameter - Test 6 - ".$res->dataFileURLs.PHP_EOL;
109   -
110   - //Test getDataset function
111   - $res = $client->getDataset("2008-01-01T00:00:00", "2008-01-02T00:00:00", "ground:based:asy", 0, "", "", WSOutputFileFormat::ASCII);
112   - if (!isset($res) || !$res->success)
113   - echo "[ERROR] - Error during call of getDataset function".PHP_EOL;
114   - else
115   - echo "[OK] - getDataset - ".$res->dataFileURLs.PHP_EOL;
116   -
117   - //Test getOrbites function
118   - $res = $client->getOrbites("2008-01-01T00:00:00", "2008-01-02T00:00:00", WSSpacecraft::VEX, WSCoordinatesSytem::VSO, WSOrbitUnit::RV,
119   - 0, "", "", WSOutputFileFormat::ASCII);
120   - if (!isset($res) || !$res->success)
121   - echo "[ERROR] - Error during call of getOrbites function".PHP_EOL;
122   - else
123   - echo "[OK] - getOrbites - ".$res->dataFileURLs.PHP_EOL;
124   -
125   - //Test getPlot function
126   - $res = $client->getPlot("2008-01-01T00:00:00", "2009-01-01T00:00:00", "ACE");
127   - if (!isset($res) || !$res->success)
128   - echo "[ERROR] - Error during call of getPlot function".PHP_EOL;
129   - else
130   - {
131   - $plotDirectoryURL = $res->plotDirectoryURL;
132   - echo "[OK] - getPlot".PHP_EOL;
133   - while (true)
134   - {
135   - echo " -> getResultPlot".PHP_EOL;
136   - $res = $client->getResultPlot($plotDirectoryURL);
137   - if (!isset($res))
138   - {
139   - echo "[ERROR] - Error during call of getResultPlot function".PHP_EOL;
140   - break;
141   - }
142   - else if ($res->success)
143   - {
144   - echo " -> plotFileURL : ".$res->plotFileURL.PHP_EOL;
145   - break;
146   - }
147   - echo " -> Result not ready => Wait 5s".PHP_EOL;
148   - sleep(5);
149   - }
150   - }
151   -}
152   -
153   -$clientSOAP = new WSClientSOAP("http://apus.irap.omp.eu/NEWAMDA/public/wsdl/Methods_AMDA.wsdl");
154   -
155   -if ( getenv('DDUSER') && getenv('DDPASS')) {
156   - define('dduser', getenv('DDUSER'));
157   - define('ddpass', getenv('DDPASS'));
158   -}
159   -else {
160   - die("Export env vars : DDUSER and DDPASS");
161   -}
162   -echo "==> Suite tests for SOAP client".PHP_EOL;
163   -runSuiteTests($clientSOAP);
164   -
165   -//REST client is obsolete
166   -/*$clientREST = new WSClientREST("http://localhost/NEWAMDA-BENJAMIN/php/rest/");
167   -
168   -echo "==> Suite tests for REST client".PHP_EOL;
169   -runSuiteTests($clientREST);*/
170   -
171   -
172   -?>
173 0 \ No newline at end of file
php/config.php
... ... @@ -106,7 +106,7 @@ define(&#39;USERPATH&#39;, IHM_SRC_DIR.&#39;/data/&#39;);
106 106 define('SHAREDPATH', IHM_SRC_DIR.'/shared_data/');
107 107  
108 108 // Web Service servers WSDL : $_SERVER['SERVER_NAME'] (par apache) gethostname() (par command)
109   -$SERVER_NAME = $_SERVER['SERVER_NAME'] ? $_SERVER['SERVER_NAME'] : gethostname();
  109 +$SERVER_NAME = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : gethostname();
110 110 define('webAlias',"http://".$SERVER_NAME.APACHE_ALIAS);
111 111  
112 112 define('DD_WSDL',DDSERVICE.'/dd.wsdl');
... ...
php/wsTests.php 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +<?php
  2 +
  3 +if (php_sapi_name() !='cli') die("This script can be only executed from command line");
  4 +
  5 +require_once("config.php");
  6 +set_include_path(get_include_path() . PATH_SEPARATOR . "WebServices/Tests/");
  7 +
  8 +require_once("Base/TestsSuite.php");
  9 +
  10 +define("BASE_URL","http://127.0.0.1");
  11 +
  12 +$suite = new TestsSuite();
  13 +$suite->init('WebServices/Tests/Suite');
  14 +$results = $suite->run();
  15 +
  16 +$error = FALSE;
  17 +foreach ($results as $result) {
  18 + if (!$result['status']['success']) {
  19 + echo "[ERROR] ".$result['name']." - ".$result['status']['message'].PHP_EOL;
  20 + $error = TRUE;
  21 + }
  22 +}
  23 +
  24 +exit ($error);
  25 +
  26 +?>
... ...