use of org.onebusaway.csv_entities.CsvEntityContextImpl in project onebusaway-gtfs-modules by OneBusAway.
the class LatLonFieldMappingFactoryTest method testTranslateFromObjectToCSV_differentLocale.
@Test
public void testTranslateFromObjectToCSV_differentLocale() {
Locale.setDefault(Locale.FRANCE);
_fieldMapping = buildFieldMapping();
Stop stop = new Stop();
stop.setLat(47.5678);
Map<String, Object> csvValues = new HashMap<String, Object>();
_fieldMapping.translateFromObjectToCSV(new CsvEntityContextImpl(), BeanWrapperFactory.wrap(stop), csvValues);
assertEquals("47.567800", csvValues.get("stop_lat"));
}
use of org.onebusaway.csv_entities.CsvEntityContextImpl in project onebusaway-gtfs-modules by OneBusAway.
the class LatLonFieldMappingFactoryTest method testTranslateFromCSVToObject.
@Test
public void testTranslateFromCSVToObject() {
Map<String, Object> csvValues = new HashMap<String, Object>();
csvValues.put("stop_lat", "47.1234");
Stop stop = new Stop();
_fieldMapping.translateFromCSVToObject(new CsvEntityContextImpl(), csvValues, BeanWrapperFactory.wrap(stop));
assertEquals(47.1234, stop.getLat(), 0.00001);
}
use of org.onebusaway.csv_entities.CsvEntityContextImpl in project onebusaway-gtfs-modules by OneBusAway.
the class LatLonFieldMappingFactoryTest method testTranslateFromObjectToCSV.
@Test
public void testTranslateFromObjectToCSV() {
Stop stop = new Stop();
stop.setLat(47.5678);
Map<String, Object> csvValues = new HashMap<String, Object>();
_fieldMapping.translateFromObjectToCSV(new CsvEntityContextImpl(), BeanWrapperFactory.wrap(stop), csvValues);
assertEquals("47.567800", csvValues.get("stop_lat"));
}
use of org.onebusaway.csv_entities.CsvEntityContextImpl in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceDateFieldMappingFactoryTest method test.
@Test
public void test() {
ServiceDateFieldMappingFactory factory = new ServiceDateFieldMappingFactory();
DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
String propName = "date";
FieldMapping mapping = factory.createFieldMapping(schemaFactory, Dummy.class, propName, propName, ServiceDate.class, true);
CsvEntityContext context = new CsvEntityContextImpl();
Map<String, Object> csvValues = new HashMap<String, Object>();
csvValues.put(propName, "20100212");
Dummy obj = new Dummy();
BeanWrapper wrapped = BeanWrapperFactory.wrap(obj);
mapping.translateFromCSVToObject(context, csvValues, wrapped);
assertEquals(new ServiceDate(2010, 2, 12), obj.getDate());
csvValues.clear();
mapping.translateFromObjectToCSV(context, wrapped, csvValues);
assertEquals("20100212", csvValues.get(propName));
}
use of org.onebusaway.csv_entities.CsvEntityContextImpl in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimeFieldMappingFactoryTest method test.
@Test
public void test() {
StopTimeFieldMappingFactory factory = new StopTimeFieldMappingFactory();
DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
String propName = "time";
FieldMapping mapping = factory.createFieldMapping(schemaFactory, Dummy.class, propName, propName, Integer.class, true);
CsvEntityContext context = new CsvEntityContextImpl();
Map<String, Object> csvValues = new HashMap<String, Object>();
csvValues.put(propName, "1234:23:32");
Dummy obj = new Dummy();
BeanWrapper wrapped = BeanWrapperFactory.wrap(obj);
mapping.translateFromCSVToObject(context, csvValues, wrapped);
assertEquals(new Integer(1234 * 60 * 60 + 23 * 60 + 32), obj.getTime());
csvValues.clear();
mapping.translateFromObjectToCSV(context, wrapped, csvValues);
assertEquals("1234:23:32", csvValues.get(propName));
}
Aggregations