Beispiel #1
0
 internal static void RunSecurityTests(Options options)
 {
     RunTests(options, "Security", Out.Info,
              new CheckCompletenessResponseTest
     {
         RelativeUrl = GetEventsLatest(),
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInEvents()
     },
              // 1                 // note: this is the same test as runfunctionality - the last one.
              new CheckCertificateTest {
         RelativeUrl = GetEventsLatest()
     },                                                                // 2
              new CallingWithInvalidCredentials
     {
         RelativeUrl    = GetEventsLatest(),
         UseCredentials = HttpTestBase.AuthenticationMode.UseInvalidCredentials
     },     // 3
              new CallingWithInvalidCredentials
     {
         RelativeUrl    = GetEventsLatest(),
         UseCredentials = HttpTestBase.AuthenticationMode.UseNoCredentials
     },     // 4
              new CheckHttpAvailableTest {
         RelativeUrl = GetEventsLatest()
     },
              new CallingWithInvalidCredentials
     {
         RelativeUrl    = GetVehicleStateLatest(),
         UseCredentials = HttpTestBase.AuthenticationMode.UseNoCredentials
     }    // 5
              );
 }
        public TestResultBase Test(Options o)
        {
            var testResult = new GenericTestResult
            {
                ShortDescription = "Performance (uptime) " + RelativeUrl,
                Status           = TestResult.INCONCLUSIVE
            };

            DateTime current         = DateTime.Now; // to check if we elapsed total seconds.
            var      results         = new List <Tuple <long, TestResult> >();
            long     lastMessageTime = 0;

            while (true)
            {
                var test = new CheckCompletenessResponseTest
                {
                    RelativeUrl = string.Format("/fcd?last_message_time={0}", lastMessageTime),
                    FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInFCD(),
                    TestResultWhenNoData      = TestResult.OK
                };

                TestResultBase res = test.Test(o);
                results.Add(new Tuple <long, TestResult>(test.RequestDuration, res.Status));

                if (test.ResponseData != null)
                {
                    // now store the last updated time from the previous
                    string data = test.ResponseData;
                    // deserialize
                    var fcdMsg = JsonConvert.DeserializeObject <FcdMessage>(data);

                    if (lastMessageTime == fcdMsg.message_time)
                    {
                        GenerationTimeValid = false;
                    }
                    else
                    {
                        if (!GenerationTimeValid.HasValue)
                        {
                            GenerationTimeValid = true;
                        }
                    }
                    lastMessageTime = fcdMsg.message_time;
                }
                else
                {
                    GenerationTimeValid = false;
                }
                Thread.Sleep(IntervalTime);
                if (DateTime.Now.Subtract(current).TotalSeconds >= TestDuration)
                {
                    break;
                }
            }

            IEnumerable <Tuple <long, TestResult> > succesCount = results.Where(t => t.Item2 == TestResult.OK);
            double percentageSuccess = succesCount.Count() / (double)results.Count;
            double avgTime           = results.Select(t => t.Item1).Average();

            testResult.ExtraInformation = Math.Round(avgTime, 0) + " ms average time";

            if (percentageSuccess >= 0.95)
            {
                testResult.Status = TestResult.OK;
            }
            else
            {
                testResult.Status         = TestResult.FAIL;
                testResult.CauseOfFailure = "Percentage success: " + Math.Round(percentageSuccess * 100, 0) + " %";
            }

            return(testResult);
        }
Beispiel #3
0
 internal static void RunContinuityTests(Options options)
 {
     RunTestsParallel(options, "Continuity", Out.Info,
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInTrafficState(),
         RelativeUrl  = GetTrafficStateLatest(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInTrafficState(),
         RelativeUrl  = GetTrafficStateHistoric(options.SegmentCsv),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInEvents(),
         RelativeUrl  = GetEventsLatest(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInEvents(),
         RelativeUrl  = GetEventsHistoric(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherState(),
         RelativeUrl  = GetWeatherStateLatest(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherState(),
         RelativeUrl  = GetWeatherStateHistoric(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherForecast(),
         RelativeUrl  = GetWeatherForecastLatest(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherForecast(),
         RelativeUrl  = GetWeatherForecastHistoric(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInSegmentState(),
         RelativeUrl  = GetSegmentState(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInSegmentState(),
         RelativeUrl  = GetSegmentStateHistoric(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInRoadSegments(),
         RelativeUrl  = GetRoadSegments(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInVehicleState(),
         RelativeUrl  = GetVehicleStateLatest(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     },
                      new KvAPerformanceTest
     {
         FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInVehicleState(),
         RelativeUrl  = GetVehicleStateHistoric(),
         IntervalTime = Options.ContinuityTestInterval,
         TestDuration = Options.ContinuityTestDuration
     }
                      );
 }
Beispiel #4
0
        internal static void RunFunctionalityTests(Options options)
        {
            RunTests(options, "Functionality", Out.Info,
                     new HttpResponseValidTest {
                RelativeUrl = GetTrafficStateLatest()
            },                                                                       // traffic state / latest
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetTrafficStateLatest(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInTrafficState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetTrafficStateLatest(),
                TypeToDeserialize = typeof(List <Trafficstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Trafficstate>)o)
                    {
                        if (i.publication_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }
                        if (i.speed >= 150 || i.speed < 0)
                        {
                            return(false);
                        }
                        if (i.max_speed > 130 || i.max_speed < 0)
                        {
                            return(false);
                        }
                        if (i.freeflow_speed > 130 || i.freeflow_speed < 0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetTrafficStateHistoric(options.SegmentCsv)
            },                                                                                           // traffic state historic
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetTrafficStateHistoric(options.SegmentCsv),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInTrafficState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetTrafficStateHistoric(options.SegmentCsv),
                TypeToDeserialize = typeof(List <Trafficstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Trafficstate>)o)
                    {
                        if (i.publication_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }
                        if (i.speed >= 150 || i.speed < 0)
                        {
                            return(false);
                        }
                        if (i.max_speed > 130 || i.max_speed < 0)
                        {
                            return(false);
                        }
                        if (i.freeflow_speed > 130 || i.freeflow_speed < 0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },
                     new HttpResponseValidTest {
                RelativeUrl = GetEventsLatest()
            },                                                                 // Events/latest
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetEventsLatest(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInEvents()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetEventsLatest(),
                TypeToDeserialize = typeof(List <TrafficEvent>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <TrafficEvent>)o)
                    {
                        if (i.start_time.Value.ToUniversalTime() >= DateTime.UtcNow)
                        {
                            return(false);
                        }

                        if (i.event_code.Any(eventCode => eventCode < 1 || eventCode > 255))
                        {
                            return(false);
                        }

                        if (i.start_time > i.expected_end_time)
                        {
                            //    // note: if traffic events in the future are allowed, this should also be removed.
                            return(false);
                        }

                        if (i.expected_end_time < DateTime.UtcNow)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },

                     // mandatory: start_time, end_time
                     new HttpResponseValidTest {
                RelativeUrl = GetEventsHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetEventsHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInEvents()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetEventsHistoric(),
                TypeToDeserialize = typeof(List <TrafficEvent>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <TrafficEvent>)o)
                    {
                        if (i.start_time.Value.ToUniversalTime() >= DateTime.UtcNow)
                        {
                            return(false);
                        }

                        if (i.event_code.Any(eventCode => eventCode < 1 || eventCode > 255))
                        {
                            return(false);
                        }

                        if (i.start_time > i.expected_end_time)
                        {
                            //    // note: if traffic events in the future are allowed, this should also be removed.
                            return(false);
                        }

                        //if (i.expected_end_time < DateTime.UtcNow) -> should be ok for historic
                        //    return false;
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetWeatherStateLatest()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetWeatherStateLatest(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetWeatherStateLatest(),
                TypeToDeserialize = typeof(List <Weatherstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Weatherstate>)o)
                    {
                        if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }

                        if (i.segment_id.Count == 0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },

                     // mandatory: start_time, end_time
                     new HttpResponseValidTest {
                RelativeUrl = GetWeatherStateHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetWeatherStateHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetWeatherStateHistoric(),
                TypeToDeserialize = typeof(List <Weatherstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Weatherstate>)o)
                    {
                        if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }

                        if (i.segment_id.Count == 0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetWeatherForecastLatest()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetWeatherForecastLatest(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherForecast()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetWeatherForecastLatest(),
                TypeToDeserialize = typeof(List <Weatherforecast>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Weatherforecast>)o)
                    {
                        //if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        //    return false;

                        if (i.segment_id.Count == 0)
                        {
                            return(false);
                        }

                        //if (i.measurement_time.ToUniversalTime() < DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)))
                        //    return false;
                    }
                    return(true);
                }
            },

                     // mandatory: start_time, end_time
                     new HttpResponseValidTest {
                RelativeUrl = GetWeatherForecastHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetWeatherForecastHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInWeatherForecast()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetWeatherForecastHistoric(),
                TypeToDeserialize = typeof(List <Weatherforecast>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Weatherforecast>)o)
                    {
                        //if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        //    return false;

                        if (i.segment_id.Count == 0)
                        {
                            return(false);
                        }

                        //if (i.measurement_time.ToUniversalTime() < DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15)))
                        //    return false;
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetSegmentState()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetSegmentState(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInSegmentState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetSegmentState(),
                TypeToDeserialize = typeof(List <Segmentstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Segmentstate>)o)
                    {
                        if (i.update_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }

                        // todo: add more sanity checks here.
                    }
                    return(true);
                }
            },

                     // mandatory: start_time, end_time
                     new HttpResponseValidTest {
                RelativeUrl = GetSegmentStateHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetSegmentStateHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInSegmentState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetSegmentStateHistoric(),
                TypeToDeserialize = typeof(List <Segmentstate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Segmentstate>)o)
                    {
                        if (i.update_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }

                        // todo: add more sanity checks here.
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetRoadSegments()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetRoadSegments(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInRoadSegments()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetRoadSegments(),
                TypeToDeserialize = typeof(List <Roadsegments>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Roadsegments>)o)
                    {
                        if (i.max_speed > 130)
                        {
                            return(false);
                        }
                        if (i.length > 100)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },
                     new HttpResponseValidTest {
                RelativeUrl = GetVehicleStateLatest()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetVehicleStateLatest(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInVehicleState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetVehicleStateLatest(),
                TypeToDeserialize = typeof(List <Vehiclestate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Vehiclestate>)o)
                    {
                        if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },

                     new HttpResponseValidTest {
                RelativeUrl = GetVehicleStateHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetVehicleStateHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInVehicleState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetVehicleStateHistoric(),
                TypeToDeserialize = typeof(List <Vehiclestate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Vehiclestate>)o)
                    {
                        if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            },
                     new HttpResponseValidTest {
                RelativeUrl = GetWeatherForecastHistoric()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = GetWeatherForecastHistoric(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInVehicleState()
            },
                     new SanityCheck()
            {
                RelativeUrl       = GetVehicleStateHistoric(),
                TypeToDeserialize = typeof(List <Vehiclestate>),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    foreach (var i in (List <Vehiclestate>)o)
                    {
                        if (i.measurement_time.ToUniversalTime() > DateTime.UtcNow)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
            }
                     );
        }
Beispiel #5
0
        internal static void RunFunctionalityTests(Options options)
        {
            RunTests(options, "Functionality", Out.Info,
                     new HttpResponseValidTest {
                RelativeUrl = FcdRetrieveRequestWithTime()
            },
                     new CheckCompletenessResponseTest
            {
                RelativeUrl = FcdRetrieveRequestWithTime(),
                FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInFCD()
            },
                     new SanityCheck()
            {
                RelativeUrl       = FcdRetrieveRequestWithTime(),
                TypeToDeserialize = typeof(FcdMessage),
                CheckValidDataInsideFunctionHandler = o =>
                {
                    var fcd = (FcdMessage)o;
                    if (fcd.provider_id == null)
                    {
                        return(false);
                    }
                    if (fcd.fcd_records.Count == 0)
                    {
                        return(false);
                    }
                    foreach (var fcdrecord in fcd.fcd_records)
                    {
                        if (fcdrecord.user_id_anonymous == 0)
                        {
                            return(false);
                        }
                        foreach (var trail in fcdrecord.trail)
                        {
                            if (trail.generation_time.ToUniversalTime() > DateTime.UtcNow)
                            {
                                return(false);
                            }
                            if (trail.speed < 0 || trail.speed > 150)
                            {
                                return(false);
                            }
                            if (trail.ref_position_lat < 51.482733 || trail.ref_position_lat > 51.555198)
                            {
                                return(false);
                            }
                            if (trail.ref_position_lon < 5.116459 || trail.ref_position_lon > 5.393983)
                            {
                                return(false);
                            }
                            if (trail.heading < 0 || trail.heading > 360)
                            {
                                return(false);
                            }

                            // Check Not implimented no valid time to countermeasure with
                            //if (trail.generation_time.ToUniversalTime() < DateTime.UtcNow.AddMinutes(-2))
                            //{
                            //    return false;
                            //}
                        }
                    }


                    return(true);
                }
            }
                     );
        }