-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbidentity_source_test.go
338 lines (300 loc) · 10.4 KB
/
dbidentity_source_test.go
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
package cli
import (
"fmt"
"sort"
"strconv"
"strings"
api "github.com/atricore/josso-api-go"
)
func (s *AccTestSuite) TestAccCliDbIdentitySourceDTO_crud() {
var t = s.T()
appliance, err := getTestAppliance(s.T(), s.client)
if err != nil {
s.client.Logger().Errorf("cannot get test appliance %v", err)
t.Error(err)
return
}
crudName := "DdIdentityVauld-a"
var orig *api.DbIdentitySourceDTO
var created api.DbIdentitySourceDTO
orig = createTestDbIdentitySourceDTO(crudName)
// Test CREATE
created, err = s.client.CreateDbIdentitySourceDTO(*appliance.Name, *orig)
if err != nil {
t.Error(err)
return
}
if err := DbIdentitySourceValidateCreate(orig, &created); err != nil {
t.Errorf("creating db identity source : %v", err)
return
}
// Test READ
var read api.DbIdentitySourceDTO
read, err = s.client.GetDbIdentitySourceDTO(*appliance.Name, crudName)
if err != nil {
t.Error(err)
return
}
if err = DbIdentitySourceDTOValidateUpdate(&read, &created); err != nil {
t.Errorf("creating db identity source : %v", err)
return
}
// Test Update
read.Description = api.PtrString("Updated description")
updated, err := s.client.UpdateDbIdentitySourceDTO(*appliance.Name, read)
if err != nil {
t.Error(err)
return
}
if err = DbIdentitySourceDTOValidateUpdate(&read, &updated); err != nil {
t.Error(err)
return
}
//Test Delete
deleted, err := s.client.DeleteDbIdentitySourceDTO(*appliance.Name, crudName)
if err != nil {
t.Error(err)
return
}
if !deleted {
t.Errorf("Not deleted! %s", crudName)
return
}
// ------------------------------------------------------------------------------------------------------------------
// Test empty list
listOfAll, err := s.client.GetDbIdentitySourceDTOs(*appliance.Name)
if err != nil {
t.Error(err)
return
}
if len(listOfAll) != 0 {
// The list should be emtpy
t.Errorf("Invalid number of elements found %d, expeted 0", len(listOfAll))
return
}
// ------------------------
// List of created elements, order by Name
var listOfCreated [2]api.DbIdentitySourceDTO
// Test list of #2 elements
element1 := createTestDbIdentitySourceDTO("dbids-1")
listOfCreated[0], _ = s.client.CreateDbIdentitySourceDTO(*appliance.Name, *element1)
element2 := createTestDbIdentitySourceDTO("dbids-2")
listOfCreated[1], _ = s.client.CreateDbIdentitySourceDTO(*appliance.Name, *element2)
// ------------------------
// Get list from server
listOfRead, err := s.client.GetDbIdentitySourceDTOs(*appliance.Name)
if err != nil {
t.Error(err)
return
}
// The list should have 2 elemetns
if len(listOfRead) != 2 {
// The list should be emtpy
t.Errorf("Invalid number of elements found %d, expected 2", len(listOfAll))
return
}
// Order list of read by Name
sort.SliceStable(listOfRead,
func(i, j int) bool {
return strings.Compare(*listOfRead[i].Name, *listOfRead[j].Name) < 0
},
)
// Validate each element from the list of created with the list of read
for idx, r := range listOfCreated {
if err = DbIdentitySourceDTOValidateUpdate(&r, &listOfRead[idx]); err != nil {
t.Error(err)
return
}
}
}
func createTestDbIdentitySourceDTO(name string) *api.DbIdentitySourceDTO {
tData := api.NewDbIdentitySourceDTO()
//
tData.SetName(name)
tData.SetAdmin(fmt.Sprint("usr-", name))
tData.SetCredentialsQueryString("SELECT USERNAME, PASSWORD FROM JOSSO_USER WHERE LOGIN = ?")
//
tData.SetPassword(fmt.Sprint("pwd-", name))
tData.SetRelayCredentialQueryString("n/a")
tData.SetResetCredentialDml("")
tData.SetRolesQueryString("SELECT R.ROLE FROM JOSSO_ROLE R, JOSSO_USER U, JOSSO_USER_ROLE RU WHERE R.ROLE = RU.ROLE AND RU.USER = U.LOGIN AND U.LOGIN = ?")
tData.SetUseColumnNamesAsPropertyNames(true)
tData.SetUserPropertiesQueryString("SELECT EMAIL, LASTNAME, FIRSTNAME FROM JOSSO_USER WHERE LOGIN = ?")
tData.SetUserQueryString("SELECT USERNAME FROM JOSSO_USER WHERE LOGIN = ?")
tData.SetAcquireIncrement(1)
tData.SetConnectionUrl(fmt.Sprintf("jdbc:mysql:localhost/%s?create=true", name))
tData.SetDescription(fmt.Sprint("Description", name))
tData.SetDriverName(fmt.Sprintln("org.mysql.driver"))
tData.SetIdleConnectionTestPeriod(1)
tData.SetInitialPoolSize(10)
tData.SetMaxIdleTime(15)
tData.SetMaxPoolSize(20)
tData.SetMinPoolSize(1)
tData.SetPooledDatasource(true)
return tData
}
func (s *AccTestSuite) TestAccCliDbIdentitySourceDTO_crud_createFailOnDupName() {
// TODO ! implement me!
}
func (s *AccTestSuite) TestAccCliDbIdentitySourceDTO_crud_updateFailOnDupName() {
// TODO ! implement me!
}
// --------------------------------------------------------
// Fields to validate after appliance creation
func DbIdentitySourceFieldTestCreate(
e *api.DbIdentitySourceDTO,
r *api.DbIdentitySourceDTO) []FiledTestStruct {
return []FiledTestStruct{
{
name: "acquire_increment",
cmp: func() bool { return Int32PtrEquals(e.AcquireIncrement, r.AcquireIncrement) },
expected: strconv.Itoa(int(Int32Deref(e.AcquireIncrement))),
received: strconv.Itoa(int(Int32Deref(r.AcquireIncrement))),
},
{
name: "admin",
cmp: func() bool { return StrPtrEquals(e.Admin, r.Admin) },
expected: StrDeref(e.Admin),
received: StrDeref(r.Admin),
},
{
name: "connect_url",
cmp: func() bool { return StrPtrEquals(e.ConnectionUrl, r.ConnectionUrl) },
expected: StrDeref(e.ConnectionUrl),
received: StrDeref(r.ConnectionUrl),
},
{
name: "credentials_query_string",
cmp: func() bool { return StrPtrEquals(e.CredentialsQueryString, r.CredentialsQueryString) },
expected: StrDeref(e.CredentialsQueryString),
received: StrDeref(r.CredentialsQueryString),
},
//{
// name: "customclass",
// cmp: func() bool { return StrPtrEquals(e.customclass, r.customclass) },
// expected: StrDeref(e.customclass),
// received: StrDeref(r.customclass),
//},
{
name: "description",
cmp: func() bool { return StrPtrEquals(e.Description, r.Description) },
expected: StrDeref(e.Description),
received: StrDeref(r.Description),
},
{
name: "driver_name",
cmp: func() bool { return StrPtrEquals(e.DriverName, r.DriverName) },
expected: StrDeref(e.DriverName),
received: StrDeref(r.DriverName),
},
{
name: "idle_connection_test_period",
cmp: func() bool { return Int32PtrEquals(e.IdleConnectionTestPeriod, r.IdleConnectionTestPeriod) },
expected: strconv.Itoa(int(Int32Deref(e.IdleConnectionTestPeriod))),
received: strconv.Itoa(int(Int32Deref(r.IdleConnectionTestPeriod))),
},
{
name: "initial_poll_size",
cmp: func() bool { return Int32PtrEquals(e.InitialPoolSize, r.InitialPoolSize) },
expected: strconv.Itoa(int(Int32Deref(e.InitialPoolSize))),
received: strconv.Itoa(int(Int32Deref(r.InitialPoolSize))),
},
{
name: "max_idle_time",
cmp: func() bool { return Int32PtrEquals(e.MaxIdleTime, r.MaxIdleTime) },
expected: strconv.Itoa(int(Int32Deref(e.MaxIdleTime))),
received: strconv.Itoa(int(Int32Deref(r.MaxIdleTime))),
},
{
name: "max_pool_size",
cmp: func() bool { return Int32PtrEquals(e.MaxPoolSize, r.MaxPoolSize) },
expected: strconv.Itoa(int(Int32Deref(e.MaxPoolSize))),
received: strconv.Itoa(int(Int32Deref(r.MaxPoolSize))),
},
{
name: "min_pool_size",
cmp: func() bool { return Int32PtrEquals(e.MinPoolSize, r.MinPoolSize) },
expected: strconv.Itoa(int(Int32Deref(e.MinPoolSize))),
received: strconv.Itoa(int(Int32Deref(r.MinPoolSize))),
},
{
name: "password",
cmp: func() bool { return StrPtrEquals(e.Password, r.Password) },
expected: StrDeref(e.Password),
received: StrDeref(r.Password),
},
{
name: "pooled_data_source",
cmp: func() bool { return BoolPtrEquals(e.PooledDatasource, r.PooledDatasource) },
expected: strconv.FormatBool(BoolDeref(e.PooledDatasource)),
received: strconv.FormatBool(BoolDeref(r.PooledDatasource)),
},
{
name: "relay_credential_query_string",
cmp: func() bool { return StrPtrEquals(e.RelayCredentialQueryString, r.RelayCredentialQueryString) },
expected: StrDeref(e.RelayCredentialQueryString),
received: StrDeref(r.RelayCredentialQueryString),
},
{
name: "reset_cretential_dml",
cmp: func() bool { return StrPtrEquals(e.ResetCredentialDml, r.ResetCredentialDml) },
expected: StrDeref(e.ResetCredentialDml),
received: StrDeref(r.ResetCredentialDml),
},
{
name: "roles_query_string",
cmp: func() bool { return StrPtrEquals(e.RolesQueryString, r.RolesQueryString) },
expected: StrDeref(e.RolesQueryString),
received: StrDeref(r.RolesQueryString),
},
{
name: "use_column_names_as_property_names",
cmp: func() bool { return BoolPtrEquals(e.UseColumnNamesAsPropertyNames, r.UseColumnNamesAsPropertyNames) },
expected: strconv.FormatBool(BoolDeref(e.UseColumnNamesAsPropertyNames)),
received: strconv.FormatBool(BoolDeref(r.UseColumnNamesAsPropertyNames)),
},
{
name: "user_properties_query_string",
cmp: func() bool { return StrPtrEquals(e.UserPropertiesQueryString, r.UserPropertiesQueryString) },
expected: StrDeref(e.UserPropertiesQueryString),
received: StrDeref(r.UserPropertiesQueryString),
}, {
name: "user_query_string",
cmp: func() bool { return StrPtrEquals(e.UserQueryString, r.UserQueryString) },
expected: StrDeref(e.UserQueryString),
received: StrDeref(r.UserQueryString),
},
}
}
// Fields to validate after DbIdentitySource update
func DbIdentitySourceFieldTestUpdate(
e *api.DbIdentitySourceDTO,
r *api.DbIdentitySourceDTO) []FiledTestStruct {
t := []FiledTestStruct{
{
name: "id",
cmp: func() bool { return Int64PtrEquals(e.Id, r.Id) },
expected: strconv.FormatInt(Int64Deref(e.Id), 10),
received: strconv.FormatInt(Int64Deref(r.Id), 10),
},
{
name: "element_id",
cmp: func() bool { return StrPtrEquals(e.ElementId, r.ElementId) },
expected: StrDeref(e.ElementId),
received: StrDeref(r.ElementId),
},
}
return append(t, DbIdentitySourceFieldTestCreate(e, r)...)
}
// Compares the expected DbIdentitySource with the received one.
func DbIdentitySourceValidateCreate(
e *api.DbIdentitySourceDTO,
r *api.DbIdentitySourceDTO) error {
return ValidateFields(DbIdentitySourceFieldTestCreate(e, r))
}
// Compares the expected DbIdentitySource with the received one.
func DbIdentitySourceDTOValidateUpdate(
e *api.DbIdentitySourceDTO,
r *api.DbIdentitySourceDTO) error {
return ValidateFields(DbIdentitySourceFieldTestUpdate(e, r))
}