@@ -26,6 +26,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
26
26
TokenService tokenService = Mock (TokenService )
27
27
SettingService settingService = Mock (SettingService )
28
28
MetadataService metadataService = Mock (MetadataService )
29
+ SpeciesReMatchService speciesReMatchService = Mock (SpeciesReMatchService )
29
30
ActivityService activityService = Mock (ActivityService )
30
31
RecordService recordService = Mock (RecordService )
31
32
UserService userService = Mock (UserService )
@@ -55,6 +56,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
55
56
service. recordService = recordService
56
57
service. cacheService = new CacheService ()
57
58
service. userService = userService
59
+ service. speciesReMatchService = speciesReMatchService
58
60
59
61
JSON . registerObjectMarshaller(new MapMarshaller ())
60
62
JSON . registerObjectMarshaller(new CollectionMarshaller ())
@@ -654,25 +656,6 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
654
656
result == " "
655
657
}
656
658
657
- void " transformSpeciesName should convert paratoo species name to object correctly" () {
658
- when :
659
- Map result = service. transformSpeciesName(" Acacia glauca [Species] (scientific: Acacia glauca Willd.)" )
660
- String outputSpeciesId = result. remove(" outputSpeciesId" )
661
- then :
662
- outputSpeciesId != null
663
- result == [name : " Acacia glauca Willd." , scientificName : " Acacia glauca Willd." , guid : " A_GUID" , commonName : " Acacia glauca" , taxonRank : " Species" ]
664
- 2 * metadataService. autoPopulateSpeciesData(_) >> null
665
-
666
- when : // no scientific name
667
- result = service. transformSpeciesName(" Frogs [Class] (scientific: )" )
668
- outputSpeciesId = result. remove(" outputSpeciesId" )
669
-
670
- then :
671
- outputSpeciesId != null
672
- result == [name : " Frogs" , scientificName : " Frogs" , guid : " A_GUID" , commonName : " Frogs" , taxonRank : " Class" ]
673
- 2 * metadataService. autoPopulateSpeciesData(_) >> null
674
- }
675
-
676
659
void " buildRelationshipTree should build relationship tree correctly" () {
677
660
given :
678
661
def properties = [
@@ -723,6 +706,25 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
723
706
relationships[" fauna-survey" ]. contains(" fauna-observation" )
724
707
}
725
708
709
+ void " transformSpeciesName should convert paratoo species name to object correctly" () {
710
+ when :
711
+ Map result = service. transformSpeciesName(" Acacia glauca [Species] (scientific: Acacia glauca Willd.)" )
712
+ String outputSpeciesId = result. remove(" outputSpeciesId" )
713
+ then :
714
+ outputSpeciesId != null
715
+ result == [name : " Acacia glauca Willd. (Acacia glauca)" , scientificName : " Acacia glauca Willd." , guid : " A_GUID" , commonName : " Acacia glauca" , taxonRank : " Species" ]
716
+ 2 * speciesReMatchService. searchByName(_) >> null
717
+
718
+ when : // no scientific name
719
+ result = service. transformSpeciesName(" Frogs [Class] (scientific: )" )
720
+ outputSpeciesId = result. remove(" outputSpeciesId" )
721
+
722
+ then :
723
+ outputSpeciesId != null
724
+ result == [name : " Frogs" , scientificName : " " , guid : " A_GUID" , commonName : " Frogs" , taxonRank : " Class" ]
725
+ 2 * speciesReMatchService. searchByName(_) >> null
726
+ }
727
+
726
728
void " buildTreeFromParentChildRelationships should build tree correctly" () {
727
729
given :
728
730
def relationships = [
@@ -1399,13 +1401,19 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
1399
1401
result. lut. remove(' outputSpeciesId' )
1400
1402
1401
1403
then :
1404
+ 1 * speciesReMatchService. searchByName(_) >> [
1405
+ commonName : " Cat" ,
1406
+ scientificName : " Felis catus" ,
1407
+ guid : " TAXON_ID" ,
1408
+ taxonRank : " species"
1409
+ ]
1402
1410
result == [
1403
1411
lut : [
1404
1412
commonName : " Cat" ,
1405
- name : " Cat" ,
1406
- taxonRank : null ,
1407
- scientificName : " Cat " ,
1408
- guid : " A_GUID "
1413
+ name : " Felis catus ( Cat) " ,
1414
+ taxonRank : " species " ,
1415
+ scientificName : " Felis catus " ,
1416
+ guid : " TAXON_ID "
1409
1417
]
1410
1418
]
1411
1419
@@ -1417,18 +1425,25 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
1417
1425
]
1418
1426
]
1419
1427
output = [
1420
- lut : " Cat "
1428
+ lut : " Cats [Species] (scientific: Felis catus) "
1421
1429
]
1422
1430
result = service. recursivelyTransformData(dataModel, output, formName, 1 , null )
1423
1431
result. lut. remove(' outputSpeciesId' )
1424
1432
then :
1433
+ 1 * speciesReMatchService. searchByName(" Felis catus" ) >> null
1434
+ 1 * speciesReMatchService. searchByName(" Cats" ) >> [
1435
+ commonName : " Cat" ,
1436
+ scientificName : " Felis catus" ,
1437
+ guid : " TAXON_ID" ,
1438
+ taxonRank : " species"
1439
+ ]
1425
1440
result == [
1426
1441
lut : [
1427
- commonName : " Cat " ,
1428
- name : " Cat " ,
1429
- taxonRank : null ,
1430
- scientificName : " Cat " ,
1431
- guid : " A_GUID "
1442
+ commonName : " Cats " ,
1443
+ name : " Felis catus (Cats) " ,
1444
+ taxonRank : " species " ,
1445
+ scientificName : " Felis catus " ,
1446
+ guid : " TAXON_ID "
1432
1447
]
1433
1448
]
1434
1449
}
0 commit comments