1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* Authors:
* Endi Sukma Dewata <edewata@redhat.com>
*
* Copyright (C) 2010 Red Hat
* see file 'COPYING' for use and warranty information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
module('association');
test("Testing serial_associator().", function() {
expect(11);
var orig_ipa_batch_command = IPA.batch_command;
var user = IPA.entity({ name: 'user' });
var group = IPA.entity({ name: 'group' });
var params = {
method: 'add_member',
pkey: 'test',
entity: user,
other_entity: group
};
params.values = ['user1', 'user2', 'user3'];
IPA.batch_command = function(spec) {
var that = orig_ipa_batch_command(spec);
that.execute = function() {
equals(that.commands.length, params.values.length,
'Checking IPA.batch_command command count');
var i, command;
for(i=0; i < params.values.length; i++) {
command = that.commands[i];
equals(
command.entity, params.other_entity.name,
'Checking IPA.command() parameter: entity');
equals(
command.method, params.method,
'Checking IPA.command() parameter: method');
equals(
command.args[0], 'user'+(i+1),
'Checking IPA.command() parameter: primary key');
}
that.on_success({});
};
return that;
};
params.on_success = function() {
ok(true, "on_success() is invoked.");
};
var associator = IPA.serial_associator(params);
associator.execute();
IPA.batch_command = orig_ipa_batch_command;
});
test("Testing bulk_associator().", function() {
expect(4);
var orig_ipa_command = IPA.command;
var counter = 0;
var user = IPA.entity({ name: 'user' });
var group = IPA.entity({ name: 'group' });
var params = {
method: 'add_member',
pkey: 'test',
entity: user,
other_entity: group
};
params.values = ['user1', 'user2', 'user3'];
IPA.command = function(spec) {
var that = orig_ipa_command(spec);
that.execute = function() {
counter++;
equals(
that.method, params.method,
'Checking IPA.command() parameter: method');
equals(
that.args[0], params.pkey,
'Checking IPA.command() parameter: primary key');
equals(
that.options[params.other_entity.name], 'user1,user2,user3',
'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]');
that.on_success({});
};
return that;
};
params.on_success = function() {
ok(true, "on_success() is invoked.");
};
var associator = IPA.bulk_associator(params);
associator.execute();
IPA.command = orig_ipa_command;
});
|