/
validator_test.go
469 lines (376 loc) · 18.3 KB
/
validator_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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
package main
import (
"bytes"
"encoding/json"
//"log"
//"net/url"
"net"
"os"
"path"
"strings"
"testing"
"time"
//"github.com/gosexy/rest"
"github.com/go-resty/resty/v2"
"github.com/nsip/nias2/lib"
"github.com/nsip/nias2/napval"
)
var customClient *resty.Client
/*
func post_file(filename string, endpoint string) (string, error) {
var f *os.File
var err error
if f, err = os.Open(filename); err != nil {
return "", err
}
defer f.Close()
files := rest.FileMap{
"validationFile": []rest.File{{
Name: path.Base(f.Name()),
Reader: f},
},
}
requestVariables := url.Values{"name": {path.Base(f.Name())}}
msg, err := rest.NewMultipartMessage(requestVariables, files)
if err != nil {
return "", err
}
dst := map[string]interface{}{}
if err = customClient.PostMultipart(&dst, endpoint, msg); err != nil {
return "", err
}
txid := dst["TxID"].(string)
return txid, nil
}
*/
func post_file(filename string, endpoint string) (string, error) {
dst := lib.NiasMessage{}
resp, err := customClient.R().
SetFiles(map[string]string{
"validationFile": filename,
}).
SetFormData(map[string]string{
"name": path.Base(filename),
}).
SetResult(&dst).
Post(endpoint)
if err != nil {
return "", err
}
out := resp.Result().(*lib.NiasMessage)
//log.Printf("%+v", out)
txid := out.TxID
return txid, nil
}
func TestRepeatPSIwithinSchool(t *testing.T) {
test_harness(t, "../../unit_test_files/5StudentsDuplicatePlatformID.csv", "PSI/ASL ID", "Platform Student ID (Student) and ASL ID (School) are potential duplicate")
}
func TestAddress(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsAddress.csv", "AddressLine1", "Additional property AddressLine1 is not allowed")
}
func TestState(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsState.csv", "StateTerritory", "Additional property StateTerritory is not allowed")
}
func TestKurdistan(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsKurdistan.csv", "", "")
}
func TestSexMissingMandatory(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatorySex.csv", "Sex", "Sex is required")
}
func TestSexInvalid(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidSex.csv", "Sex", "Sex must be one of the following")
}
func TestYearLevelPrep(t *testing.T) {
test_harness(t, "../../unit_test_files/1students1YearLevelPrep.csv", "BirthDate/TestLevel", "Year Level P does not match Test level")
}
func TestYearLevelF(t *testing.T) {
test_harness(t, "../../unit_test_files/1students2YearLevelF.csv", "BirthDate/TestLevel", "Year Level F does not match Test level")
}
func TestYearLevelP(t *testing.T) {
test_harness(t, "../../unit_test_files/1students1YearLevelP.csv", "BirthDate/TestLevel", "")
}
func TestFutureBirthdate(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsFutureBirthDates.csv", "BirthDate/YearLevel", "Year Level calculated from BirthDate does not fall within expected NAPLAN year level ranges")
}
func TestMissingParent2LOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1students2MissingParent2LOTE.csv", "Parent2LOTE", "Must be present if other Parent2 fields are present")
}
func TestACARAIDandStateBlank(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsACARAIDandStateBlank.csv", "ASLSchoolId", "ASLSchoolId is required")
}
func TestBirthdateYearLevel(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsBirthdateYearLevel.csv", "BirthDate/YearLevel/TestLevel", "does not match year level derived from BirthDate")
}
/*
func TestACARAIDandStateMismatch(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsACARAIDandStateMismatch.csv", "ASLSchoolId", "is a valid ID, but not for")
}
*/
func TestMissingSurname(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingSurname.csv", "FamilyName", "FamilyName is required")
}
func TestEmptySurname(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsEmptySurname.csv", "FamilyName", "FamilyName is required")
}
func TestInvalidVisaClass(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidVisaSubClass.csv", "VisaCode", "is not one of known values from")
}
func TestMalformedPSI(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentMalformedPlatformStudentID.csv", "PlatformId", "PlatformId is not in correct format")
}
func TestCommaAddressField(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsCommaAddressField.csv", "", "")
}
func TestDupGivenLastNameDOBDiffACARAId(t *testing.T) {
test_harness(t, "../../unit_test_files/2studentsDupGivenLastNameDOBDiffACARAId.csv", "Multiple (see description)", "Potential duplicate")
}
func TestExceedCharLengthsSurname(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsExceedCharLengthsSurname.csv", "FamilyName", "String length must be less than or equal to 40")
}
/*
func TestExceedCharLengthsAddress(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsExceedCharLengthsAddress.csv", "AddressLine1", "String length must be less than or equal to 40")
}
*/
func TestExceedCharLengthsGivenName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsExceedCharLengthsGivenName.csv", "GivenName", "String length must be less than or equal to 40")
}
func TestInvalidAcaraId(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidAcaraId.csv", "ASLSchoolId", "not found in ASL list of valid IDs")
}
func TestInvalidCountryCodes(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidCountryCodes.csv", "CountryOfBirth", "Country Code is not one of SACC 1269.0 codeset")
}
func TestInvalidDateFormat(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidDateFormat.csv", "BirthDate", "Date provided does not parse correctly for yyyy-mm-dd")
}
func TestInvalidLanguageCodes(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidLanguageCodes.csv", "StudentLOTE", "Language Code is not one of ASCL 1267.0 codeset")
}
func TestInvalidValuesLBOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesLBOTE.csv", "LBOTE", "LBOTE must be one of the following")
}
func TestInvalidValuesOfflineDelivery(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesOfflineDelivery.csv", "OfflineDelivery", "OfflineDelivery must be one of the following")
}
func TestInvalidValuesMainSchoolFlag(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesMainSchoolFlag.csv", "MainSchoolFlag", "MainSchoolFlag must be one of the following")
}
func TestInvalidValuesParent1LOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidParent1LOTE.csv", "Parent1LOTE", "Language Code is not one of ASCL 1267.0 codeset")
}
func TestInvalidInvalidValuesFFPOS(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesFFPOS.csv", "FFPOS", "FFPOS must be one of the following")
}
func TestInvalidValuesParent2Occupation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesParent2Occupation.csv", "Parent2Occupation", "Parent2Occupation must be one of the following")
}
func TestInvalidValuesParent2NonSchoolEducation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesParent2NonSchoolEducation.csv", "Parent2NonSchoolEducation", "Parent2NonSchoolEducation must be one of the following")
}
func TestInvalidValuesParent2SchoolEducation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesParent2SchoolEducation.csv", "Parent2SchoolEducation", "Parent2SchoolEducation must be one of the following")
}
func TestInvalidValuesHomeSchooledStudent(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesHomeSchooledStudent.csv", "HomeSchooledStudent", "HomeSchooledStudent must be one of the following")
}
func TestInvalidValuesYearLevel(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsInvalidValuesYearLevel.csv", "YearLevel", "YearLevel must be one of the following")
}
func TestMissingMandatoryParent1SchlEduc(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent1SchlEduc.csv", "Parent1SchoolEducation", "Parent1SchoolEducation is required")
}
func TestMissingMandatoryASLSchoolID(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryASLSchoolID.csv", "ASLSchoolId", "ASLSchoolId is required")
}
func TestMissingMandatoryDOB(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryDOB.csv", "BirthDate", "BirthDate is required")
}
func TestMissingMandatoryFFPOS(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryFFPOS.csv", "FFPOS", "FFPOS is required")
}
func TestMissingMandatoryGivenName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryGivenName.csv", "GivenName", "GivenName is required")
}
func TestMissingMandatoryIndigenousStatus(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryIndigenousStatus.csv", "IndigenousStatus", "IndigenousStatus is required")
}
func TestMissingMandatoryLocalId(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryLocalId.csv", "LocalId", "LocalId is required")
}
func TestMissingMandatoryParent1LOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent1LOTE.csv", "Parent1LOTE", "Parent1LOTE is required")
}
func TestMissingMandatoryParent1NonSchoolEducation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent1NonSchlEduc.csv", "Parent1NonSchoolEducation", "Parent1NonSchoolEducation is required")
}
func TestMissingMandatoryParent1Occupation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent1Occupation.csv", "Parent1Occupation", "Parent1Occupation is required")
}
func TestMissingMandatoryParent2LOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent2LOTE.csv", "Parent2LOTE", "Must be present if other Parent2 fields are present")
}
func TestMissingMandatoryParent2NonSchoolEducation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent2NonSchoolEduc.csv", "Parent2NonSchoolEducation", "Must be present if other Parent2 fields are present")
}
func TestMissingMandatoryParent2Occupation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent2Occupation.csv", "Parent2Occupation", "Must be present if other Parent2 fields are present")
}
func TestMissingMandatoryParent2SchoolEducation(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryParent2SchlEduc.csv", "Parent2SchoolEducation", "Must be present if other Parent2 fields are present")
}
func TestMissingMandatoryCountryOfBirth(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryStudentCountryBirth.csv", "CountryOfBirth", "CountryOfBirth is required")
}
func TestMissingMandatoryStudentLOTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryStudentLOTE.csv", "StudentLOTE", "StudentLOTE is required")
}
func TestMissingMandatoryTestLevel(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryTestLevel.csv", "TestLevel", "TestLevel is required")
}
func TestMissingMandatoryYearLevel(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsMissingMandatoryYearLevel.csv", "YearLevel", "YearLevel is required")
}
func TestOptionalMissing(t *testing.T) {
test_harness(t, "../../unit_test_files/4studentsOptionalMissing.csv", "", "")
}
func TestOutsideAgeRange3(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsOutsideAgeRange3.csv", "BirthDate/YearLevel", "Year Level calculated from BirthDate does not fall within expected NAPLAN year level ranges")
}
func TestOutsideAgeRange5(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsOutsideAgeRange5.csv", "BirthDate/YearLevel", "Year Level calculated from BirthDate does not fall within expected NAPLAN year level ranges")
}
func TestOutsideAgeRange7(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsOutsideAgeRange7.csv", "BirthDate/YearLevel", "Year Level calculated from BirthDate does not fall within expected NAPLAN year level ranges")
}
func TestOutsideAgeRange9(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsOutsideAgeRange9.csv", "BirthDate/YearLevel", "Year Level calculated from BirthDate does not fall within expected NAPLAN year level ranges")
}
func TestOutsideAgeRangeUG(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsOutsideAgeRangeUG.csv", "BirthDate/TestLevel", "Year level supplied is UG, will result in SRM warning flag for test level")
}
func TestSameStudentIdTwoDifferentSchoolId(t *testing.T) {
test_harness(t, "../../unit_test_files/2studentsSameStudentIdTwoDifferentSchoolId.csv", "", "")
}
func TestUngradedValuesUGJunSec(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsUngradedValuesUGJunSec.csv", "BirthDate/YearLevel", "Student Year Level (yr UGJunSec) does not match year level derived from BirthDate")
}
func TestUngradedValuesUGSnrSec(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsUngradedValuesUGSnrSec.csv", "BirthDate/YearLevel", "Student Year Level (yr UGSnrSec) does not match year level derived from BirthDate")
}
func TestUngradedValuesUGPri(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsUngradedValuesUGPri.csv", "BirthDate/YearLevel", "Student Year Level (yr UGPri) does not match year level derived from BirthDate")
}
func TestUngradedValuesUGSec(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsUngradedValuesUGSec.csv", "BirthDate/YearLevel", "Student Year Level (yr UGSec) does not match year level derived from BirthDate")
}
func TestUnusualCountryCodes(t *testing.T) {
test_harness(t, "../../unit_test_files/3studentsUnusualCountryCodes.csv", "", "")
}
func TestUnusualLanguageCodes(t *testing.T) {
test_harness(t, "../../unit_test_files/3studentsUnusualLanguageCodes.csv", "", "")
}
func TestWrongChecksumPlatformId(t *testing.T) {
test_harness(t, "../../unit_test_files/1WrongChecksumPlatformId.csv", "PlatformId", "Platform ID has incorrect checksum")
}
func TestWrongChecksumPreviousPlatformId(t *testing.T) {
test_harness(t, "../../unit_test_files/1WrongChecksumPrevPlatformId.csv", "PreviousPlatformId", "Previous Platform ID has incorrect checksum")
}
func TestYearLevelTestLevelMismatch(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsYearLevelTestLevelMismatch.csv", "BirthDate/TestLevel", "does not match Test level ")
}
func TestExtraneousNotPermittedField(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsExtraneousNotPermittedField.csv", "Pokemon", "Additional property Pokemon is not allowed")
}
func TestExtraneousPermittedField(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsExtraneousPermittedField.csv", "PossibleDuplicate", "Additional property PossibleDuplicate is not allowed")
}
func TestMaximumFTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1MaximumFTE.csv", "FTE", "FTE is greater than 1")
}
func TestMinimumFTE(t *testing.T) {
test_harness(t, "../../unit_test_files/1MinimumFTE.csv", "FTE", "FTE is less than 0")
}
func TestDupGivenLastNameDOBCARAId(t *testing.T) {
for i := 0; i < 20; i++ {
test_harness(t, "../../unit_test_files/2studentsDupGivenLastNameDOBSchool.csv", "Multiple (see description)", "otential duplicate of record")
}
}
func TestDuplicateStudentOneSchool(t *testing.T) {
for i := 0; i < 20; i++ {
test_harness(t, "../../unit_test_files/2studentsDuplicateStudentOneSchool.csv", "LocalID/ASL ID", "otential duplicate of record")
}
}
func TestSuspectCharactersFamilyName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsSuspectCharacterFamilyName.csv", "FamilyName", "Family Name contains suspect character")
}
func TestSuspectCharactersGivenName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsSuspectCharacterGivenName.csv", "GivenName", "Given Name contains suspect character")
}
func TestSuspectCharactersMiddleName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsSuspectCharacterMiddleName.csv", "MiddleName", "Middle Name contains suspect character")
}
func TestSuspectCharactersPreferredName(t *testing.T) {
test_harness(t, "../../unit_test_files/1studentsSuspectCharacterPreferredName.csv", "PreferredName", "Preferred Name contains suspect character")
}
func errcheck(t *testing.T, err error) {
if err != nil {
t.Fatalf("Error %s", err)
}
}
/* if errfield is nil, we expect test to pass */
func test_harness(t *testing.T, filename string, errfield string, errdescription string) {
var err error
//bytebuf := []byte{}
dat := map[string]string{}
txid, err := post_file(filename, "naplan/reg/validate")
errcheck(t, err)
time.Sleep(100 * time.Millisecond)
//err = customClient.Get(&bytebuf, "naplan/reg/results/"+txid, nil)
resp, err := customClient.R().Get("naplan/reg/results/" + txid)
errcheck(t, err)
//log.Println("+++" + string(bytebuf))
bytebuf := resp.Body()
// we are getting back line delimited JSON
lines := bytes.Split(bytebuf, []byte{'\n'})
// grab first error
//log.Println(">>>" + string(lines[0]) + "<<<")
if len(lines[0]) == 0 {
err = nil
} else {
//err = json.Unmarshal(bytebuf, &dat)
err = json.Unmarshal(lines[0], &dat)
}
errcheck(t, err)
// we are getting back a JSON array
/*
for i := 0; i < len(lines); i++ {
log.Println("\t" + string(lines[i]))
log.Println(dat)
}
*/
if errfield == "" {
if len(dat) > 0 {
t.Fatalf("Expected no error, got error in %s: %s", dat["errfield"], dat["description"])
}
} else {
if len(dat) < 1 {
t.Fatalf("Expected error field %s, got no error", errfield)
} else {
if dat["errField"] != errfield {
t.Fatalf("Expected error field %s, got field %s: %s", errfield, dat["errField"], dat["description"])
}
if !strings.Contains(dat["description"], errdescription) {
t.Fatalf("Expected error description %s, got description %s", errdescription, dat["description"])
}
}
}
}
func TestMain(m *testing.M) {
config := napval.LoadNAPLANConfig()
//customClient, _ = rest.New("http://localhost:" + config.WebServerPort + "/")
localAddress, _ := net.ResolveTCPAddr("tcp", "127.0.0.1")
customClient = resty.NewWithLocalAddr(localAddress)
customClient.SetHostURL("http://localhost:" + config.WebServerPort + "/")
os.Exit(m.Run())
}