Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Add tracker_scalar model test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrauer committed Oct 1, 2015
1 parent be8693f commit b96d04f
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/tracker/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ to_titlecase(${module_name} module_name_titlecase)
add_midas_style_test(Style${module_name_titlecase} ${CMAKE_SOURCE_DIR}/modules/${module_name})

add_subdirectory(controllers)
add_subdirectory(models)
2 changes: 1 addition & 1 deletion modules/tracker/tests/databaseDataset/default.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<tracker_producer producer_id="100" community_id="1" display_name="Test Producer" repository="https://example.com"
<tracker_producer producer_id="100" community_id="2000" display_name="Test Producer" repository="https://example.com"
executable_name="test.exe" description="" revision_url="https:/example.net" />
<tracker_trend trend_id="1" producer_id="100" metric_name="metric_0" display_name="Metric #0" config_item_id="1000"
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
Expand Down
20 changes: 20 additions & 0 deletions modules/tracker/tests/models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#=============================================================================
# Midas Server
# Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
# All rights reserved.
# For more information visit http://www.kitware.com/.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

add_subdirectory(base)
23 changes: 23 additions & 0 deletions modules/tracker/tests/models/base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#=============================================================================
# Midas Server
# Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
# All rights reserved.
# For more information visit http://www.kitware.com/.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

set(module_name tracker)
to_titlecase(${module_name} module_name_titlecase)

add_midas_test(${module_name_titlecase}ScalarModel ScalarModelTest.php)
170 changes: 170 additions & 0 deletions modules/tracker/tests/models/base/ScalarModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** test ScalarModel */
class Tracker_ScalarModelTest extends DatabaseTestCase
{
/** set up tests */
public function setUp()
{
$this->setupDatabase(array('default')); // core dataset
$this->setupDatabase(array('default'), 'tracker'); // module dataset
$this->enabledModules = array('tracker');
parent::setUp();
}

/** testScalarModel */
public function testScalarModel()
{
$uuidComponent = MidasLoader::loadComponent('Uuid');

$communityId = '2000';
$producerDisplayName = 'Test Producer';
$producerRevision = 'deadbeef';
$submitTime = 'now';
$submissionUuid = $uuidComponent->generate();

$userModel = MidasLoader::loadModel('User');
$usersFile = $this->loadData('User', 'default');
$userDao = $userModel->load($usersFile[0]->getKey());

$producerModel = MidasLoader::loadModel('Producer', 'tracker');
$producerDao = $producerModel->load(100);

$submissionModel = MidasLoader::loadModel('Submission', 'tracker');
$submissionDao = $submissionModel->getOrCreateSubmission($producerDao, $submissionUuid);
$submissionId = $submissionDao->getKey();

// Create two scalars, each tied to a separate trend.

$trendModel = MidasLoader::loadModel('Trend', 'tracker');
$scalarModel = MidasLoader::loadModel('Scalar', 'tracker');

$metric0trend = $trendModel->load(1);
$scalarValue0 = '0';
$params0 = array(
'num_param' => 90,
'text_param' => 'master',
'null_param' => '',
);
$scalarDao0 = $scalarModel->addToTrend(
$metric0trend,
$submitTime,
$submissionId,
$producerRevision,
$scalarValue0,
$userDao,
true,
true,
'http://buildresultsurl',
'master',
$params0);

// Ensure value and params are properly set on scalar.

$paramChecks = array(
'num_param' => array('found' => false, 'type' => 'numeric', 'val' => 90),
'text_param' => array('found' => false, 'type' => 'text', 'val' => 'master'),
'null_param' => array('found' => false, 'type' => 'text', 'val' => ''),
);

$scalarDao0Params = $scalarDao0->getParams();
foreach ($scalarDao0Params as $param) {
$checks = $paramChecks[$param->getParamName()];
$this->assertEquals($checks['type'], $param->getParamType());
if ($checks['type'] === 'numeric') {
$this->assertEquals($checks['val'], $param->getNumericValue());
} else {
$this->assertEquals($checks['val'], $param->getTextValue());
}
$paramChecks[$param->getParamName()]['found'] = true;
}

foreach ($paramChecks as $checks) {
$this->assertTrue($checks['found']);
}

$this->assertEquals($scalarDao0->getValue(), $scalarValue0);

// Scalar the second.

$metric1trend = $trendModel->load(2);
$scalarValue1 = '1';
$params1 = array(
'num_param' => 92,
'text_param' => 'dev',
'null_param' => '',
);
$scalarDao1 = $scalarModel->addToTrend(
$metric1trend,
$submitTime,
$submissionId,
$producerRevision,
$scalarValue1,
$userDao,
true,
true,
'http://buildresultsurl',
'dev',
$params1);

// Ensure value and params are properly set on scalar.

$paramChecks = array(
'num_param' => array('found' => false, 'type' => 'numeric', 'val' => 92),
'text_param' => array('found' => false, 'type' => 'text', 'val' => 'dev'),
'null_param' => array('found' => false, 'type' => 'text', 'val' => ''),
);

$scalarDao1Params = $scalarDao1->getParams();
foreach ($scalarDao1Params as $param) {
$checks = $paramChecks[$param->getParamName()];
$this->assertEquals($checks['type'], $param->getParamType());
if ($checks['type'] === 'numeric') {
$this->assertEquals($checks['val'], $param->getNumericValue());
} else {
$this->assertEquals($checks['val'], $param->getTextValue());
}
$paramChecks[$param->getParamName()]['found'] = true;
}

foreach ($paramChecks as $checks) {
$this->assertTrue($checks['found']);
}

$this->assertEquals($scalarDao1->getValue(), $scalarValue1);


// Delete scalars and ensure params are deleted.

$scalarModel->delete($scalarDao0);
$scalarModel->delete($scalarDao1);

$paramModel = MidasLoader::loadModel('Param', 'tracker');
foreach ($scalarDao0Params as $scalarParam) {
$scalarParamReloaded = $paramModel->load($scalarParam->getParamId());
$this->assertFalse($scalarParamReloaded, 'Scalar param should have been deleted');
}
foreach ($scalarDao1Params as $scalarParam) {
$scalarParamReloaded = $paramModel->load($scalarParam->getParamId());
$this->assertFalse($scalarParamReloaded, 'Scalar param should have been deleted');
}
}
}

0 comments on commit b96d04f

Please sign in to comment.