@@ -17,35 +17,135 @@ class ApiTest extends ControllerTestCase
17
17
public function setUp ()
18
18
{
19
19
$ this ->setupDatabase (array ('default ' , 'adminUser ' ));
20
- $ this ->_models = array ('User ' );
21
- $ this ->enabledModules = array ('remoteprocessing ' );
20
+ $ this ->_models = array ('User ' , ' Item ' );
21
+ $ this ->enabledModules = array ('scheduler ' , ' remoteprocessing ' , ' api ' );
22
22
parent ::setUp ();
23
23
}
24
24
25
- /** test config */
26
- public function testIndex ()
25
+ private function _getSecurityKey ()
27
26
{
27
+ $ this ->resetAll ();
28
28
$ usersFile = $ this ->loadData ('User ' , 'adminUser ' );
29
29
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
30
-
31
- $ this ->dispatchUrI ('/remoteprocessing/config ' , $ userDao );
32
- $ this ->assertQuery ("input#securitykey " );
33
-
34
- $ this ->resetAll ();
35
-
36
30
$ this ->params = array ();
37
31
$ securityKey = uniqid ();
38
32
$ this ->params ['securitykey ' ] = $ securityKey ;
39
33
$ this ->params ['submitConfig ' ] = 'true ' ;
40
34
$ this ->request ->setMethod ('POST ' );
41
35
$ this ->dispatchUrI ("/remoteprocessing/config " , $ userDao );
36
+ $ this ->resetAll ();
37
+ return $ securityKey ;
38
+ }
39
+
40
+ /** test manage */
41
+ public function testAllApiSubmissionProcess ()
42
+ {
43
+ $ usersFile = $ this ->loadData ('User ' , 'adminUser ' );
44
+ $ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
45
+ $ itemFile = $ this ->loadData ('Item ' , 'default ' );
46
+
47
+ $ revision = $ this ->Item ->getLastRevision ($ itemFile [0 ]);
48
+
49
+ // register (create user)
50
+ $ this ->params = array ();
51
+ $ this ->params ['securitykey ' ] = $ this ->_getSecurityKey ();
52
+ $ this ->params ['os ' ] = MIDAS_REMOTEPROCESSING_OS_WINDOWS ;
53
+ $ this ->request ->setMethod ('POST ' );
42
54
43
- if (!file_exists (BASE_PATH ."/core/configs/remoteprocessing.local.ini " ))
55
+ $ this ->dispatchUrI ('/api/json?method=midas.remoteprocessing.registerserver ' );
56
+
57
+ $ jsonResults = $ this ->getBody ();
58
+ $ this ->resetAll ();
59
+ if (strpos ($ jsonResults , '{"stat":"ok" ' ) === false )
60
+ {
61
+ $ this ->fail ('Error json ' );
62
+ }
63
+ $ results = JsonComponent::decode ($ jsonResults );
64
+
65
+ $ token = $ results ['data ' ]['token ' ];
66
+ $ email = $ results ['data ' ]['email ' ];
67
+ $ apikey = $ results ['data ' ]['apikey ' ];
68
+
69
+ // authenticate
70
+ $ this ->params = array ();
71
+ $ this ->params ['securitykey ' ] = $ this ->_getSecurityKey ();
72
+ $ this ->params ['email ' ] = $ email ;
73
+ $ this ->params ['apikey ' ] = $ apikey ;
74
+ $ this ->request ->setMethod ('POST ' );
75
+
76
+ $ this ->dispatchUrI ('/api/json?method=midas.remoteprocessing.registerserver ' );
77
+
78
+ $ jsonResults = $ this ->getBody ();
79
+ $ this ->resetAll ();
80
+ if (strpos ($ jsonResults , '{"stat":"ok" ' ) === false )
44
81
{
45
- $ this ->fail ('Unable to find config file ' );
82
+ $ this ->fail ('Error json ' );
46
83
}
47
- $ applicationConfig = parse_ini_file ( BASE_PATH . " /core/configs/remoteprocessing.local.ini " , true );
84
+ $ results = JsonComponent:: decode ( $ jsonResults );
48
85
49
- $ this ->assertEquals ($ securityKey , $ applicationConfig ['global ' ]['securitykey ' ]);
86
+ $ token = $ results ['data ' ]['token ' ];
87
+
88
+ // ask action
89
+ $ this ->params = array ();
90
+ $ this ->params ['token ' ] = $ token ;
91
+ $ this ->params ['os ' ] = MIDAS_REMOTEPROCESSING_OS_WINDOWS ;
92
+ $ this ->request ->setMethod ('POST ' );
93
+
94
+ $ this ->dispatchUrI ('/api/json?method=midas.remoteprocessing.keepaliveserver ' );
95
+
96
+ $ jsonResults = $ this ->getBody ();
97
+ $ this ->resetAll ();
98
+ if (strpos ($ jsonResults , '{"stat":"ok" ' ) === false )
99
+ {
100
+ $ this ->fail ('Error json ' );
101
+ }
102
+ $ results = JsonComponent::decode ($ jsonResults );
103
+
104
+ if ($ results ['data ' ]['action ' ] != 'wait ' )
105
+ {
106
+ $ this ->fail ('Should be wait, was ' .$ results ['data ' ]['action ' ]);
107
+ }
108
+
109
+ // add a job
110
+ $ scriptParams ['script ' ] = 'script ' ;
111
+ $ scriptParams ['os ' ] = MIDAS_REMOTEPROCESSING_OS_WINDOWS ;
112
+ $ scriptParams ['condition ' ] = '' ;
113
+ $ scriptParams ['params ' ] = array ();
114
+ Zend_Registry::get ('notifier ' )->callback ("CALLBACK_REMOTEPROCESSING_ADD_JOB " , $ scriptParams );
115
+
116
+ $ this ->params = array ();
117
+ $ this ->params ['token ' ] = $ token ;
118
+ $ this ->params ['os ' ] = MIDAS_REMOTEPROCESSING_OS_WINDOWS ;
119
+ $ this ->request ->setMethod ('POST ' );
120
+
121
+ $ this ->dispatchUrI ('/api/json?method=midas.remoteprocessing.keepaliveserver ' );
122
+
123
+ $ jsonResults = $ this ->getBody ();
124
+ $ this ->resetAll ();
125
+ if (strpos ($ jsonResults , '{"stat":"ok" ' ) === false )
126
+ {
127
+ $ this ->fail ('Error json ' );
128
+ }
129
+ $ results = JsonComponent::decode ($ jsonResults );
130
+
131
+ if ($ results ['data ' ]['action ' ] != 'process ' )
132
+ {
133
+ $ this ->fail ('Should be process, was ' .$ results ['data ' ]['action ' ]);
134
+ }
135
+
136
+ // send results
137
+ $ this ->params = array ();
138
+ $ this ->params ['token ' ] = $ token ;
139
+ $ this ->params ['os ' ] = MIDAS_REMOTEPROCESSING_OS_WINDOWS ;
140
+ $ this ->request ->setMethod ('POST ' );
141
+
142
+ $ this ->dispatchUrI ('/api/json?method=midas.remoteprocessing.resultsserver&testingmode=1 ' );
143
+ $ jsonResults = $ this ->getBody ();
144
+ $ this ->resetAll ();
145
+ if (strpos ($ jsonResults , '{"stat":"ok" ' ) === false )
146
+ {
147
+ $ this ->fail ('Error json ' );
148
+ }
50
149
}
150
+
51
151
}
0 commit comments