Good stuff

This commit is contained in:
Tim Zöller 2025-12-05 10:21:45 +01:00
parent 9e428a0499
commit 0e81a65d62
11 changed files with 86 additions and 59 deletions

View file

@ -0,0 +1,32 @@
package org.operaton.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.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
/**
* Testcontainers configuration for tests.
* Automatically starts a PostgreSQL container with PostGIS extension for integration tests.
*/
@TestConfiguration(proxyBeanMethods = false)
public class TestcontainersConfiguration {
/**
* PostgreSQL container with PostGIS extension for tests.
* @ServiceConnection automatically configures the datasource from this container.
*/
@Bean
@ServiceConnection
public PostgreSQLContainer<?> postgresContainer() {
return new PostgreSQLContainer<>(
DockerImageName.parse("postgis/postgis:16-3.4")
.asCompatibleSubstituteFor("postgres")
)
.withDatabaseName("fitpub")
.withUsername("fitpub")
.withPassword("fitpub")
.withReuse(true);
}
}

View file

@ -2,10 +2,12 @@ package org.operaton.fitpub.security;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.operaton.fitpub.config.TestcontainersConfiguration;
import org.operaton.fitpub.model.entity.User;
import org.operaton.fitpub.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
@ -23,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.*;
* Test to validate that users' public and private keys match.
*/
@SpringBootTest
@Import(TestcontainersConfiguration.class)
@Slf4j
public class KeyPairValidationTest {

View file

@ -3,6 +3,7 @@ package org.operaton.fitpub.service;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import org.operaton.fitpub.config.TestcontainersConfiguration;
import org.operaton.fitpub.model.entity.Activity;
import org.operaton.fitpub.model.entity.ActivityMetrics;
import org.operaton.fitpub.model.entity.User;
@ -11,6 +12,7 @@ import org.operaton.fitpub.repository.UserRepository;
import org.operaton.fitpub.util.FitParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import java.io.File;
@ -30,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.*;
"fitpub.image.osm-tiles.enabled=true"
})
@ActiveProfiles("test")
@Import(TestcontainersConfiguration.class)
class ActivityImageServiceTest {
@Autowired

View file

@ -55,6 +55,21 @@ class FitFileServiceTest {
@Mock
private ActivityMetricsRepository metricsRepository;
@Mock
private PersonalRecordService personalRecordService;
@Mock
private AchievementService achievementService;
@Mock
private TrainingLoadService trainingLoadService;
@Mock
private ActivitySummaryService activitySummaryService;
@Mock
private WeatherService weatherService;
@Spy
private ObjectMapper objectMapper;
@ -148,7 +163,9 @@ class FitFileServiceTest {
// Assert
assertNotNull(result);
assertTrue(result.getTitle().contains("Run"));
assertTrue(result.getTitle().contains(testParsedData.getStartTime().toLocalDate().toString()));
// Title format is "[Time of Day] [Activity Type]" (e.g., "Morning Run")
// Start time is 8:00 AM, which is "Morning"
assertTrue(result.getTitle().contains("Morning"));
}
@Test