diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 0000000..0e498d3 --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,4 @@ +The integration test framework is designed to be used to run tests against +an installed and working XDMoD instance. + +Run the tests with ./runtests.sh diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php new file mode 100644 index 0000000..9536daa --- /dev/null +++ b/tests/integration/bootstrap.php @@ -0,0 +1,46 @@ + 'rest/app_kernels/details', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'int_params' => [ + 'ak', + 'resource', + 'instance_id', + 'metric', + 'num_proc_units', + 'collected' + ], + 'string_params' => ['status'], + 'bool_params' => ['debug', 'resource_first'], + 'unix_ts_params' => ['start_time', 'end_time'] + ] + ); + } + + /** + * @dataProvider provideGetDatasets + */ + public function testGetDatasets($id, $role, $input, $output) + { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetDatasets() + { + $validInput = [ + 'path' => 'rest/app_kernels/datasets', + 'method' => 'get', + 'params' => ['ak' => '0'], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'int_params' => ['ak', 'resource', 'num_proc_units'], + 'string_params' => ['metric', 'format'], + 'bool_params' => ['debug', 'metadata_only', 'inline'], + 'unix_ts_params' => ['start_time', 'end_time'] + ] + ); + } + + /** + * @dataProvider provideGetPlots + */ + public function testGetPlots($id, $role, $input, $output) + { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetPlots() + { + $validInput = [ + 'path' => 'rest/app_kernels/plots', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'int_params' => ['limit', 'offset', 'num_proc_units'], + 'float_params' => ['width', 'height', 'scale'], + 'string_params' => [ + 'legend_type', + 'font_size', + 'contextMenuOnClick', + 'format' + ], + 'bool_params' => [ + 'show_title', + 'swap_xy', + 'inline', + 'show_change_indicator', + 'show_control_plot', + 'show_control_zones', + 'discrete_controls', + 'show_running_averages', + 'show_control_interval', + 'show_num_proc_units_separately' + ], + 'unix_ts_params' => ['start_time', 'end_time'] + ] + ); + } + + /** + * @dataProvider provideGetControlRegions + */ + public function testGetControlRegions($id, $role, $input, $output) + { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetControlRegions() + { + $validInput = [ + 'path' => 'rest/app_kernels/control_regions', + 'method' => 'get', + 'params' => [ + 'resource_id' => '0', + 'ak_def_id' => '0' + ], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + ['int_params' => ['resource_id', 'ak_def_id']] + ); + } + + /** + * @dataProvider provideUpdateControlRegions + */ + public function testUpdateControlRegions( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideUpdateControlRegions() + { + $validInput = [ + 'path' => 'rest/app_kernels/control_regions', + 'method' => 'post', + 'params' => null, + 'data' => [ + 'resource_id' => '0', + 'ak_def_id' => '0', + 'control_region_time_interval_type' => 'foo', + 'startDateTime' => 'foo' + ] + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'authorization' => 'mgr', + 'int_params' => ['resource_id', 'ak_def_id', 'n_points'], + 'string_params' => [ + 'control_region_time_interval_type', + 'startDateTime', + 'endDateTime', + 'comment', + 'control_region_def_id' + ] + ] + ); + } + + /** + * @dataProvider provideDeleteControlRegions + */ + public function testDeleteControlRegions( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideDeleteControlRegions() + { + $validInput = [ + 'path' => 'rest/app_kernels/control_regions', + 'method' => 'delete', + 'params' => [ + 'resource_id' => '0', + 'ak_def_id' => '0', + 'controlRegiondIDs' => 'foo' + ], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'authorization' => 'mgr', + 'int_params' => ['resource_id', 'ak_def_id'], + 'string_params' => ['controlRegiondIDs'] + ] + ); + } + + /** + * @dataProvider provideGetNotifications + */ + public function testGetNotifications( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetNotifications($path) + { + return $this->provideNotificationTests( + 'rest/app_kernels/notifications', + 'get', + 'load load_default_notification_settings' + ); + } + + private function provideNotificationTests($path, $method, $action) + { + return [ + [ + 'missing_curent_tmp_settings', + 'usr', + [ + 'path' => $path, + 'method' => $method, + 'params' => [], + 'data' => null + ], + parent::validateSuccessResponse([ + 'success' => false, + 'errorMessage' => ( + "Can not $action. curent_tmp_settings is a" + . ' required parameter.' + ) + ]) + ] + ]; + } + + /** + * @dataProvider providePutNotifications + */ + public function testPutNotifications( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function providePutNotifications() + { + return $this->provideNotificationTests( + 'rest/app_kernels/notifications', + 'put', + 'save notification_settings' + ); + } + + /** + * @dataProvider provideGetDefaultNotifications + */ + public function testGetDefaultNotifications( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetDefaultNotifications() + { + return $this->provideNotificationTests( + 'rest/app_kernels/notifications/default', + 'get', + 'load load_default_notification_settings' + ); + } + + /** + * @dataProvider provideSendNotification + */ + public function testSendNotification( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideSendNotification() + { + $validInput = [ + 'path' => 'rest/app_kernels/notifications/send', + 'method' => 'get', + 'params' => [ + 'report_type' => 'foo', + 'report_param' => 'foo' + ], + 'data' => null + ]; + return $this->provideRestEndpointTestsGivenCustomExceptionHandler( + $validInput, + ['string_params' => [ + 'report_type', + 'start_date', + 'end_date', + 'report_param' + ]], + 200, + 'Can not send report\\. .* ' + ); + } + + /** + * This function is used because AppKernelControllerProvider has custom + * exception handling that changes the response HTTP status code and + * prepends text to the response message. + */ + private function provideRestEndpointTestsGivenCustomExceptionHandler( + array $validInput, + array $options, + $expectedStatusCode, + $messagePrefixRegex + ) { + $tests = parent::provideRestEndpointTests($validInput, $options); + foreach ($tests as $i => $test) { + // Get the test's expected message text. + $closure = $test[3]['body_validator']; + $reflection = new ReflectionFunction($closure); + $vars = $reflection->getStaticVariables(); + $message = $vars['message']; + // Replace the output object with a new object that has the custom + // HTTP status code and message prefix. + $tests[$i][3] = [ + 'status_code' => $expectedStatusCode, + 'body_validator' => function ( + $body, + $assertMessage + ) use ( + $messagePrefixRegex, + $message + ) { + parent::assertFalse($body['success'], $assertMessage); + parent::assertRegExp( + ( + "/$messagePrefixRegex" + . preg_quote($message) + . '/' + ), + $body['message'], + $assertMessage + ); + } + ]; + } + return $tests; + } + + /** + * @dataProvider provideGetAppKernelSuccessRate + */ + public function testGetAppKernelSuccessRate( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetAppKernelSuccessRate() + { + $validInput = [ + 'path' => 'rest/app_kernels/success_rate', + 'method' => 'get', + 'params' => [ + 'start_date' => 'foo', + 'end_date' => 'foo' + ], + 'data' => null + ]; + // Run the tests of missing and invalid parameters for parameters that + // are parsed before the try/catch in + // AppKernelControllerProvider::getAppKernelSuccessRate. + $tests = parent::provideRestEndpointTests( + $validInput, + [ + 'string_params' => [ + 'format', + 'start_date', + 'end_date', + 'resources', + 'appKers', + 'problemSizes' + ], + 'bool_params' => [ + 'showAppKer', + 'showAppKerTotal', + 'showResourceTotal', + 'showUnsuccessfulTasksDetails', + 'showSuccessfulTasksDetails', + 'showInternalFailureTasks' + ] + ] + ); + // Run the test of the invalid 'node' parameter, which is parsed inside + // the try/catch in + // AppKernelControllerProvider::getAppKernelSuccessRate. + $validInput['params'] = []; + return array_merge( + $tests, + $this->provideRestEndpointTestsGivenCustomExceptionHandler( + $validInput, + [ + 'string_params' => ['node'], + 'additional_params' => [ + 'start_date' => 'foo', + 'end_date' => 'foo' + ] + ], + 500, + ( + 'There was an exception while trying to process the' + . ' requested operation\\. Message: ' + ) + ) + ); + } + + /** + * @dataProvider provideGetPerformanceMap + */ + public function testGetPerformanceMap( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetPerformanceMap() + { + $validInput = [ + 'path' => 'rest/app_kernels/performance_map', + 'method' => 'get', + 'params' => [], + 'data' => null + ]; + return $this->provideRestEndpointTestsGivenCustomExceptionHandler( + $validInput, + ['string_params' => ['start_date', 'end_date', 'format']], + 200, + 'Can not send performance map\\. .* ' + ); + } + + /** + * @dataProvider provideGetRawPerformanceMap + */ + public function testGetRawPerformanceMap( + $id, + $role, + $input, + $output + ) { + parent::authenticateRequestAndValidateJson( + self::$helper, + $role, + $input, + $output + ); + } + + public function provideGetRawPerformanceMap() + { + $validInput = [ + 'path' => 'rest/app_kernels/performance_map/raw', + 'method' => 'get', + 'params' => [ + 'start_date' => '9999-01-02', + 'end_date' => '9999-01-01' + ], + 'data' => null + ]; + // Run some standard endpoint tests. + return parent::provideRestEndpointTests( + $validInput, + [ + 'authentication' => true, + 'run_as' => 'cd', + 'string_params' => [ + 'start_date', + 'end_date', + 'app_kernels', + 'problem_sizes' + ] + ] + ); + } +} diff --git a/tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php similarity index 72% rename from tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php rename to tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php index e7a9f17..954b009 100644 --- a/tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php +++ b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php @@ -2,12 +2,14 @@ namespace IntegrationTests\REST\internal_dashboard; +use IntegrationTests\TestHarness\XdmodTestHelper; + class DashboardAppKernelTest extends \PHPUnit_Framework_TestCase { public function __construct() { $xdmodConfig = array( "decodetextasjson" => true ); - $this->xdmodhelper = new \TestHarness\XdmodTestHelper($xdmodConfig); + $this->xdmodhelper = new XdmodTestHelper($xdmodConfig); $this->endpoint = 'rest/v0.1/akrr/'; $this->xdmodhelper->authenticate("mgr"); @@ -20,8 +22,8 @@ private function validateAkrrResourceEntries($searchparams) $result = $this->xdmodhelper->get($this->endpoint . 'resources', $searchparams); $this->assertEquals(200, $result[1]['http_code']); - $this->assertArrayHasKey('success', $result[0]); - $this->assertEquals($result[0]['success'], true); + $this->assertArrayHasKey('status', $result[0]); + $this->assertEquals($result[0]['status'], 'success'); $data = $result[0]['data']; foreach ($data as $item) { @@ -45,15 +47,15 @@ private function validateAkrrKernelEntries($searchparams) $result = $this->xdmodhelper->get($this->endpoint . 'kernels', $searchparams); $this->assertEquals(200, $result[1]['http_code']); - $this->assertArrayHasKey('message', $result[0]); - $this->assertEquals($result[0]['message'], 'success'); + $this->assertArrayHasKey('status', $result[0]); + $this->assertEquals($result[0]['status'], 'success'); $data = $result[0]['data']; foreach ($data as $item) { - $this->assertArrayHasKey('nodes_list', $data[0]); - $this->assertArrayHasKey('name', $data[0]); - $this->assertArrayHasKey('enabled', $data[0]); - $this->assertArrayHasKey('id', $data[0]); + $this->assertArrayHasKey('nodes_list', $item); + $this->assertArrayHasKey('name', $item); + $this->assertArrayHasKey('enabled', $item); + $this->assertArrayHasKey('id', $item); } return $data; diff --git a/tests/integration_tests/phpunit.xml.dist b/tests/integration/phpunit.xml.dist similarity index 93% rename from tests/integration_tests/phpunit.xml.dist rename to tests/integration/phpunit.xml.dist index 578d81b..50b04a1 100644 --- a/tests/integration_tests/phpunit.xml.dist +++ b/tests/integration/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" diff --git a/tests/integration_tests/runtests.sh b/tests/integration/runtests.sh similarity index 100% rename from tests/integration_tests/runtests.sh rename to tests/integration/runtests.sh diff --git a/tests/integration_tests/scripts/bootstrap.sh b/tests/integration/scripts/bootstrap.sh similarity index 100% rename from tests/integration_tests/scripts/bootstrap.sh rename to tests/integration/scripts/bootstrap.sh diff --git a/tests/integration_tests/scripts/validate.sh b/tests/integration/scripts/validate.sh similarity index 100% rename from tests/integration_tests/scripts/validate.sh rename to tests/integration/scripts/validate.sh diff --git a/tests/integration_tests/README.md b/tests/integration_tests/README.md deleted file mode 100644 index 8ea333d..0000000 --- a/tests/integration_tests/README.md +++ /dev/null @@ -1,7 +0,0 @@ -The integration test framework is designed to be used to run tests against -an installed and working XDMoD instance. - -The test harness in the xdmod repository must be configured correctly as -per the instructions in the readme file: xdmod/open_xdmod/modules/xdmod/integration_tests/README.md - -Run the tests with ./runtests.sh diff --git a/tests/integration_tests/bootstrap.php b/tests/integration_tests/bootstrap.php deleted file mode 100644 index 7e09b61..0000000 --- a/tests/integration_tests/bootstrap.php +++ /dev/null @@ -1,20 +0,0 @@ -getDB(); $db_ak_id = $db->query( @@ -43,7 +44,7 @@ public function processingUnitProvider() $proc_unit_node_1to4 = array_slice($proc_unit_node_1to32, 0, 3); $proc_unit_node_2to8 = array_slice($proc_unit_node_1to32, 1, 3); - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $metrics_id = intval( $ak_db->getDB()->query( 'SELECT metric_id FROM mod_appkernel.metric WHERE name="Wall Clock Time"' @@ -75,7 +76,7 @@ public function processingUnitProvider() */ public function testProcessingUnit($start_date, $end_date, array $resource_ids, array $metrics, $expected) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getProcessingUnits($start_date, $end_date, $resource_ids, $metrics); if ($expected === null) { @@ -245,7 +246,7 @@ public function testGetUniqueAppKernels( $n_expected = null, $expected = null ) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getUniqueAppKernels($resource_ids, $node_counts, $core_counts); if ($expected === null && $n_expected === null) { @@ -284,7 +285,7 @@ public function testGetUniqueAppKernels( public function getMetricsProvider() { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $db = $ak_db->getDB(); # Get metric id $ak_exec_exists_id = intval( @@ -356,7 +357,7 @@ public function testGetMetrics( $n_expected = null, $expected = null ) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getMetrics($ak_def_id, $start_date, $end_date, $resource_ids, $pu_counts); if ($n_expected === null && $expected !== null) { @@ -434,7 +435,7 @@ public function loadAppKernelInstancesProvider() */ public function testLoadAppKernelInstances($ak_def_id, $resource_id, $n_expected = null, $expected = null) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->loadAppKernelInstances($ak_def_id, $resource_id); $db = $ak_db->getDB(); @@ -472,7 +473,7 @@ public function testLoadAppKernelInstances($ak_def_id, $resource_id, $n_expected public function testNewControlRegions() { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); // update initial control for 5 points $ak_db->newControlRegions( diff --git a/tests/unit/phpunit.xml.dist b/tests/unit/phpunit.xml.dist index 578d81b..50b04a1 100644 --- a/tests/unit/phpunit.xml.dist +++ b/tests/unit/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false"