@@ -632,195 +632,171 @@ mod test {
632
632
#[ rstest:: rstest]
633
633
async fn empty_object ( ) {
634
634
let app = create_test_service ( ) . await ;
635
- let small_infra = small_infra ( db_pool ( ) ) . await ;
636
- 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
637
638
638
let catenary: RailjsonObject = Catenary :: default ( ) . into ( ) ;
639
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
640
- assert_eq ! (
641
- call_service( & app, req_create) . await . status( ) ,
642
- StatusCode :: OK
643
- ) ;
639
+ let operational_point = OperationalPoint :: default ( ) . into ( ) ;
640
+ let speed_section = SpeedSection :: default ( ) . into ( ) ;
644
641
645
- let operational_point: RailjsonObject = OperationalPoint :: default ( ) . into ( ) ;
646
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
647
- assert_eq ! (
648
- call_service( & app, req_create) . await . status( ) ,
649
- StatusCode :: OK
650
- ) ;
651
-
652
- let speed_section: RailjsonObject = SpeedSection :: default ( ) . into ( ) ;
653
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
654
- assert_eq ! (
655
- call_service( & app, req_create) . await . status( ) ,
656
- StatusCode :: OK
657
- ) ;
642
+ for obj in [ & catenary, & operational_point, & speed_section] {
643
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
644
+ assert_eq ! (
645
+ call_service( & app, req_create) . await . status( ) ,
646
+ StatusCode :: OK
647
+ ) ;
648
+ }
658
649
659
- let response = call_service ( & app, auto_fixes_request ( small_infra_id ) ) . await ;
650
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id ) ) . await ;
660
651
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
661
652
662
653
let operations: Vec < Operation > = read_body_json ( response) . await ;
663
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
664
- obj_id: catenary. get_id( ) . to_string( ) ,
665
- obj_type: ObjectType :: Catenary ,
666
- } ) ) ) ;
667
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
668
- obj_id: operational_point. get_id( ) . to_string( ) ,
669
- obj_type: ObjectType :: OperationalPoint ,
670
- } ) ) ) ;
671
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
672
- obj_id: speed_section. get_id( ) . to_string( ) ,
673
- obj_type: ObjectType :: SpeedSection ,
674
- } ) ) ) ;
654
+
655
+ for obj in [ & catenary, & operational_point, & speed_section] {
656
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
657
+ obj_id: obj. get_id( ) . to_string( ) ,
658
+ obj_type: obj. get_type( ) ,
659
+ } ) ) )
660
+ }
675
661
}
676
662
677
663
#[ rstest:: rstest]
678
664
async fn out_of_range_must_be_ignored ( ) {
679
665
let app = create_test_service ( ) . await ;
680
- let small_infra = small_infra ( db_pool ( ) ) . await ;
681
- let small_infra_id = small_infra. id ( ) ;
666
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
667
+ let empty_infra_id = empty_infra. id ( ) ;
668
+
669
+ let track: RailjsonObject = TrackSection {
670
+ id : "test_track" . into ( ) ,
671
+ length : 1_000.0 ,
672
+ slopes : vec ! [ Slope {
673
+ begin: 250.0 ,
674
+ end: 1250.0 ,
675
+ gradient: 0. ,
676
+ } ] ,
677
+ ..Default :: default ( )
678
+ }
679
+ . into ( ) ;
682
680
683
681
let catenary: RailjsonObject = Catenary {
684
682
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
685
- begin: 100000000000.0 ,
686
- end: 100000000001.0 ,
683
+ track: "test_track" . into( ) ,
684
+ begin: 250.0 ,
685
+ end: 1250.0 ,
687
686
..Default :: default ( )
688
687
} ] ,
689
688
..Default :: default ( )
690
689
}
691
690
. into ( ) ;
692
- let req_create = get_create_operation_request ( catenary. clone ( ) , small_infra_id) ;
693
- assert_eq ! (
694
- call_service( & app, req_create) . await . status( ) ,
695
- StatusCode :: OK
696
- ) ;
697
691
698
692
let operational_point: RailjsonObject = OperationalPoint {
699
693
parts : vec ! [ OperationalPointPart {
700
- position: 10000000000000.0 ,
694
+ track: "test_track" . into( ) ,
695
+ position: 1250.0 ,
701
696
..Default :: default ( )
702
697
} ] ,
703
698
..Default :: default ( )
704
699
}
705
700
. into ( ) ;
706
- let req_create = get_create_operation_request ( operational_point. clone ( ) , small_infra_id) ;
707
- assert_eq ! (
708
- call_service( & app, req_create) . await . status( ) ,
709
- StatusCode :: OK
710
- ) ;
711
701
712
702
let speed_section: RailjsonObject = SpeedSection {
713
703
track_ranges : vec ! [ ApplicableDirectionsTrackRange {
714
- begin: 100000000000.0 ,
715
- end: 100000000001.0 ,
704
+ track: "test_track" . into( ) ,
705
+ begin: 250.0 ,
706
+ end: 1250.0 ,
716
707
..Default :: default ( )
717
708
} ] ,
718
709
..Default :: default ( )
719
710
}
720
711
. into ( ) ;
721
- let req_create = get_create_operation_request ( speed_section. clone ( ) , small_infra_id) ;
722
- assert_eq ! (
723
- call_service( & app, req_create) . await . status( ) ,
724
- StatusCode :: OK
725
- ) ;
726
712
727
- let track_section: RailjsonObject = TrackSection {
728
- slopes : vec ! [ Slope {
729
- begin: 100000000000.0 ,
730
- end: 100000000001.0 ,
731
- gradient: 0.1 ,
732
- } ] ,
733
- ..Default :: default ( )
713
+ for obj in [ & track, & catenary, & operational_point, & speed_section] {
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
+ ) ;
734
719
}
735
- . into ( ) ;
736
- let req_create = get_create_operation_request ( track_section. clone ( ) , small_infra_id) ;
737
- assert_eq ! (
738
- call_service( & app, req_create) . await . status( ) ,
739
- StatusCode :: OK
740
- ) ;
741
-
742
- let response = call_service ( & app, auto_fixes_request ( small_infra_id) ) . await ;
743
720
721
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id) ) . await ;
744
722
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
745
723
746
724
let operations: Vec < Operation > = read_body_json ( response) . await ;
747
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
748
- obj_id: catenary. get_id( ) . to_string( ) ,
749
- obj_type: ObjectType :: Catenary ,
750
- } ) ) ) ;
751
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
752
- obj_id: operational_point. get_id( ) . to_string( ) ,
753
- obj_type: ObjectType :: OperationalPoint ,
754
- } ) ) ) ;
755
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
756
- obj_id: speed_section. get_id( ) . to_string( ) ,
757
- obj_type: ObjectType :: SpeedSection ,
758
- } ) ) ) ;
759
- assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
760
- obj_id: track_section. get_id( ) . to_string( ) ,
761
- obj_type: ObjectType :: TrackSection ,
762
- } ) ) ) ;
725
+
726
+ for obj in [ & track, & catenary, & operational_point, & speed_section] {
727
+ assert ! ( !operations. contains( & Operation :: Delete ( DeleteOperation {
728
+ obj_id: obj. get_id( ) . to_string( ) ,
729
+ obj_type: obj. get_type( ) ,
730
+ } ) ) )
731
+ }
763
732
}
764
733
765
734
#[ rstest:: rstest]
766
- async fn out_of_range_must_be_deleted ( ) {
735
+ #[ case( 250. , 1 ) ]
736
+ #[ case( 1250. , 5 ) ]
737
+ async fn out_of_range_must_be_deleted ( #[ case] pos : f64 , #[ case] error_count : usize ) {
767
738
let app = create_test_service ( ) . await ;
768
- let small_infra = small_infra ( db_pool ( ) ) . await ;
769
- let small_infra_id = small_infra. id ( ) ;
739
+ let empty_infra = empty_infra ( db_pool ( ) ) . await ;
740
+ let empty_infra_id = empty_infra. id ( ) ;
741
+
742
+ let track: RailjsonObject = TrackSection {
743
+ id : "test_track" . into ( ) ,
744
+ length : 1_000.0 ,
745
+ geo : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
746
+ vec![ 0.0 , 0.0 ] ,
747
+ vec![ 1.0 , 1.0 ] ,
748
+ ] ) ) ,
749
+ sch : geos:: geojson:: Geometry :: new ( geos:: geojson:: Value :: LineString ( vec ! [
750
+ vec![ 0.0 , 0.0 ] ,
751
+ vec![ 1.0 , 1.0 ] ,
752
+ ] ) ) ,
753
+ ..Default :: default ( )
754
+ }
755
+ . into ( ) ;
770
756
771
757
let signal: RailjsonObject = Signal {
772
- position : 10000000000000.0 ,
773
- track : "TC0 " . into ( ) ,
758
+ position : pos ,
759
+ track : "test_track " . into ( ) ,
774
760
..Default :: default ( )
775
761
}
776
762
. into ( ) ;
777
- let req_create = get_create_operation_request ( signal. clone ( ) , small_infra_id) ;
778
- assert_eq ! (
779
- call_service( & app, req_create) . await . status( ) ,
780
- StatusCode :: OK
781
- ) ;
782
763
783
764
let detector: RailjsonObject = Detector {
784
- position : 10000000000000.0 ,
785
- track : "TC0 " . into ( ) ,
765
+ position : pos ,
766
+ track : "test_track " . into ( ) ,
786
767
..Default :: default ( )
787
768
}
788
769
. into ( ) ;
789
- let req_create = get_create_operation_request ( detector. clone ( ) , small_infra_id) ;
790
- assert_eq ! (
791
- call_service( & app, req_create) . await . status( ) ,
792
- StatusCode :: OK
793
- ) ;
794
770
795
771
let buffer_stop: RailjsonObject = BufferStop {
796
- position : 10000000000000.0 ,
797
- track : "TC0 " . into ( ) ,
772
+ position : pos ,
773
+ track : "test_track " . into ( ) ,
798
774
..Default :: default ( )
799
775
}
800
776
. into ( ) ;
801
- let req_create = get_create_operation_request ( buffer_stop. clone ( ) , small_infra_id) ;
802
- assert_eq ! (
803
- call_service( & app, req_create) . await . status( ) ,
804
- StatusCode :: OK
805
- ) ;
806
777
807
- let response = call_service ( & app, auto_fixes_request ( small_infra_id) ) . await ;
778
+ for obj in [ & track, & signal, & detector, & buffer_stop] {
779
+ let req_create = get_create_operation_request ( obj. clone ( ) , empty_infra_id) ;
780
+ assert_eq ! (
781
+ call_service( & app, req_create) . await . status( ) ,
782
+ StatusCode :: OK
783
+ ) ;
784
+ }
808
785
786
+ let response = call_service ( & app, auto_fixes_request ( empty_infra_id) ) . await ;
809
787
assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
810
788
811
789
let operations: Vec < Operation > = read_body_json ( response) . await ;
812
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
813
- obj_id: signal. get_id( ) . to_string( ) ,
814
- obj_type: ObjectType :: Signal ,
815
- } ) ) ) ;
816
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
817
- obj_id: detector. get_id( ) . to_string( ) ,
818
- obj_type: ObjectType :: Detector ,
819
- } ) ) ) ;
820
- assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
821
- obj_id: buffer_stop. get_id( ) . to_string( ) ,
822
- obj_type: ObjectType :: BufferStop ,
823
- } ) ) ) ;
790
+ assert_eq ! ( operations. len( ) , error_count) ;
791
+
792
+ if !operations. len ( ) == 5 {
793
+ for obj in [ & signal, & detector, & buffer_stop] {
794
+ assert ! ( operations. contains( & Operation :: Delete ( DeleteOperation {
795
+ obj_id: obj. get_id( ) . to_string( ) ,
796
+ obj_type: obj. get_type( ) ,
797
+ } ) ) )
798
+ }
799
+ }
824
800
}
825
801
826
802
#[ rstest:: rstest]
0 commit comments