Skip to content

Commit

Permalink
22.NEXT features (#505 #498 #495)
Browse files Browse the repository at this point in the history
  • Loading branch information
FJBDev committed May 13, 2022
1 parent 8bf3b0e commit 8202a2f
Show file tree
Hide file tree
Showing 73 changed files with 3,329 additions and 1,000 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private String buildFormattedDescription(final TourData tourData) {
if (_prefStore.getBoolean(Preferences.STRAVA_SENDWEATHERDATA_IN_DESCRIPTION)) {

if (StringUtils.hasContent(description.toString())) {
description.append(net.tourbook.ui.UI.SYSTEM_NEW_LINE);
description.append(UI.SYSTEM_NEW_LINE);
}
String weatherData = WeatherUtils.buildWeatherDataString(tourData, false, false, false);
if (StringUtils.hasContent(description.toString())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.time.zone.ZoneRules;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.tourbook.common.CommonActivator;
import net.tourbook.common.Messages;
Expand Down Expand Up @@ -84,7 +85,7 @@ public class TimeTools {
/**
* Contains the short weekday strings. For example: "Sun", "Mon", etc.
*/
public static String[] weekDays_Short;
protected static String[] weekDays_Short;

/**
* Contains the full text, typically the full description. For example, day-of-week Monday might
Expand Down Expand Up @@ -126,6 +127,7 @@ public class TimeTools {
public static final DateTimeFormatter Formatter_Week_Month = DateTimeFormatter.ofPattern("dd MMM"); //$NON-NLS-1$
public static final DateTimeFormatter Formatter_Weekday = DateTimeFormatter.ofPattern("E"); //$NON-NLS-1$
public static final DateTimeFormatter Formatter_Weekday_L = DateTimeFormatter.ofPattern("EEEE"); //$NON-NLS-1$
public static final DateTimeFormatter Formatter_YearMonthDay = DateTimeFormatter.ofPattern("yyyy-MM-dd"); //$NON-NLS-1$

public static final DateTimeFormatter Formatter_DayTimeSecondsAmPm = DateTimeFormatter.ofPattern("h:mm:ss a"); //$NON-NLS-1$

Expand Down Expand Up @@ -259,24 +261,6 @@ public static long createdNowAsYMDhms() {
return createYMDhms_From_DateTime(ZonedDateTime.now());
}

/**
* @return Returns a long value for the given date/time in the YYYYMMDDhhmmss format
*/
public static long createYMDhms_From_DateTime(final ZonedDateTime zonedDateTime) {

final long dtYMDhms = 0

+ (zonedDateTime.getYear() * 10000000000L)
+ (zonedDateTime.getMonthValue() * 100000000L)
+ (zonedDateTime.getDayOfMonth() * 1000000L)

+ (zonedDateTime.getHour() * 10000L)
+ (zonedDateTime.getMinute() * 100L)
+ zonedDateTime.getSecond();

return dtYMDhms;
}

private static SunTimes createSunTimes(final ZonedDateTime zonedDateTime, final double latitude, final double longitude) {

// Because giving a date with a specific hour could result into getting the
Expand Down Expand Up @@ -343,6 +327,24 @@ public static TourDateTime createTourDateTime(final long epochMilli, final Strin
return new TourDateTime(tourZonedDateTime, timeZoneOffsetLabel, weekDays_Short[weekDayIndex]);
}

/**
* @return Returns a long value for the given date/time in the YYYYMMDDhhmmss format
*/
public static long createYMDhms_From_DateTime(final ZonedDateTime zonedDateTime) {

final long dtYMDhms = 0

+ (zonedDateTime.getYear() * 10000000000L)
+ (zonedDateTime.getMonthValue() * 100000000L)
+ (zonedDateTime.getDayOfMonth() * 1000000L)

+ (zonedDateTime.getHour() * 10000L)
+ (zonedDateTime.getMinute() * 100L)
+ zonedDateTime.getSecond();

return dtYMDhms;
}

public static ZonedDateTime determineSunriseTimes(final ZonedDateTime zonedDateTime,
final double latitude,
final double longitude) {
Expand All @@ -365,7 +367,7 @@ public static ZonedDateTime determineSunsetTimes(final ZonedDateTime zonedDateTi
* @return Returns a list with all available time zones which are sorted by zone offset, zone id
* and zone name key.
*/
public static ArrayList<TimeZoneData> getAllTimeZones() {
public static List<TimeZoneData> getAllTimeZones() {

if (_allSortedTimeZones == null) {

Expand Down Expand Up @@ -519,7 +521,7 @@ public static int getNumberOfWeeksWithYear(final int year) {
*/
private static TimeZoneData getTimeZone(final String timeZoneId) {

final ArrayList<TimeZoneData> allTimeZones = getAllTimeZones();
final List<TimeZoneData> allTimeZones = getAllTimeZones();

for (final TimeZoneData timeZone : allTimeZones) {

Expand All @@ -533,7 +535,7 @@ private static TimeZoneData getTimeZone(final String timeZoneId) {

public static TimeZoneData getTimeZone_ByIndex(final int selectedTimeZoneIndex) {

final ArrayList<TimeZoneData> allTimeZone = getAllTimeZones();
final List<TimeZoneData> allTimeZone = getAllTimeZones();

if (selectedTimeZoneIndex == -1) {
return allTimeZone.get(0);
Expand Down Expand Up @@ -578,7 +580,7 @@ public static int getTimeZoneIndex(final double latitude, final double longitude
*/
public static int getTimeZoneIndex(final String timeZoneId) {

final ArrayList<TimeZoneData> allTimeZones = getAllTimeZones();
final List<TimeZoneData> allTimeZones = getAllTimeZones();

for (int timeZoneIndex = 0; timeZoneIndex < allTimeZones.size(); timeZoneIndex++) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2005, 2021 Wolfgang Schramm and Contributors
* Copyright (C) 2005, 2022 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
Expand Down
6 changes: 3 additions & 3 deletions bundles/net.tourbook.ext.jars/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<classpathentry exported="true" kind="lib" path="commons-imaging-1.0-alpha1.jar"/> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-imaging -->
<classpathentry exported="true" kind="lib" path="core-3.1.0.jar" sourcepath="jar-sources/core-3.1.0-sources.jar"/> <!-- https://mvnrepository.com/artifact/net.sf.trove4j/core -->
<classpathentry exported="true" kind="lib" path="imgscalr-lib-4.2.jar"/> <!-- https://mvnrepository.com/artifact/org.imgscalr/imgscalr-lib -->
<classpathentry exported="true" kind="lib" path="jackson-core-2.12.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<classpathentry exported="true" kind="lib" path="jackson-databind-2.12.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<classpathentry exported="true" kind="lib" path="jackson-annotations-2.12.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<classpathentry exported="true" kind="lib" path="jackson-core-2.13.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<classpathentry exported="true" kind="lib" path="jackson-databind-2.13.2.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<classpathentry exported="true" kind="lib" path="jackson-annotations-2.13.2.jar"/> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<classpathentry exported="true" kind="lib" path="joda-time-2.10.10.jar"/> <!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<classpathentry exported="true" kind="lib" path="json-20220320.jar"/> <!-- https://mvnrepository.com/artifact/org.json/json -->
<classpathentry exported="true" kind="lib" path="lat-lon-timezone-converter-2019-04-30.jar" /> <!-- https://github.com/drtimcooper/LatLongToTimezone/blob/master/src/main/java/com/skedgo/converter/TimezoneMapper.java -->
Expand Down
6 changes: 3 additions & 3 deletions bundles/net.tourbook.ext.jars/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Bundle-ClassPath:
json-20220320.jar,
lat-lon-timezone-converter-2019-04-30.jar,
simplelatlng-1.3.1.jar,
jackson-core-2.12.2.jar,
jackson-databind-2.12.2.jar,
jackson-annotations-2.12.2.jar,
jackson-core-2.13.2.jar,
jackson-databind-2.13.2.2.jar,
jackson-annotations-2.13.2.jar,
commons-suncalc-3.4.jar,
httpclient-4.5.13.jar,
httpcore-4.4.15.jar
Expand Down
6 changes: 3 additions & 3 deletions bundles/net.tourbook.ext.jars/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ bin.includes = META-INF/,\
commons-imaging-1.0-alpha1.jar,\
core-3.1.0.jar,\
imgscalr-lib-4.2.jar,\
jackson-core-2.12.2.jar,\
jackson-annotations-2.12.2.jar,\
jackson-databind-2.12.2.jar,\
jackson-core-2.13.2.jar,\
jackson-annotations-2.13.2.2.jar,\
jackson-databind-2.13.2.jar,\
joda-time-2.10.10.jar,\
json-20220320.jar,\
lat-lon-timezone-converter-2019-04-30.jar,\
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion bundles/net.tourbook.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<classpathentry kind="src" path="src/test"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry exported="true" kind="lib" path="jsonassert-1.5.0.jar"/> <!-- https://github.com/skyscreamer/JSONassert/releases -->
<classpathentry exported="true" kind="lib" path="xmlunit-core-2.8.4.jar"/> <!-- https://mvnrepository.com/artifact/org.xmlunit/xmlunit-core -->
<classpathentry exported="true" kind="lib" path="xmlunit-core-2.9.0.jar"/> <!-- https://mvnrepository.com/artifact/org.xmlunit/xmlunit-core -->
<classpathentry exported="true" kind="lib" path="HttpClientMock-1.0.0.jar"/> <!-- https://mvnrepository.com/artifact/com.pgs-soft/HttpClientMock -->
<classpathentry exported="true" kind="lib" path="hamcrest-all-1.3.jar"/> <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<classpathentry exported="true" kind="lib" path="hibernate-entitymanager.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion bundles/net.tourbook.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
hibernate-entitymanager.jar,
jsonassert-1.5.0.jar,
xmlunit-core-2.8.4.jar,
xmlunit-core-2.9.0.jar,
HttpClientMock-1.0.0.jar,
hamcrest-all-1.3.jar
Bundle-Vendor: MyTourbook
Expand Down
2 changes: 1 addition & 1 deletion bundles/net.tourbook.tests/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ bin.includes = META-INF/,\
.,\
hibernate-entitymanager.jar,\
jsonassert-1.5.0.jar,\
xmlunit-core-2.8.4.jar
xmlunit-core-2.9.0.jar
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import java.lang.reflect.Field;

import net.tourbook.cloud.oauth2.OAuth2Constants;
import net.tourbook.data.TourData;
import net.tourbook.weather.WeatherUtils;
import net.tourbook.weather.openweathermap.OpenWeatherMapRetriever;

import org.junit.jupiter.api.BeforeAll;
Expand All @@ -42,24 +42,28 @@ public class OpenWeatherMapRetrieverTests {
OpenWeatherMapRetriever openWeatherMapRetriever;

@BeforeAll
static void initAll() {
static void initAll() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {

httpClientMock = new HttpClientMock();
final Field field = OpenWeatherMapRetriever.class
.getSuperclass()
.getDeclaredField("httpClient"); //$NON-NLS-1$
field.setAccessible(true);
field.set(null, httpClientMock);
}

/**
* Regression test for the weather retrieval from OpenWeatherMap.
*/
@Test
void testWeatherRetrieval() throws IllegalAccessException, NoSuchFieldException {
void testWeatherRetrieval() {

final String urlBase = OAuth2Constants.HEROKU_APP_URL
final String urlBase = WeatherUtils.HEROKU_APP_URL
+ "/openweathermap/timemachine?units=metric&lat=40.263996&lon=-105.58854099999999&lang=en&dt="; //$NON-NLS-1$

final String openWeatherMapResponse1 = Comparison.readFileContent(OPENWEATHERMAP_FILE_PATH
+ "LongsPeak-Manual-OpenWeatherMapResponse-1647086400.json"); //$NON-NLS-1$

//First call configuration
final String url1 = urlBase + "1647086400"; //$NON-NLS-1$
httpClientMock.onGet(url1)
.doReturn(openWeatherMapResponse1);
Expand All @@ -70,13 +74,6 @@ void testWeatherRetrieval() throws IllegalAccessException, NoSuchFieldException
httpClientMock.onGet(url2)
.doReturn(openWeatherMapResponse2);

//Second call configuration
final Field field = OpenWeatherMapRetriever.class
.getSuperclass()
.getDeclaredField("httpClient"); //$NON-NLS-1$
field.setAccessible(true);
field.set(null, httpClientMock);

final TourData tour = Initializer.importTour();
//Tuesday, March 12, 2022 12:00:00 PM
tour.setTourStartTime(2022, 3, 12, 12, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (C) 2022 Frédéric Bard
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/
package data.weather.weatherapi;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.pgssoft.httpclient.HttpClientMock;

import java.lang.reflect.Field;

import net.tourbook.data.TourData;
import net.tourbook.weather.WeatherUtils;
import net.tourbook.weather.weatherapi.WeatherApiRetriever;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import utils.Comparison;
import utils.FilesUtils;
import utils.Initializer;

public class WeatherAPIRetrieverTests {

private static final String WEATHERAPI_FILE_PATH =
FilesUtils.rootPath + "data/weather/weatherapi/files/"; //$NON-NLS-1$

static HttpClientMock httpClientMock;
WeatherApiRetriever weatherApiRetriever;

@BeforeAll
static void initAll() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {

httpClientMock = new HttpClientMock();
final Field field = WeatherApiRetriever.class
.getSuperclass()
.getDeclaredField("httpClient"); //$NON-NLS-1$
field.setAccessible(true);
field.set(null, httpClientMock);
}

/**
* Regression test for the weather retrieval from WeatherAPI.
*/
@Test
void testWeatherRetrieval() {

final String weatherApiResponse = Comparison.readFileContent(WEATHERAPI_FILE_PATH
+ "LongsPeak-Manual-WeatherApiResponse.json"); //$NON-NLS-1$
final String url = WeatherUtils.HEROKU_APP_URL
+ "/weatherapi?lat=40.263996&lon=-105.58854099999999&lang=en&dt=2022-05-10"; //$NON-NLS-1$
httpClientMock.onGet(url)
.doReturn(weatherApiResponse);

final TourData tour = Initializer.importTour();
//Tuesday, May 10, 2022 12:00:00 PM
tour.setTourStartTime(2022, 5, 10, 12, 0, 0);
//We set the current time elapsed to trigger the computation of the new end time
tour.setTourDeviceTime_Elapsed(tour.getTourDeviceTime_Elapsed());

weatherApiRetriever = new WeatherApiRetriever(tour);

assertTrue(weatherApiRetriever.retrieveHistoricalWeatherData());
httpClientMock.verify().get(url).called();

// SET_FORMATTING_OFF

assertEquals(13.92f, tour.getWeather_Temperature_Average());
assertEquals(11, tour.getWeather_Wind_Speed());
assertEquals(121, tour.getWeather_Wind_Direction());
assertEquals("Ensoleille", tour.getWeather()); //$NON-NLS-1$
assertEquals("weather-sunny", tour.getWeather_Clouds()); //$NON-NLS-1$
assertEquals(29, tour.getWeather_Humidity());
assertEquals(0.0, tour.getWeather_Precipitation());
assertEquals(1012.0, tour.getWeather_Pressure());
assertEquals(22.1f, tour.getWeather_Temperature_Max());
assertEquals(3.4f, tour.getWeather_Temperature_Min());
assertEquals(13.32f, tour.getWeather_Temperature_WindChill());

// SET_FORMATTING_ON
}
}

0 comments on commit 8202a2f

Please sign in to comment.