@@ -191,8 +191,7 @@ mod test {
191
191
use crate :: schema:: {
192
192
ApplicableDirectionsTrackRange , BufferStop , BufferStopCache , Catenary , Detector ,
193
193
DetectorCache , Endpoint , ObjectRef , ObjectType , OperationalPoint , OperationalPointPart ,
194
- Route , Signal , SignalCache , Slope , SpeedSection , Switch , TrackEndpoint , TrackSection ,
195
- Waypoint ,
194
+ Route , Signal , SignalCache , SpeedSection , Switch , TrackEndpoint , TrackSection , Waypoint ,
196
195
} ;
197
196
use crate :: views:: pagination:: PaginatedResponse ;
198
197
use crate :: views:: tests:: create_test_service;
@@ -602,194 +601,165 @@ mod test {
602
601
#[ rstest:: rstest]
603
602
async fn empty_object ( ) {
604
603
let app = create_test_service ( ) . await ;
605
- let small_infra = small_infra ( db_pool ( ) ) . await ;
606
- let small_infra_id = small_infra . id ( ) ;
604
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
605
+ let empty_infra_id = empty_infra . id ( ) ;
607
606
608
607
let catenary: RailjsonObject = Catenary :: default ( ) . into ( ) ;
609
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
610
- assert_eq ! (
611
- call_service( & app, req_create) . await . status( ) ,
612
- StatusCode :: OK
613
- ) ;
608
+ let operational_point = OperationalPoint :: default ( ) . into ( ) ;
609
+ let speed_section = SpeedSection :: default ( ) . into ( ) ;
614
610
615
- let operational_point: RailjsonObject = OperationalPoint :: default ( ) . into ( ) ;
616
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
617
- assert_eq ! (
618
- call_service( & app, req_create) . await . status( ) ,
619
- StatusCode :: OK
620
- ) ;
621
-
622
- let speed_section: RailjsonObject = SpeedSection :: default ( ) . into ( ) ;
623
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
624
- assert_eq ! (
625
- call_service( & app, req_create) . await . status( ) ,
626
- StatusCode :: OK
627
- ) ;
611
+ for obj in [ & catenary, & operational_point, & speed_section] {
612
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
613
+ assert_eq ! (
614
+ call_service( & app, req_create) . await . status( ) ,
615
+ StatusCode :: OK
616
+ ) ;
617
+ }
628
618
629
- let response = call_service ( & app, auto_fixes_request ( small_infra_id ) ) . await ;
619
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id ) ) . await ;
630
620
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
631
621
632
622
let operations: Vec < Operation > = read_body_json ( response) . await ;
633
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
634
- obj_id: catenary. get_id( ) . to_string( ) ,
635
- obj_type: ObjectType :: Catenary ,
636
- } ) ) ) ;
637
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
638
- obj_id: operational_point. get_id( ) . to_string( ) ,
639
- obj_type: ObjectType :: OperationalPoint ,
640
- } ) ) ) ;
641
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
642
- obj_id: speed_section. get_id( ) . to_string( ) ,
643
- obj_type: ObjectType :: SpeedSection ,
644
- } ) ) ) ;
623
+
624
+ for obj in [ & catenary, & operational_point, & speed_section] {
625
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
626
+ obj_id: obj. get_id( ) . to_string( ) ,
627
+ obj_type: obj. get_type( ) ,
628
+ } ) ) )
629
+ }
645
630
}
646
631
647
632
#[ rstest:: rstest]
648
633
async fn out_of_range_must_be_ignored ( ) {
649
634
let app = create_test_service ( ) . await ;
650
- let small_infra = small_infra ( db_pool ( ) ) . await ;
651
- let small_infra_id = small_infra. id ( ) ;
635
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
636
+ let empty_infra_id = empty_infra. id ( ) ;
637
+
638
+ let track: RailjsonObject = TrackSection {
639
+ id : "test_track" . into ( ) ,
640
+ length : 1_000.0 ,
641
+ ..Default :: default ( )
642
+ }
643
+ . into ( ) ;
652
644
653
645
let catenary: RailjsonObject = Catenary {
654
646
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
655
- begin: 100000000000.0 ,
656
- end: 100000000001.0 ,
647
+ track: "test_track" . into( ) ,
648
+ begin: 250.0 ,
649
+ end: 1250.0 ,
657
650
..Default :: default ( )
658
651
} ] ,
659
652
..Default :: default ( )
660
653
}
661
654
. into ( ) ;
662
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
663
- assert_eq ! (
664
- call_service( & app, req_create) . await . status( ) ,
665
- StatusCode :: OK
666
- ) ;
667
655
668
656
let operational_point: RailjsonObject = OperationalPoint {
669
657
parts : vec ! [ OperationalPointPart {
670
- position: 10000000000000.0 ,
658
+ track: "test_track" . into( ) ,
659
+ position: 1250.0 ,
671
660
..Default :: default ( )
672
661
} ] ,
673
662
..Default :: default ( )
674
663
}
675
664
. into ( ) ;
676
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
677
- assert_eq ! (
678
- call_service( & app, req_create) . await . status( ) ,
679
- StatusCode :: OK
680
- ) ;
681
665
682
666
let speed_section: RailjsonObject = SpeedSection {
683
667
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
684
- begin: 100000000000.0 ,
685
- end: 100000000001.0 ,
668
+ track: "test_track" . into( ) ,
669
+ begin: 250.0 ,
670
+ end: 1250.0 ,
686
671
..Default :: default ( )
687
672
} ] ,
688
673
..Default :: default ( )
689
674
}
690
675
. into ( ) ;
691
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
692
- assert_eq ! (
693
- call_service( & app, req_create) . await . status( ) ,
694
- StatusCode :: OK
695
- ) ;
696
676
697
- let track_section: RailjsonObject = TrackSection {
698
- slopes : vec ! [ Slope {
699
- begin: 100000000000.0 ,
700
- end: 100000000001.0 ,
701
- gradient: 0.1 ,
702
- } ] ,
703
- ..Default :: default ( )
677
+ for obj in [ & track, & catenary, & operational_point, & speed_section] {
678
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
679
+ assert_eq ! (
680
+ call_service( & app, req_create) . await . status( ) ,
681
+ StatusCode :: OK
682
+ ) ;
704
683
}
705
- . into ( ) ;
706
- let req_create = get_create_operation_request ( track_section. clone ( ) , small_infra_id) ;
707
- assert_eq ! (
708
- call_service( & app, req_create) . await . status( ) ,
709
- StatusCode :: OK
710
- ) ;
711
-
712
- let response = call_service ( & app, auto_fixes_request ( small_infra_id) ) . await ;
713
684
685
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id) ) . await ;
714
686
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
715
687
716
688
let operations: Vec < Operation > = read_body_json ( response) . await ;
717
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
718
- obj_id: catenary. get_id( ) . to_string( ) ,
719
- obj_type: ObjectType :: Catenary ,
720
- } ) ) ) ;
721
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
722
- obj_id: operational_point. get_id( ) . to_string( ) ,
723
- obj_type: ObjectType :: OperationalPoint ,
724
- } ) ) ) ;
725
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
726
- obj_id: speed_section. get_id( ) . to_string( ) ,
727
- obj_type: ObjectType :: SpeedSection ,
728
- } ) ) ) ;
729
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
730
- obj_id: track_section. get_id( ) . to_string( ) ,
731
- obj_type: ObjectType :: TrackSection ,
732
- } ) ) ) ;
689
+
690
+ for obj in [ & catenary, & operational_point, & speed_section] {
691
+ assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
692
+ obj_id: obj. get_id( ) . to_string( ) ,
693
+ obj_type: obj. get_type( ) ,
694
+ } ) ) )
695
+ }
733
696
}
734
697
735
698
#[ rstest:: rstest]
736
- async fn out_of_range_must_be_deleted ( ) {
699
+ #[ case( 250. , 0 ) ]
700
+ #[ case( 1250. , 3 ) ]
701
+ async fn out_of_range_must_be_deleted ( #[ case] pos : f64 , #[ case] error_count : usize ) {
737
702
let app = create_test_service ( ) . await ;
738
- let small_infra = small_infra ( db_pool ( ) ) . await ;
739
- let small_infra_id = small_infra. id ( ) ;
703
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
704
+ let empty_infra_id = empty_infra. id ( ) ;
705
+
706
+ let track: RailjsonObject = TrackSection {
707
+ id : "test_track" . into ( ) ,
708
+ length : 1_000.0 ,
709
+ geo : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
710
+ vec![ 0.0 , 0.0 ] ,
711
+ vec![ 1.0 , 1.0 ] ,
712
+ ] ) ) ,
713
+ sch : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
714
+ vec![ 0.0 , 0.0 ] ,
715
+ vec![ 1.0 , 1.0 ] ,
716
+ ] ) ) ,
717
+ ..Default :: default ( )
718
+ }
719
+ . into ( ) ;
740
720
741
721
let signal: RailjsonObject = Signal {
742
- position : 10000000000000.0 ,
743
- track : "TC0 " . into ( ) ,
722
+ position : pos ,
723
+ track : "test_track " . into ( ) ,
744
724
..Default :: default ( )
745
725
}
746
726
. into ( ) ;
747
- let req_create = get_create_operation_request ( signal. clone ( ) , small_infra_id) ;
748
- assert_eq ! (
749
- call_service( & app, req_create) . await . status( ) ,
750
- StatusCode :: OK
751
- ) ;
752
727
753
728
let detector: RailjsonObject = Detector {
754
- position : 10000000000000.0 ,
755
- track : "TC0 " . into ( ) ,
729
+ position : pos ,
730
+ track : "test_track " . into ( ) ,
756
731
..Default :: default ( )
757
732
}
758
733
. into ( ) ;
759
- let req_create = get_create_operation_request ( detector. clone ( ) , small_infra_id) ;
760
- assert_eq ! (
761
- call_service( & app, req_create) . await . status( ) ,
762
- StatusCode :: OK
763
- ) ;
764
734
765
735
let buffer_stop: RailjsonObject = BufferStop {
766
- position : 10000000000000.0 ,
767
- track : "TC0 " . into ( ) ,
736
+ position : pos ,
737
+ track : "test_track " . into ( ) ,
768
738
..Default :: default ( )
769
739
}
770
740
. into ( ) ;
771
- let req_create = get_create_operation_request ( buffer_stop. clone ( ) , small_infra_id) ;
772
- assert_eq ! (
773
- call_service( & app, req_create) . await . status( ) ,
774
- StatusCode :: OK
775
- ) ;
776
741
777
- let response = call_service ( & app, auto_fixes_request ( small_infra_id) ) . await ;
742
+ for obj in [ & track, & signal, & detector, & buffer_stop] {
743
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
744
+ assert_eq ! (
745
+ call_service( & app, req_create) . await . status( ) ,
746
+ StatusCode :: OK
747
+ ) ;
748
+ }
778
749
750
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id) ) . await ;
779
751
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
780
752
781
753
let operations: Vec < Operation > = read_body_json ( response) . await ;
782
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
783
- obj_id: signal. get_id( ) . to_string( ) ,
784
- obj_type: ObjectType :: Signal ,
785
- } ) ) ) ;
786
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
787
- obj_id: detector. get_id( ) . to_string( ) ,
788
- obj_type: ObjectType :: Detector ,
789
- } ) ) ) ;
790
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
791
- obj_id: buffer_stop. get_id( ) . to_string( ) ,
792
- obj_type: ObjectType :: BufferStop ,
793
- } ) ) ) ;
754
+ assert_eq ! ( operations. len( ) , error_count) ;
755
+
756
+ if !operations. is_empty ( ) {
757
+ for obj in [ & signal, & detector, & buffer_stop] {
758
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
759
+ obj_id: obj. get_id( ) . to_string( ) ,
760
+ obj_type: obj. get_type( ) ,
761
+ } ) ) )
762
+ }
763
+ }
794
764
}
795
765
}
0 commit comments