@@ -194,8 +194,7 @@ mod test {
194
194
use crate :: schema:: {
195
195
ApplicableDirectionsTrackRange , BufferStop , BufferStopCache , Catenary , Detector ,
196
196
DetectorCache , Endpoint , ObjectRef , ObjectType , OperationalPoint , OperationalPointPart ,
197
- Route , Signal , SignalCache , Slope , SpeedSection , Switch , TrackEndpoint , TrackSection ,
198
- Waypoint ,
197
+ Route , Signal , SignalCache , SpeedSection , Switch , TrackEndpoint , TrackSection , Waypoint ,
199
198
} ;
200
199
use crate :: views:: tests:: create_test_service;
201
200
use actix_http:: { Request , StatusCode } ;
@@ -565,204 +564,177 @@ mod test {
565
564
#[ rstest:: rstest]
566
565
async fn empty_object ( ) {
567
566
let app = create_test_service ( ) . await ;
568
- let small_infra = small_infra ( db_pool ( ) ) . await ;
569
- let small_infra_id = small_infra . id ( ) ;
567
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
568
+ let empty_infra_id = empty_infra . id ( ) ;
570
569
571
570
let catenary: RailjsonObject = Catenary :: default ( ) . into ( ) ;
572
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
573
- assert_eq ! (
574
- call_service( & app, req_create) . await . status( ) ,
575
- StatusCode :: OK
576
- ) ;
571
+ let operational_point = OperationalPoint :: default ( ) . into ( ) ;
572
+ let speed_section = SpeedSection :: default ( ) . into ( ) ;
577
573
578
- let operational_point: RailjsonObject = OperationalPoint :: default ( ) . into ( ) ;
579
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
580
- assert_eq ! (
581
- call_service( & app, req_create) . await . status( ) ,
582
- StatusCode :: OK
583
- ) ;
584
-
585
- let speed_section: RailjsonObject = SpeedSection :: default ( ) . into ( ) ;
586
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
587
- assert_eq ! (
588
- call_service( & app, req_create) . await . status( ) ,
589
- StatusCode :: OK
590
- ) ;
574
+ for obj in [ & catenary, & operational_point, & speed_section] {
575
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
576
+ assert_eq ! (
577
+ call_service( & app, req_create) . await . status( ) ,
578
+ StatusCode :: OK
579
+ ) ;
580
+ }
591
581
592
582
let req_fix = TestRequest :: get ( )
593
- . uri ( format ! ( "/infra/{small_infra_id }/auto_fixes" ) . as_str ( ) )
583
+ . uri ( format ! ( "/infra/{empty_infra_id }/auto_fixes" ) . as_str ( ) )
594
584
. to_request ( ) ;
595
585
let response = call_service ( & app, req_fix) . await ;
596
586
597
587
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
598
588
599
589
let operations: Vec < Operation > = read_body_json ( response) . await ;
600
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
601
- obj_id: catenary. get_id( ) . to_string( ) ,
602
- obj_type: ObjectType :: Catenary ,
603
- } ) ) ) ;
604
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
605
- obj_id: operational_point. get_id( ) . to_string( ) ,
606
- obj_type: ObjectType :: OperationalPoint ,
607
- } ) ) ) ;
608
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
609
- obj_id: speed_section. get_id( ) . to_string( ) ,
610
- obj_type: ObjectType :: SpeedSection ,
611
- } ) ) ) ;
590
+
591
+ for obj in [ & catenary, & operational_point, & speed_section] {
592
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
593
+ obj_id: obj. get_id( ) . to_string( ) ,
594
+ obj_type: obj. get_type( ) ,
595
+ } ) ) )
596
+ }
612
597
}
613
598
614
599
#[ rstest:: rstest]
615
600
async fn out_of_range_must_be_ignored ( ) {
616
601
let app = create_test_service ( ) . await ;
617
- let small_infra = small_infra ( db_pool ( ) ) . await ;
618
- let small_infra_id = small_infra. id ( ) ;
602
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
603
+ let empty_infra_id = empty_infra. id ( ) ;
604
+
605
+ let track: RailjsonObject = TrackSection {
606
+ id : "test_track" . into ( ) ,
607
+ length : 1_000.0 ,
608
+ ..Default :: default ( )
609
+ }
610
+ . into ( ) ;
619
611
620
612
let catenary: RailjsonObject = Catenary {
621
613
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
622
- begin: 100000000000.0 ,
623
- end: 100000000001.0 ,
614
+ track: "test_track" . into( ) ,
615
+ begin: 250.0 ,
616
+ end: 1250.0 ,
624
617
..Default :: default ( )
625
618
} ] ,
626
619
..Default :: default ( )
627
620
}
628
621
. into ( ) ;
629
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
630
- assert_eq ! (
631
- call_service( & app, req_create) . await . status( ) ,
632
- StatusCode :: OK
633
- ) ;
634
622
635
623
let operational_point: RailjsonObject = OperationalPoint {
636
624
parts : vec ! [ OperationalPointPart {
637
- position: 10000000000000.0 ,
625
+ track: "test_track" . into( ) ,
626
+ position: 1250.0 ,
638
627
..Default :: default ( )
639
628
} ] ,
640
629
..Default :: default ( )
641
630
}
642
631
. into ( ) ;
643
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
644
- assert_eq ! (
645
- call_service( & app, req_create) . await . status( ) ,
646
- StatusCode :: OK
647
- ) ;
648
632
649
633
let speed_section: RailjsonObject = SpeedSection {
650
634
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
651
- begin: 100000000000.0 ,
652
- end: 100000000001.0 ,
635
+ track: "test_track" . into( ) ,
636
+ begin: 250.0 ,
637
+ end: 1250.0 ,
653
638
..Default :: default ( )
654
639
} ] ,
655
640
..Default :: default ( )
656
641
}
657
642
. into ( ) ;
658
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
659
- assert_eq ! (
660
- call_service( & app, req_create) . await . status( ) ,
661
- StatusCode :: OK
662
- ) ;
663
643
664
- let track_section: RailjsonObject = TrackSection {
665
- slopes : vec ! [ Slope {
666
- begin: 100000000000.0 ,
667
- end: 100000000001.0 ,
668
- gradient: 0.1 ,
669
- } ] ,
670
- ..Default :: default ( )
644
+ for obj in [ & track, & catenary, & operational_point, & speed_section] {
645
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
646
+ assert_eq ! (
647
+ call_service( & app, req_create) . await . status( ) ,
648
+ StatusCode :: OK
649
+ ) ;
671
650
}
672
- . into ( ) ;
673
- let req_create = get_create_operation_request ( track_section. clone ( ) , small_infra_id) ;
674
- assert_eq ! (
675
- call_service( & app, req_create) . await . status( ) ,
676
- StatusCode :: OK
677
- ) ;
678
651
679
652
let req_fix = TestRequest :: get ( )
680
- . uri ( format ! ( "/infra/{small_infra_id }/auto_fixes" ) . as_str ( ) )
653
+ . uri ( format ! ( "/infra/{empty_infra_id }/auto_fixes" ) . as_str ( ) )
681
654
. to_request ( ) ;
682
655
let response = call_service ( & app, req_fix) . await ;
683
656
684
657
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
685
658
686
659
let operations: Vec < Operation > = read_body_json ( response) . await ;
687
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
688
- obj_id: catenary. get_id( ) . to_string( ) ,
689
- obj_type: ObjectType :: Catenary ,
690
- } ) ) ) ;
691
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
692
- obj_id: operational_point. get_id( ) . to_string( ) ,
693
- obj_type: ObjectType :: OperationalPoint ,
694
- } ) ) ) ;
695
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
696
- obj_id: speed_section. get_id( ) . to_string( ) ,
697
- obj_type: ObjectType :: SpeedSection ,
698
- } ) ) ) ;
699
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
700
- obj_id: track_section. get_id( ) . to_string( ) ,
701
- obj_type: ObjectType :: TrackSection ,
702
- } ) ) ) ;
660
+
661
+ for obj in [ & catenary, & operational_point, & speed_section] {
662
+ assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
663
+ obj_id: obj. get_id( ) . to_string( ) ,
664
+ obj_type: obj. get_type( ) ,
665
+ } ) ) )
666
+ }
703
667
}
704
668
705
669
#[ rstest:: rstest]
706
- async fn out_of_range_must_be_deleted ( ) {
670
+ #[ case( 250. , 0 ) ]
671
+ #[ case( 1250. , 3 ) ]
672
+ async fn out_of_range_must_be_deleted ( #[ case] pos : f64 , #[ case] error_count : usize ) {
707
673
let app = create_test_service ( ) . await ;
708
- let small_infra = small_infra ( db_pool ( ) ) . await ;
709
- let small_infra_id = small_infra. id ( ) ;
674
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
675
+ let empty_infra_id = empty_infra. id ( ) ;
676
+
677
+ let track: RailjsonObject = TrackSection {
678
+ id : "test_track" . into ( ) ,
679
+ length : 1_000.0 ,
680
+ geo : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
681
+ vec![ 0.0 , 0.0 ] ,
682
+ vec![ 1.0 , 1.0 ] ,
683
+ ] ) ) ,
684
+ sch : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
685
+ vec![ 0.0 , 0.0 ] ,
686
+ vec![ 1.0 , 1.0 ] ,
687
+ ] ) ) ,
688
+ ..Default :: default ( )
689
+ }
690
+ . into ( ) ;
710
691
711
692
let signal: RailjsonObject = Signal {
712
- position : 10000000000000.0 ,
713
- track : "TC0 " . into ( ) ,
693
+ position : pos ,
694
+ track : "test_track " . into ( ) ,
714
695
..Default :: default ( )
715
696
}
716
697
. into ( ) ;
717
- let req_create = get_create_operation_request ( signal. clone ( ) , small_infra_id) ;
718
- assert_eq ! (
719
- call_service( & app, req_create) . await . status( ) ,
720
- StatusCode :: OK
721
- ) ;
722
698
723
699
let detector: RailjsonObject = Detector {
724
- position : 10000000000000.0 ,
725
- track : "TC0 " . into ( ) ,
700
+ position : pos ,
701
+ track : "test_track " . into ( ) ,
726
702
..Default :: default ( )
727
703
}
728
704
. into ( ) ;
729
- let req_create = get_create_operation_request ( detector. clone ( ) , small_infra_id) ;
730
- assert_eq ! (
731
- call_service( & app, req_create) . await . status( ) ,
732
- StatusCode :: OK
733
- ) ;
734
705
735
706
let buffer_stop: RailjsonObject = BufferStop {
736
- position : 10000000000000.0 ,
737
- track : "TC0 " . into ( ) ,
707
+ position : pos ,
708
+ track : "test_track " . into ( ) ,
738
709
..Default :: default ( )
739
710
}
740
711
. into ( ) ;
741
- let req_create = get_create_operation_request ( buffer_stop. clone ( ) , small_infra_id) ;
742
- assert_eq ! (
743
- call_service( & app, req_create) . await . status( ) ,
744
- StatusCode :: OK
745
- ) ;
712
+
713
+ for obj in [ & track, & signal, & detector, & buffer_stop] {
714
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
715
+ assert_eq ! (
716
+ call_service( & app, req_create) . await . status( ) ,
717
+ StatusCode :: OK
718
+ ) ;
719
+ }
746
720
747
721
let req_fix = TestRequest :: get ( )
748
- . uri ( format ! ( "/infra/{small_infra_id }/auto_fixes" ) . as_str ( ) )
722
+ . uri ( format ! ( "/infra/{empty_infra_id }/auto_fixes" ) . as_str ( ) )
749
723
. to_request ( ) ;
750
724
let response = call_service ( & app, req_fix) . await ;
751
725
752
726
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
753
727
754
728
let operations: Vec < Operation > = read_body_json ( response) . await ;
755
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
756
- obj_id: signal. get_id( ) . to_string( ) ,
757
- obj_type: ObjectType :: Signal ,
758
- } ) ) ) ;
759
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
760
- obj_id: detector. get_id( ) . to_string( ) ,
761
- obj_type: ObjectType :: Detector ,
762
- } ) ) ) ;
763
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
764
- obj_id: buffer_stop. get_id( ) . to_string( ) ,
765
- obj_type: ObjectType :: BufferStop ,
766
- } ) ) ) ;
729
+ assert_eq ! ( operations. len( ) , error_count) ;
730
+
731
+ if !operations. is_empty ( ) {
732
+ for obj in [ & signal, & detector, & buffer_stop] {
733
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
734
+ obj_id: obj. get_id( ) . to_string( ) ,
735
+ obj_type: obj. get_type( ) ,
736
+ } ) ) )
737
+ }
738
+ }
767
739
}
768
740
}
0 commit comments