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

Commit b96d04f

Browse files
author
mgrauer
committed
Add tracker_scalar model test
1 parent be8693f commit b96d04f

File tree

5 files changed

+215
-1
lines changed

5 files changed

+215
-1
lines changed

modules/tracker/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ to_titlecase(${module_name} module_name_titlecase)
2323
add_midas_style_test(Style${module_name_titlecase} ${CMAKE_SOURCE_DIR}/modules/${module_name})
2424

2525
add_subdirectory(controllers)
26+
add_subdirectory(models)

modules/tracker/tests/databaseDataset/default.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<dataset>
3-
<tracker_producer producer_id="100" community_id="1" display_name="Test Producer" repository="https://example.com"
3+
<tracker_producer producer_id="100" community_id="2000" display_name="Test Producer" repository="https://example.com"
44
executable_name="test.exe" description="" revision_url="https:/example.net" />
55
<tracker_trend trend_id="1" producer_id="100" metric_name="metric_0" display_name="Metric #0" config_item_id="1000"
66
test_dataset_id="1001" truth_dataset_id="1002" unit="mm" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#=============================================================================
2+
# Midas Server
3+
# Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
4+
# All rights reserved.
5+
# For more information visit http://www.kitware.com/.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0.txt
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#=============================================================================
19+
20+
add_subdirectory(base)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#=============================================================================
2+
# Midas Server
3+
# Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
4+
# All rights reserved.
5+
# For more information visit http://www.kitware.com/.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0.txt
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#=============================================================================
19+
20+
set(module_name tracker)
21+
to_titlecase(${module_name} module_name_titlecase)
22+
23+
add_midas_test(${module_name_titlecase}ScalarModel ScalarModelTest.php)
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
/*=========================================================================
3+
Midas Server
4+
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
5+
All rights reserved.
6+
For more information visit http://www.kitware.com/.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** test ScalarModel */
22+
class Tracker_ScalarModelTest extends DatabaseTestCase
23+
{
24+
/** set up tests */
25+
public function setUp()
26+
{
27+
$this->setupDatabase(array('default')); // core dataset
28+
$this->setupDatabase(array('default'), 'tracker'); // module dataset
29+
$this->enabledModules = array('tracker');
30+
parent::setUp();
31+
}
32+
33+
/** testScalarModel */
34+
public function testScalarModel()
35+
{
36+
$uuidComponent = MidasLoader::loadComponent('Uuid');
37+
38+
$communityId = '2000';
39+
$producerDisplayName = 'Test Producer';
40+
$producerRevision = 'deadbeef';
41+
$submitTime = 'now';
42+
$submissionUuid = $uuidComponent->generate();
43+
44+
$userModel = MidasLoader::loadModel('User');
45+
$usersFile = $this->loadData('User', 'default');
46+
$userDao = $userModel->load($usersFile[0]->getKey());
47+
48+
$producerModel = MidasLoader::loadModel('Producer', 'tracker');
49+
$producerDao = $producerModel->load(100);
50+
51+
$submissionModel = MidasLoader::loadModel('Submission', 'tracker');
52+
$submissionDao = $submissionModel->getOrCreateSubmission($producerDao, $submissionUuid);
53+
$submissionId = $submissionDao->getKey();
54+
55+
// Create two scalars, each tied to a separate trend.
56+
57+
$trendModel = MidasLoader::loadModel('Trend', 'tracker');
58+
$scalarModel = MidasLoader::loadModel('Scalar', 'tracker');
59+
60+
$metric0trend = $trendModel->load(1);
61+
$scalarValue0 = '0';
62+
$params0 = array(
63+
'num_param' => 90,
64+
'text_param' => 'master',
65+
'null_param' => '',
66+
);
67+
$scalarDao0 = $scalarModel->addToTrend(
68+
$metric0trend,
69+
$submitTime,
70+
$submissionId,
71+
$producerRevision,
72+
$scalarValue0,
73+
$userDao,
74+
true,
75+
true,
76+
'http://buildresultsurl',
77+
'master',
78+
$params0);
79+
80+
// Ensure value and params are properly set on scalar.
81+
82+
$paramChecks = array(
83+
'num_param' => array('found' => false, 'type' => 'numeric', 'val' => 90),
84+
'text_param' => array('found' => false, 'type' => 'text', 'val' => 'master'),
85+
'null_param' => array('found' => false, 'type' => 'text', 'val' => ''),
86+
);
87+
88+
$scalarDao0Params = $scalarDao0->getParams();
89+
foreach ($scalarDao0Params as $param) {
90+
$checks = $paramChecks[$param->getParamName()];
91+
$this->assertEquals($checks['type'], $param->getParamType());
92+
if ($checks['type'] === 'numeric') {
93+
$this->assertEquals($checks['val'], $param->getNumericValue());
94+
} else {
95+
$this->assertEquals($checks['val'], $param->getTextValue());
96+
}
97+
$paramChecks[$param->getParamName()]['found'] = true;
98+
}
99+
100+
foreach ($paramChecks as $checks) {
101+
$this->assertTrue($checks['found']);
102+
}
103+
104+
$this->assertEquals($scalarDao0->getValue(), $scalarValue0);
105+
106+
// Scalar the second.
107+
108+
$metric1trend = $trendModel->load(2);
109+
$scalarValue1 = '1';
110+
$params1 = array(
111+
'num_param' => 92,
112+
'text_param' => 'dev',
113+
'null_param' => '',
114+
);
115+
$scalarDao1 = $scalarModel->addToTrend(
116+
$metric1trend,
117+
$submitTime,
118+
$submissionId,
119+
$producerRevision,
120+
$scalarValue1,
121+
$userDao,
122+
true,
123+
true,
124+
'http://buildresultsurl',
125+
'dev',
126+
$params1);
127+
128+
// Ensure value and params are properly set on scalar.
129+
130+
$paramChecks = array(
131+
'num_param' => array('found' => false, 'type' => 'numeric', 'val' => 92),
132+
'text_param' => array('found' => false, 'type' => 'text', 'val' => 'dev'),
133+
'null_param' => array('found' => false, 'type' => 'text', 'val' => ''),
134+
);
135+
136+
$scalarDao1Params = $scalarDao1->getParams();
137+
foreach ($scalarDao1Params as $param) {
138+
$checks = $paramChecks[$param->getParamName()];
139+
$this->assertEquals($checks['type'], $param->getParamType());
140+
if ($checks['type'] === 'numeric') {
141+
$this->assertEquals($checks['val'], $param->getNumericValue());
142+
} else {
143+
$this->assertEquals($checks['val'], $param->getTextValue());
144+
}
145+
$paramChecks[$param->getParamName()]['found'] = true;
146+
}
147+
148+
foreach ($paramChecks as $checks) {
149+
$this->assertTrue($checks['found']);
150+
}
151+
152+
$this->assertEquals($scalarDao1->getValue(), $scalarValue1);
153+
154+
155+
// Delete scalars and ensure params are deleted.
156+
157+
$scalarModel->delete($scalarDao0);
158+
$scalarModel->delete($scalarDao1);
159+
160+
$paramModel = MidasLoader::loadModel('Param', 'tracker');
161+
foreach ($scalarDao0Params as $scalarParam) {
162+
$scalarParamReloaded = $paramModel->load($scalarParam->getParamId());
163+
$this->assertFalse($scalarParamReloaded, 'Scalar param should have been deleted');
164+
}
165+
foreach ($scalarDao1Params as $scalarParam) {
166+
$scalarParamReloaded = $paramModel->load($scalarParam->getParamId());
167+
$this->assertFalse($scalarParamReloaded, 'Scalar param should have been deleted');
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)