Created
July 3, 2012 15:02
-
-
Save mattwigway/3040283 to your computer and use it in GitHub Desktop.
ntd agency
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
package models; | |
import javax.persistence.*; | |
import java.util.*; | |
import play.db.jpa.*; | |
import play.data.validation.*; | |
@Entity | |
public class NtdAgency extends Model { | |
/** Human-readable agency name */ | |
@Required | |
public String name; | |
/** This agency's primary location on the WWW */ | |
@Required | |
@URL | |
public String website; | |
/** This agency's ID in the National Transit Database */ | |
public String ntdId; | |
/** Service area population */ | |
public int population; | |
/** Annual unlinked passenger trips */ | |
public int ridership; | |
/** Annual passenger miles */ | |
public int passengerMiles; | |
// TODO: geometry | |
@ManyToOne | |
public MetroArea metroArea; | |
@ManyToMany(mappedBy="agencies") | |
public Set<GtfsFeed> feeds; | |
/** | |
* Convert to a human-readable string. This is exposed in the admin interface, so it should be | |
* correct. | |
*/ | |
public String toString () { | |
return name; | |
} | |
} |
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
@Test | |
public void testMetroAreaToString () { | |
// TODO: assuming the autogenerated IDs are sequential from 0 isn't safe. Something | |
// must be done. | |
MetroArea sf = MetroArea.find("byName", "San Francisco-Oakland-San José, CA").first(); | |
MetroArea empty = MetroArea.find("byId", 1L).first(); | |
MetroArea full = NtdAgency.find("byWebsite", "http://metro.kingcounty.gov").first() | |
.metroArea; | |
MetroArea fullNoAgencyName = NtdAgency.find("byWebsite", "http://example.com").first() | |
.metroArea; | |
assertEquals("San Francisco-Oakland-San José, CA", sf.toString()); | |
// assertEquals("Empty metro area", empty.toString()); | |
assertEquals("Metro including King County Metro", full.toString()); | |
assertEquals("Metro including http://example.com", fullNoAgencyName.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment