Last active
August 29, 2015 14:18
-
-
Save mminella/cb0f32be1fe61f26210c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper | |
def result = true | |
def slurper = new JsonSlurper() | |
def jsonPayload = null; | |
try { | |
jsonPayload = slurper.parseText(payload) | |
} catch (Exception e) { | |
return false; | |
} | |
def fuelLevelInput = jsonPayload.containsKey("fuel_level_input") ? jsonPayload?.fuel_level_input : null | |
def massAirFlow = jsonPayload.containsKey("maf_airflow") ? jsonPayload?.maf_airflow : null | |
def rpm = jsonPayload.containsKey("rpm") ? jsonPayload?.rpm : null | |
def intakeManifoldPressure = jsonPayload.containsKey("intake_manifold_pressure") ? jsonPayload?.intake_manifold_pressure : null | |
def intakeAirTemp = jsonPayload.containsKey("intake_air_temp") ? jsonPayload?.intake_air_temp : null | |
def vehicleSpeed = jsonPayload.containsKey("vehicle_speed") ? jsonPayload?.vehicle_speed : null | |
if((fuelLevelInput == null || fuelLevelInput instanceof String) || (vehicleSpeed == null || vehicleSpeed instanceof String)) { | |
println "Rejecting " + payload + " because either fuelLevelInput or vehicleSpeed are empty" | |
result = false | |
} else { | |
if((massAirFlow == null || massAirFlow instanceof String)) { | |
if((rpm == null || rpm instanceof String) || (intakeAirTemp == null || intakeAirTemp instanceof String) || (intakeManifoldPressure == null || intakeMainfoldPressure instanceof String)) { | |
println "Rejecting " + payload + " because maf related fields are not available" | |
result = false | |
} | |
} | |
} | |
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2015 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.acmemotors.filter; | |
import java.io.IOException; | |
import groovy.lang.Binding; | |
import groovy.lang.GroovyShell; | |
import org.junit.Test; | |
import org.springframework.core.io.ClassPathResource; | |
/** | |
* @author Michael Minella | |
*/ | |
public class DataFilterTests { | |
@Test | |
public void testEmptyString() throws Exception { | |
testScript("", false); | |
} | |
@Test | |
public void testEmptyJson() throws Exception { | |
testScript("{}", false); | |
} | |
@Test | |
public void testNull() throws Exception { | |
testScript(null, false); | |
} | |
@Test | |
public void testNoFuelLevelInput() throws Exception { | |
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":\"\",\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":0,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", true); | |
} | |
@Test | |
public void testNoVehicleSpeed() throws Exception { | |
testScript("{\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":\"\",\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", true); | |
} | |
@Test | |
public void testNoMassAirFlowNoRpm() throws Exception { | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":\"\",\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":\"\",\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", true); | |
} | |
@Test | |
public void testNoMassAirFlowNoIntakeAirTemp() throws Exception { | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":\"\"," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":\"\"," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", true); | |
} | |
@Test | |
public void testNoMassAirFlowNoIntakeMainfoldPressure() throws Exception { | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"maf_airflow\":\"\",\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":685,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", false); | |
testScript("{\"vehicle_speed\":10,\"obd_standards\":2," + | |
"\"intake_manifold_pressure\":5,\"accelerator_throttle_pos_e\":8," + | |
"\"engine_load\":30,\"latitude\":\"32.984979\"," + | |
"\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\"," + | |
"\"catalyst_temp\":446,\"relative_throttle_pos\":1," + | |
"\"fuel_level_input\":5,\"fuel_system_status\":[2,0]," + | |
"\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\"," + | |
"\"throttle_position\":14,\"barometric_pressure\":95," + | |
"\"control_module_voltage\":13,\"longitude\":\"-96.709578\"," + | |
"\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60," + | |
"\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217," + | |
"\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2," + | |
"\"timestamp\":1408670439897}", true); | |
} | |
@Test | |
public void testDallas() throws Exception { | |
testScript("{\"vehicle_speed\":0,\"obd_standards\":2,\"intake_manifold_pressure\":\"\",\"accelerator_throttle_pos_e\":8,\"engine_load\":30,\"maf_airflow\":7,\"latitude\":\"32.984979\",\"vin\":\"SCEDT26T0BD007019\",\"bearing\":\"319.492374\",\"catalyst_temp\":446,\"relative_throttle_pos\":1,\"fuel_level_input\":99,\"fuel_system_status\":[2,0],\"accelerator_throttle_pos_d\":16,\"acceleration\":\"0.992\",\"throttle_position\":14,\"barometric_pressure\":95,\"control_module_voltage\":13,\"longitude\":\"-96.709578\",\"distance_with_mil_on\":0,\"coolant_temp\":92,\"intake_air_temp\":60,\"rpm\":659,\"short_term_fuel\":-1,\"time_since_engine_start\":217,\"absolute_throttle_pos_b\":18,\"long_term_fuel\":2,\"timestamp\":1408670439897,\"guid\":\"de7a9806-0e13-48d3-b93f-119d17b6dc6f\"}", true); | |
} | |
private void testScript(String payload, boolean result) throws IOException { | |
Binding binding = new Binding(); | |
binding.setVariable("payload", payload); | |
GroovyShell shell = new GroovyShell(binding); | |
Object value = | |
shell.evaluate(new ClassPathResource("DataFilter.groovy").getFile()); | |
assert value.equals(result); | |
} | |
} |
Author
mminella
commented
Mar 30, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment