Delayed Fediverse publication
This commit is contained in:
parent
47fd3808d2
commit
e203250104
16 changed files with 98 additions and 136 deletions
|
|
@ -3,26 +3,17 @@ package net.javahippie.fitpub.config;
|
|||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.testcontainers.containers.BindMode;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;
|
||||
import org.testcontainers.containers.startupcheck.StartupCheckStrategy;
|
||||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
/**
|
||||
* Testcontainers configuration for tests.
|
||||
* Automatically starts a PostgreSQL container with PostGIS extension for integration tests.
|
||||
* Testcontainers configuration for tests and dev mode (via spring-boot:test-run).
|
||||
* Automatically starts a PostgreSQL container with PostGIS extension.
|
||||
*/
|
||||
@TestConfiguration(proxyBeanMethods = false)
|
||||
public class TestcontainersConfiguration {
|
||||
|
||||
/**
|
||||
* PostgreSQL container with PostGIS extension for tests.
|
||||
* PostGIS image is treated as a standard PostgreSQL container.
|
||||
*
|
||||
* @ServiceConnection automatically configures the datasource from this container.
|
||||
*/
|
||||
@Bean
|
||||
@ServiceConnection
|
||||
public PostgreSQLContainer<?> postgresContainer() {
|
||||
|
|
@ -34,7 +25,6 @@ public class TestcontainersConfiguration {
|
|||
.withUsername("test")
|
||||
.withPassword("test")
|
||||
.waitingFor(new HostPortWaitStrategy())
|
||||
.withReuse(true)
|
||||
.withFileSystemBind(".postgresdata", "/var/lib/postgresql/data", BindMode.READ_WRITE);
|
||||
.withReuse(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ class WeatherServiceTest {
|
|||
""";
|
||||
testActivity.setTrackPointsJson(trackPointsJson);
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn(SAMPLE_WEATHER_RESPONSE);
|
||||
when(weatherDataRepository.save(any(WeatherData.class)))
|
||||
|
|
@ -163,7 +162,6 @@ class WeatherServiceTest {
|
|||
""";
|
||||
testActivity.setTrackPointsJson(trackPointsJson);
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn(SAMPLE_WEATHER_RESPONSE);
|
||||
when(weatherDataRepository.save(any(WeatherData.class)))
|
||||
|
|
@ -211,26 +209,6 @@ class WeatherServiceTest {
|
|||
verify(restTemplate, never()).getForObject(any(URI.class), eq(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return cached weather if it already exists")
|
||||
void testFetchWeather_Cached() {
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
WeatherData cachedWeather = new WeatherData();
|
||||
cachedWeather.setActivityId(activityId);
|
||||
cachedWeather.setTemperatureCelsius(new BigDecimal("20.0"));
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(true);
|
||||
when(weatherDataRepository.findByActivityId(activityId)).thenReturn(Optional.of(cachedWeather));
|
||||
|
||||
Optional<WeatherData> result = weatherService.fetchWeatherForActivity(testActivity);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(new BigDecimal("20.0"), result.get().getTemperatureCelsius());
|
||||
verify(restTemplate, never()).getForObject(any(URI.class), eq(String.class));
|
||||
verify(weatherDataRepository, never()).save(any(WeatherData.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return empty when track points JSON is null")
|
||||
void testFetchWeather_NoTrackPoints() {
|
||||
|
|
@ -291,8 +269,6 @@ class WeatherServiceTest {
|
|||
testActivity.setStartedAt(LocalDateTime.now().minusDays(10)); // Old activity
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
|
||||
Optional<WeatherData> result = weatherService.fetchWeatherForActivity(testActivity);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
|
|
@ -305,7 +281,6 @@ class WeatherServiceTest {
|
|||
void testFetchWeather_AuthenticationError() {
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenThrow(new HttpClientErrorException(
|
||||
org.springframework.http.HttpStatus.UNAUTHORIZED,
|
||||
|
|
@ -325,7 +300,6 @@ class WeatherServiceTest {
|
|||
void testFetchWeather_NetworkError() {
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenThrow(new ResourceAccessException("Connection timeout"));
|
||||
|
||||
|
|
@ -340,7 +314,6 @@ class WeatherServiceTest {
|
|||
void testFetchWeather_MalformedResponse() {
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn("this is not valid JSON");
|
||||
|
||||
|
|
@ -372,7 +345,6 @@ class WeatherServiceTest {
|
|||
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn(responseWithRain);
|
||||
when(weatherDataRepository.save(any(WeatherData.class)))
|
||||
|
|
@ -414,7 +386,6 @@ class WeatherServiceTest {
|
|||
|
||||
testActivity.setTrackPointsJson("[{\"latitude\":50.0,\"longitude\":8.0}]");
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn(minimalResponse);
|
||||
when(weatherDataRepository.save(any(WeatherData.class)))
|
||||
|
|
@ -470,7 +441,6 @@ class WeatherServiceTest {
|
|||
""";
|
||||
testActivity.setTrackPointsJson(trackPointsJson);
|
||||
|
||||
when(weatherDataRepository.existsByActivityId(activityId)).thenReturn(false);
|
||||
when(restTemplate.getForObject(any(URI.class), eq(String.class)))
|
||||
.thenReturn(SAMPLE_WEATHER_RESPONSE);
|
||||
when(weatherDataRepository.save(any(WeatherData.class)))
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ public class FitFileAnalyzer {
|
|||
private static final double SEMICIRCLES_TO_DEGREES = 180.0 / Math.pow(2, 31);
|
||||
private static final long FIT_EPOCH_OFFSET = 631065600L;
|
||||
|
||||
public static void main(String[] args) {
|
||||
/**
|
||||
* Run from IDE or via {@code analyzeFitFile(path)} directly.
|
||||
*/
|
||||
public static void analyze(String[] args) {
|
||||
if (args.length == 0) {
|
||||
System.out.println("Usage: FitFileAnalyzer <path-to-fit-file>");
|
||||
System.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue