PropertyMethodResolverImpl extends DefaultPropertyMethodResolver { @Override public PropertyMethod getPropertyMethod(Class<?> targetType, String propertyName) { @SuppressWarnings("rawtypes") PropertyMethod method = _virtualPropertyMethods.get(Tuples.tuple( (Class) targetType, propertyName)); if (method != null) { return method; } SingleFieldMapping mapping = _schemaCache.getFieldMappingForCsvFieldName( targetType, propertyName); if (mapping != null) { propertyName = mapping.getObjFieldName(); } return super.getPropertyMethod(targetType, propertyName); } PropertyMethodResolverImpl(GtfsRelationalDao dao,
      EntitySchemaCache schemaCache); @Override PropertyMethod getPropertyMethod(Class<?> targetType,
      String propertyName);  }
@Test public void testUseCsvFieldMappings() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory(); EntitySchema entitySchema = factory.getSchema(Route.class); _schemaCache.addEntitySchema(entitySchema); PropertyMethod method = _resolver.getPropertyMethod(Route.class, "route_id"); Route route = new Route(); AgencyAndId id = new AgencyAndId("1", "10"); route.setId(id); assertSame(id, method.invoke(route)); }
@Test public void testAgencyRoutesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Agency agency = new Agency(); agency.setId("1"); Route route = new Route(); route.setId(new AgencyAndId("1", "r0")); route.setAgency(agency); _dao.saveEntity(route); PropertyMethod method = _resolver.getPropertyMethod(Agency.class, "routes"); assertEquals(Arrays.asList(route), method.invoke(agency)); }
@Test public void testRouteTripsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Route route = new Route(); route.setId(new AgencyAndId("1", "r0")); _dao.saveEntity(route); Trip trip = new Trip(); trip.setId(new AgencyAndId("1", "t0")); trip.setRoute(route); _dao.saveEntity(trip); PropertyMethod method = _resolver.getPropertyMethod(Route.class, "trips"); assertEquals(Arrays.asList(trip), method.invoke(route)); }
@Test public void testTripStopTimesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Trip trip = new Trip(); trip.setId(new AgencyAndId("1", "t0")); _dao.saveEntity(trip); StopTime stopTime = new StopTime(); stopTime.setTrip(trip); stopTime.setStop(new Stop()); _dao.saveEntity(stopTime); PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "stop_times"); assertEquals(Arrays.asList(stopTime), method.invoke(trip)); }
@Test public void testTripCalendarsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Trip trip = new Trip(); trip.setId(new AgencyAndId("1", "t0")); trip.setServiceId(new AgencyAndId("1", "sid0")); _dao.saveEntity(trip); ServiceCalendar calendar = new ServiceCalendar(); calendar.setServiceId(trip.getServiceId()); _dao.saveEntity(calendar); PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "calendar"); assertEquals(calendar, method.invoke(trip)); }