CountryEnhancerTest.java from Tea Stats at Krugle
Show CountryEnhancerTest.java syntax highlighted
package net.time4tea.webstats.enhancer.geoip;
import com.maxmind.geoip.Country;
import com.maxmind.geoip.DatabaseInfo;
import com.maxmind.geoip.Location;
import com.maxmind.geoip.Region;
import junit.framework.TestCase;
import net.time4tea.webstats.geoip.LocationLookup;
import net.time4tea.webstats.process.Processor;
import net.time4tea.webstats.record.Page;
import net.time4tea.webstats.session.Session;
import java.net.InetAddress;
/**
* Originally richja Mar 30, 2006
*/
public class CountryEnhancerTest extends TestCase {
public void testTheEnhancerEnhancesWhenGivenWorkingLookupService() throws Exception {
Page record = new Page();
record.setClientAddress("12.34.56.78");
MockCountryLocationLookup lookupservice = new MockCountryLocationLookup("uk", "United Kingdom");
Processor<Session> processor = new CountryEnhancer(lookupservice);
Session session = new Session();
session.click(record);
processor.process(session);
Country country = ((Country) (session.getAttribute("country")).getValue());
assertEquals(lookupservice.code, country.getCode());
assertEquals(lookupservice.name, country.getName());
}
class MockCountryLocationLookup implements LocationLookup {
public String code;
public String name;
public MockCountryLocationLookup(String code, String name) {
this.code = code;
this.name = name;
}
public Country getCountry(String ipAddress) {
return new Country(code, name);
}
public Country getCountry(InetAddress ipAddress) {
return new Country(code, name);
}
public Country getCountry(long ipAddress) {
return new Country(code, name);
}
public int getID(String ipAddress) {
throw new UnsupportedOperationException();
}
public int getID(InetAddress ipAddress) {
throw new UnsupportedOperationException();
}
public int getID(long ipAddress) {
throw new UnsupportedOperationException();
}
public DatabaseInfo getDatabaseInfo() {
throw new UnsupportedOperationException();
}
// for GeoIP City only
public Location getLocation(InetAddress addr) {
throw new UnsupportedOperationException();
}
// for GeoIP City only
public Location getLocation(String str) {
throw new UnsupportedOperationException();
}
public Location getLocationwithdnsservice(String str) {
throw new UnsupportedOperationException();
}
public Region getRegion(String str) {
throw new UnsupportedOperationException();
}
public Region getRegion(long ipnum) {
throw new UnsupportedOperationException();
}
public Location getLocation(long ipnum) {
throw new UnsupportedOperationException();
}
public String getOrg(InetAddress addr) {
throw new UnsupportedOperationException();
}
public String getOrg(String str) {
throw new UnsupportedOperationException();
}
// GeoIP Organization and ISP Edition methods
public String getOrg(long ipnum) {
throw new UnsupportedOperationException();
}
}
}
See more files for this project here