diff --git a/tests/integration_tests/bootstrap.php b/tests/integration_tests/bootstrap.php index 9fb9ee400..73bef99f2 100644 --- a/tests/integration_tests/bootstrap.php +++ b/tests/integration_tests/bootstrap.php @@ -5,11 +5,25 @@ // Autoloader for main framework test classes. spl_autoload_register( function ($className) use ($dir) { + // Look for classes relative to the `lib` directory; each namespace has + // its own directory in `lib` with the exception of the + // `IntegrationTests` namespace whose classes are defined in files + // directly in `lib`. For example, `TestHarness\XdmodTestHelper` + // resolves to `$dir/lib/TestHarness/XdmodTestHelper.php`, whereas + // `IntegrationTests\TokenAuthTest` resolves to + // `$dir/lib/TokenAuthTest.php`. $classPath = $dir . '/../../../xdmod/tests/integration/lib/' - . str_replace('\\', '/', $className) - . '.php'; + . str_replace( + '\\', + '/', + preg_replace( + '/IntegrationTests\\\\?/', + '', + $className + ) + ) . '.php'; if (is_readable($classPath)) { return require_once $classPath; diff --git a/tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php b/tests/integration_tests/lib/REST/EfficiencyControllerProviderTest.php similarity index 74% rename from tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php rename to tests/integration_tests/lib/REST/EfficiencyControllerProviderTest.php index c08e4afbf..ace7549ca 100644 --- a/tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php +++ b/tests/integration_tests/lib/REST/EfficiencyControllerProviderTest.php @@ -1,8 +1,10 @@ assertFalse($response[0]['success']); } - public function scatterPlotDataMalformedRequest() - { - $inputs = array(); - - $inputs[] = array('cd', array('start' => 0, 'limit' => 10)); - $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => '')); - $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => '{"realm": "SUPREMM"}')); - $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => 'not json data')); - $inputs[] = array('cd', array('start' => 'smart', 'limit' => 'asdf', 'config' => '{"realm": "SUPREMM"}')); - - return $inputs; - } - /** - * @dataProvider scatterPlotDataMalformedRequest + * @dataProvider provideCPUUsageScatterPlotEndpointMalformedRequest */ - public function testCPUUsageScatterPlotEndpointMalformedRequest($usr, $params) + public function testCPUUsageScatterPlotEndpointMalformedRequest( + $id, + $role, + $input, + $output + ) { + parent::requestAndValidateJson( + self::$helpers[$role], + $input, + $output + ); + } + + public function provideCPUUsageScatterPlotEndpointMalformedRequest() { - $response = self::$helpers[$usr]->get(self::ENDPOINT . 'scatterPlot/CPU%20Usage', $params); - $this->assertEquals(400, $response[1]['http_code']); - $this->assertFalse($response[0]['success']); + $validInput = [ + 'path' => self::ENDPOINT . 'scatterPlot/CPU%20Usage', + 'method' => 'get', + 'params' => $this->getScatterPlotDataParameters(), + 'data' => null + ]; + // Run some standard endpoint tests. + $tests = parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'int_params' => ['start', 'limit'], + 'string_params' => ['config'] + ] + ); + // Test bad request parameters. + $tests[] = [ + 'invalid_config', + 'cd', + parent::mergeParams( + $validInput, + 'params', + ['config' => 'foo'] + ), + parent::validateBadRequestResponse( + 'syntax error in config parameter', + 104 + ) + ]; + $config = json_decode($validInput['params']['config'], true); + $tests = $this->getCPUUsageScatterPlotEndpointMalformedParamTests( + $tests, + $validInput, + $config, + null, + 'missing_config_', + function ($param) { + return "Missing mandatory config property $param"; + } + ); + $tests = $this->getCPUUsageScatterPlotEndpointMalformedParamTests( + $tests, + $validInput, + $config, + 'order_by', + 'missing_config_order_by_', + function () { + return 'Malformed config property order_by'; + } + ); + return $tests; + } + + private function getCPUUsageScatterPlotEndpointMalformedParamTests( + array $tests, + array $validInput, + array $config, + $key, + $idPrefix, + $getMessage + ) { + if (is_null($key)) { + $params = $config; + } else { + $params = $config[$key]; + } + foreach (array_keys($params) as $param) { + $newConfig = $config; + if (is_null($key)) { + unset($newConfig[$param]); + } else { + unset($newConfig[$key][$param]); + } + $tests[] = [ + $idPrefix . $param, + 'cd', + parent::mergeParams( + $validInput, + 'params', + ['config' => json_encode($newConfig)] + ), + parent::validateBadRequestResponse($getMessage($param), 104) + ]; + } + return $tests; } /*** @@ -313,10 +397,6 @@ public function drilldownDataMalformedRequest() { $inputs = array(); - $inputs[] = array('cd', 400, array('')); - $inputs[] = array('cd', 400, array('not json data')); - $inputs[] = array('cd', 400, array('{"realm": "SUPREMM"}')); - $params = $this->getDrillDownDataParameters(array( 'global_filters' => array( 'data' => array( @@ -391,4 +471,43 @@ public function testCPUUsageDrillownEndpointMalformedRequest($usr, $http_code, $ $this->assertFalse($resdata['success']); } } + + /** + * @dataProvider provideGetHistogramDataParamValidation + */ + public function testGetHistogramDataParamValidation( + $id, + $role, + $input, + $output + ) { + parent::requestAndValidateJson( + self::$helpers[$role], + $input, + $output + ); + } + + public function provideGetHistogramDataParamValidation() + { + $validInput = [ + 'path' => self::ENDPOINT . 'histogram/cpuuser', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'run_as' => 'cd', + 'additional_params' => $this->getDrillDownDataParameters(), + // note that 'limit' is not included in the int_params because + // the path to getIntParam('limit') via getDimensionValues() + // is not taken if 'limit' is an invalid integer. + 'int_params' => ['offset'], + 'string_params' => ['search_text', 'realm'] + ] + ); + } } diff --git a/tests/integration_tests/lib/REST/SupremmDataflow/QualityTest.php b/tests/integration_tests/lib/REST/SupremmDataflow/QualityTest.php deleted file mode 100644 index 2d78e9893..000000000 --- a/tests/integration_tests/lib/REST/SupremmDataflow/QualityTest.php +++ /dev/null @@ -1,62 +0,0 @@ -authenticate($user); - } - } - } - - public static function tearDownAfterClass() - { - foreach (self::$helpers as $helper) { - $helper->logout(); - } - } - - public function qualityParams() - { - $inputs = array(); - - // test user access - $inputs[] = array('pub', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => 'gpu'), 401); - $inputs[] = array('usr', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => 'gpu'), 403); - $inputs[] = array('mgr', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => 'gpu'), 200); - - // test dates - $inputs[] = array('mgr', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => 'gpu'), 200); - $inputs[] = array('mgr', array('start' => '5/1/2022', 'end' => '5/8/2022', 'type' => 'gpu'), 400); - $inputs[] = array('mgr', array('start' => '5/1/2022', 'end' => '2022-05-08', 'type' => 'gpu'), 400); - $inputs[] = array('mgr', array('start' =>'2022-05-01', 'end' => '5/8/2022', 'type' => 'gpu'), 400); - - // test types - foreach (array('gpu', 'hardware', 'cpu', 'script', 'realms') as $type) { - $inputs[] = array('mgr', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => $type), 200); - } - - foreach (array('', 'ahhhhhh') as $type) { - $inputs[] = array('mgr', array('start' => '2022-05-01', 'end' => '2022-05-08', 'type' => $type), 400); - } - - return $inputs; - } - - /** - * @dataProvider qualityParams - */ - public function testQuality($usr, $params, $expected) - { - $response = self::$helpers[$usr]->get("rest/supremm_dataflow/quality", $params); - $this->assertEquals($expected, $response[1]['http_code']); - } -} // class QualityTest diff --git a/tests/integration_tests/lib/REST/SupremmDataflowControllerProviderTest.php b/tests/integration_tests/lib/REST/SupremmDataflowControllerProviderTest.php new file mode 100644 index 000000000..8e6af12a0 --- /dev/null +++ b/tests/integration_tests/lib/REST/SupremmDataflowControllerProviderTest.php @@ -0,0 +1,156 @@ + 'rest/supremm_dataflow/dbstats', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'authorization' => 'mgr', + 'int_params' => ['resource_id'], + 'string_params' => ['db_id'] + ] + ); + } + + /** + * @dataProvider provideGetQuality + */ + public function testGetQuality($id, $role, $input, $output) + { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetQuality() + { + $validInput = [ + 'path' => 'rest/supremm_dataflow/quality', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + // Run some standard endpoint tests. + $tests = parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'authorization' => 'mgr', + 'string_params' => ['start', 'end', 'type'] + ] + ); + // Test bad request parameters. + foreach (['start', 'end'] as $date) { + $tests[] = [ + 'invalid_' . $date . '_date', + 'mgr', + parent::mergeParams( + $validInput, + 'params', + [$date => '5/1/2022'] + ), + parent::validateBadRequestResponse( + 'Please provide dates in YYYY-MM-DD format.', + 0 + ) + ]; + } + array_push( + $tests, + [ + 'invalid_date_range', + 'mgr', + parent::mergeParams( + $validInput, + 'params', + [ + 'start' => '2023-01-01', + 'end' => '2023-01-01' + ] + ), + parent::validateBadRequestResponse('Invalid date range.', 0) + ], + [ + 'invalid_type', + 'mgr', + parent::mergeParams( + $validInput, + 'params', + [ + 'start' => '2022-05-01', + 'end' => '2022-05-08', + 'type' => 'foo' + ] + ), + parent::validateBadRequestResponse( + ( + 'Unsupported information type. Valid types are: gpu,' + . ' hardware, cpu, script, or realms.' + ), + 0 + ) + ] + ); + // Test successful requests. + foreach (['gpu', 'hardware', 'cpu', 'script', 'realms'] as $type) { + $tests[] = [ + 'success_' . $type, + 'mgr', + parent::mergeParams( + $validInput, + 'params', + [ + 'start' => '2022-05-01', + 'end' => '2022-05-08', + 'type' => $type + ] + ), + parent::validateSuccessResponse( + function ($body, $assertMessage) use ($type) { + $this->assertSame($type, $body['type']); + $this->assertInternalType('array', $body['result']); + } + ) + ]; + } + return $tests; + } +} diff --git a/tests/integration_tests/phpunit.xml.dist b/tests/integration_tests/phpunit.xml.dist index 578d81b69..50b04a1a9 100644 --- a/tests/integration_tests/phpunit.xml.dist +++ b/tests/integration_tests/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false"