@Test public void getFormattedUrl_WhenPostBody_ValuesSubstituted() throws Exception { Location loc = MockLocations.builder("MOCK", 12.193, 19.111) .putExtra("satellites",9) .withAltitude(45) .withAccuracy(8) .withBearing(359) .withSpeed(9001) .withTime(1457205869949l) .putExtra(BundleConstants.DETECTED_ACTIVITY, "TILTED") .build(); CustomUrlLogger logger = new CustomUrlLogger("",0, "GET", "",""); String expected ="This my post body\nlat=12.193&lon=19.111&sat=9&desc=blah&alt=45.0&acc=8.0&dir=359.0&prov=MOCK&spd=9001.0&time=2016-03-05T19:24:29.949Z&battery=91.0&androidId=22&serial=SRS11&activity=TILTED&dist=27"; String urlTemplate = "This my post body\nlat=%LAT&lon=%LON&sat=%SAT&desc=%DESC&alt=%ALT&acc=%ACC&dir=%DIR&prov=%PROV&spd=%SPD&time=%TIME&battery=%BATT&androidId=%AID&serial=%SER&activity=%act&dist=%DIST"; assertThat("Post body parameters are substituted", logger.getFormattedTextblock(urlTemplate,loc, "blah", "22", 91, "SRS11", 0,"","", 27.5), is(expected)); }
public String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId, float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance) throws Exception { String logUrl = customLoggingUrl; SerializableLocation sLoc = new SerializableLocation(loc); logUrl = logUrl.replaceAll("(?i)%lat", String.valueOf(sLoc.getLatitude())); logUrl = logUrl.replaceAll("(?i)%lon", String.valueOf(sLoc.getLongitude())); logUrl = logUrl.replaceAll("(?i)%sat", String.valueOf(sLoc.getSatelliteCount())); logUrl = logUrl.replaceAll("(?i)%desc", String.valueOf(URLEncoder.encode(Strings.htmlDecode(description), "UTF-8"))); logUrl = logUrl.replaceAll("(?i)%alt", String.valueOf(sLoc.getAltitude())); logUrl = logUrl.replaceAll("(?i)%acc", String.valueOf(sLoc.getAccuracy())); logUrl = logUrl.replaceAll("(?i)%dir", String.valueOf(sLoc.getBearing())); logUrl = logUrl.replaceAll("(?i)%prov", String.valueOf(sLoc.getProvider())); logUrl = logUrl.replaceAll("(?i)%spd", String.valueOf(sLoc.getSpeed())); logUrl = logUrl.replaceAll("(?i)%timestamp", String.valueOf(sLoc.getTime()/1000)); logUrl = logUrl.replaceAll("(?i)%time", String.valueOf(Strings.getIsoDateTime(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%date", String.valueOf(Strings.getIsoCalendarDate(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%starttimestamp", String.valueOf(sessionStartTimeStamp/1000)); logUrl = logUrl.replaceAll("(?i)%batt", String.valueOf(batteryLevel)); logUrl = logUrl.replaceAll("(?i)%aid", String.valueOf(androidId)); logUrl = logUrl.replaceAll("(?i)%ser", String.valueOf(buildSerial)); logUrl = logUrl.replaceAll("(?i)%act", String.valueOf(sLoc.getDetectedActivity())); logUrl = logUrl.replaceAll("(?i)%filename", fileName); logUrl = logUrl.replaceAll("(?i)%profile",URLEncoder.encode(profileName, "UTF-8")); logUrl = logUrl.replaceAll("(?i)%hdop", sLoc.getHDOP()); logUrl = logUrl.replaceAll("(?i)%vdop", sLoc.getVDOP()); logUrl = logUrl.replaceAll("(?i)%pdop", sLoc.getPDOP()); logUrl = logUrl.replaceAll("(?i)%dist", String.valueOf((int)distance)); return logUrl; }
CustomUrlLogger implements FileLogger { public String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId, float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance) throws Exception { String logUrl = customLoggingUrl; SerializableLocation sLoc = new SerializableLocation(loc); logUrl = logUrl.replaceAll("(?i)%lat", String.valueOf(sLoc.getLatitude())); logUrl = logUrl.replaceAll("(?i)%lon", String.valueOf(sLoc.getLongitude())); logUrl = logUrl.replaceAll("(?i)%sat", String.valueOf(sLoc.getSatelliteCount())); logUrl = logUrl.replaceAll("(?i)%desc", String.valueOf(URLEncoder.encode(Strings.htmlDecode(description), "UTF-8"))); logUrl = logUrl.replaceAll("(?i)%alt", String.valueOf(sLoc.getAltitude())); logUrl = logUrl.replaceAll("(?i)%acc", String.valueOf(sLoc.getAccuracy())); logUrl = logUrl.replaceAll("(?i)%dir", String.valueOf(sLoc.getBearing())); logUrl = logUrl.replaceAll("(?i)%prov", String.valueOf(sLoc.getProvider())); logUrl = logUrl.replaceAll("(?i)%spd", String.valueOf(sLoc.getSpeed())); logUrl = logUrl.replaceAll("(?i)%timestamp", String.valueOf(sLoc.getTime()/1000)); logUrl = logUrl.replaceAll("(?i)%time", String.valueOf(Strings.getIsoDateTime(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%date", String.valueOf(Strings.getIsoCalendarDate(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%starttimestamp", String.valueOf(sessionStartTimeStamp/1000)); logUrl = logUrl.replaceAll("(?i)%batt", String.valueOf(batteryLevel)); logUrl = logUrl.replaceAll("(?i)%aid", String.valueOf(androidId)); logUrl = logUrl.replaceAll("(?i)%ser", String.valueOf(buildSerial)); logUrl = logUrl.replaceAll("(?i)%act", String.valueOf(sLoc.getDetectedActivity())); logUrl = logUrl.replaceAll("(?i)%filename", fileName); logUrl = logUrl.replaceAll("(?i)%profile",URLEncoder.encode(profileName, "UTF-8")); logUrl = logUrl.replaceAll("(?i)%hdop", sLoc.getHDOP()); logUrl = logUrl.replaceAll("(?i)%vdop", sLoc.getVDOP()); logUrl = logUrl.replaceAll("(?i)%pdop", sLoc.getPDOP()); logUrl = logUrl.replaceAll("(?i)%dist", String.valueOf((int)distance)); return logUrl; } }
CustomUrlLogger implements FileLogger { public String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId, float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance) throws Exception { String logUrl = customLoggingUrl; SerializableLocation sLoc = new SerializableLocation(loc); logUrl = logUrl.replaceAll("(?i)%lat", String.valueOf(sLoc.getLatitude())); logUrl = logUrl.replaceAll("(?i)%lon", String.valueOf(sLoc.getLongitude())); logUrl = logUrl.replaceAll("(?i)%sat", String.valueOf(sLoc.getSatelliteCount())); logUrl = logUrl.replaceAll("(?i)%desc", String.valueOf(URLEncoder.encode(Strings.htmlDecode(description), "UTF-8"))); logUrl = logUrl.replaceAll("(?i)%alt", String.valueOf(sLoc.getAltitude())); logUrl = logUrl.replaceAll("(?i)%acc", String.valueOf(sLoc.getAccuracy())); logUrl = logUrl.replaceAll("(?i)%dir", String.valueOf(sLoc.getBearing())); logUrl = logUrl.replaceAll("(?i)%prov", String.valueOf(sLoc.getProvider())); logUrl = logUrl.replaceAll("(?i)%spd", String.valueOf(sLoc.getSpeed())); logUrl = logUrl.replaceAll("(?i)%timestamp", String.valueOf(sLoc.getTime()/1000)); logUrl = logUrl.replaceAll("(?i)%time", String.valueOf(Strings.getIsoDateTime(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%date", String.valueOf(Strings.getIsoCalendarDate(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%starttimestamp", String.valueOf(sessionStartTimeStamp/1000)); logUrl = logUrl.replaceAll("(?i)%batt", String.valueOf(batteryLevel)); logUrl = logUrl.replaceAll("(?i)%aid", String.valueOf(androidId)); logUrl = logUrl.replaceAll("(?i)%ser", String.valueOf(buildSerial)); logUrl = logUrl.replaceAll("(?i)%act", String.valueOf(sLoc.getDetectedActivity())); logUrl = logUrl.replaceAll("(?i)%filename", fileName); logUrl = logUrl.replaceAll("(?i)%profile",URLEncoder.encode(profileName, "UTF-8")); logUrl = logUrl.replaceAll("(?i)%hdop", sLoc.getHDOP()); logUrl = logUrl.replaceAll("(?i)%vdop", sLoc.getVDOP()); logUrl = logUrl.replaceAll("(?i)%pdop", sLoc.getPDOP()); logUrl = logUrl.replaceAll("(?i)%dist", String.valueOf((int)distance)); return logUrl; } CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders);  CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders, String basicAuthUsername, String basicAuthPassword); }
CustomUrlLogger implements FileLogger { public String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId, float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance) throws Exception { String logUrl = customLoggingUrl; SerializableLocation sLoc = new SerializableLocation(loc); logUrl = logUrl.replaceAll("(?i)%lat", String.valueOf(sLoc.getLatitude())); logUrl = logUrl.replaceAll("(?i)%lon", String.valueOf(sLoc.getLongitude())); logUrl = logUrl.replaceAll("(?i)%sat", String.valueOf(sLoc.getSatelliteCount())); logUrl = logUrl.replaceAll("(?i)%desc", String.valueOf(URLEncoder.encode(Strings.htmlDecode(description), "UTF-8"))); logUrl = logUrl.replaceAll("(?i)%alt", String.valueOf(sLoc.getAltitude())); logUrl = logUrl.replaceAll("(?i)%acc", String.valueOf(sLoc.getAccuracy())); logUrl = logUrl.replaceAll("(?i)%dir", String.valueOf(sLoc.getBearing())); logUrl = logUrl.replaceAll("(?i)%prov", String.valueOf(sLoc.getProvider())); logUrl = logUrl.replaceAll("(?i)%spd", String.valueOf(sLoc.getSpeed())); logUrl = logUrl.replaceAll("(?i)%timestamp", String.valueOf(sLoc.getTime()/1000)); logUrl = logUrl.replaceAll("(?i)%time", String.valueOf(Strings.getIsoDateTime(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%date", String.valueOf(Strings.getIsoCalendarDate(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%starttimestamp", String.valueOf(sessionStartTimeStamp/1000)); logUrl = logUrl.replaceAll("(?i)%batt", String.valueOf(batteryLevel)); logUrl = logUrl.replaceAll("(?i)%aid", String.valueOf(androidId)); logUrl = logUrl.replaceAll("(?i)%ser", String.valueOf(buildSerial)); logUrl = logUrl.replaceAll("(?i)%act", String.valueOf(sLoc.getDetectedActivity())); logUrl = logUrl.replaceAll("(?i)%filename", fileName); logUrl = logUrl.replaceAll("(?i)%profile",URLEncoder.encode(profileName, "UTF-8")); logUrl = logUrl.replaceAll("(?i)%hdop", sLoc.getHDOP()); logUrl = logUrl.replaceAll("(?i)%vdop", sLoc.getVDOP()); logUrl = logUrl.replaceAll("(?i)%pdop", sLoc.getPDOP()); logUrl = logUrl.replaceAll("(?i)%dist", String.valueOf((int)distance)); return logUrl; } CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders);  CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders, String basicAuthUsername, String basicAuthPassword); @Override void write(Location loc); @Override void annotate(String description, Location loc); String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId,
                                        float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance); @Override String getName(); }
CustomUrlLogger implements FileLogger { public String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId, float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance) throws Exception { String logUrl = customLoggingUrl; SerializableLocation sLoc = new SerializableLocation(loc); logUrl = logUrl.replaceAll("(?i)%lat", String.valueOf(sLoc.getLatitude())); logUrl = logUrl.replaceAll("(?i)%lon", String.valueOf(sLoc.getLongitude())); logUrl = logUrl.replaceAll("(?i)%sat", String.valueOf(sLoc.getSatelliteCount())); logUrl = logUrl.replaceAll("(?i)%desc", String.valueOf(URLEncoder.encode(Strings.htmlDecode(description), "UTF-8"))); logUrl = logUrl.replaceAll("(?i)%alt", String.valueOf(sLoc.getAltitude())); logUrl = logUrl.replaceAll("(?i)%acc", String.valueOf(sLoc.getAccuracy())); logUrl = logUrl.replaceAll("(?i)%dir", String.valueOf(sLoc.getBearing())); logUrl = logUrl.replaceAll("(?i)%prov", String.valueOf(sLoc.getProvider())); logUrl = logUrl.replaceAll("(?i)%spd", String.valueOf(sLoc.getSpeed())); logUrl = logUrl.replaceAll("(?i)%timestamp", String.valueOf(sLoc.getTime()/1000)); logUrl = logUrl.replaceAll("(?i)%time", String.valueOf(Strings.getIsoDateTime(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%date", String.valueOf(Strings.getIsoCalendarDate(new Date(sLoc.getTime())))); logUrl = logUrl.replaceAll("(?i)%starttimestamp", String.valueOf(sessionStartTimeStamp/1000)); logUrl = logUrl.replaceAll("(?i)%batt", String.valueOf(batteryLevel)); logUrl = logUrl.replaceAll("(?i)%aid", String.valueOf(androidId)); logUrl = logUrl.replaceAll("(?i)%ser", String.valueOf(buildSerial)); logUrl = logUrl.replaceAll("(?i)%act", String.valueOf(sLoc.getDetectedActivity())); logUrl = logUrl.replaceAll("(?i)%filename", fileName); logUrl = logUrl.replaceAll("(?i)%profile",URLEncoder.encode(profileName, "UTF-8")); logUrl = logUrl.replaceAll("(?i)%hdop", sLoc.getHDOP()); logUrl = logUrl.replaceAll("(?i)%vdop", sLoc.getVDOP()); logUrl = logUrl.replaceAll("(?i)%pdop", sLoc.getPDOP()); logUrl = logUrl.replaceAll("(?i)%dist", String.valueOf((int)distance)); return logUrl; } CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders);  CustomUrlLogger(String customLoggingUrl, int batteryLevel, String httpMethod, String httpBody, String httpHeaders, String basicAuthUsername, String basicAuthPassword); @Override void write(Location loc); @Override void annotate(String description, Location loc); String getFormattedTextblock(String customLoggingUrl, Location loc, String description, String androidId,
                                        float batteryLevel, String buildSerial, long sessionStartTimeStamp, String fileName, String profileName, double distance); @Override String getName();  }