Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
@PHONY: run-dev
.PHONY: run-dev test test-all test-api-gateway test-document-service test-eureka test-hello-service

run-dev:
docker compose up --build
docker compose up --build

# Directories of all server microservices that contain a Gradle wrapper
SERVER_SERVICES := \
server/api-gateway \
server/document-service \
server/eureka \
server/hello-service

# Default target to run the test-suite of every microservice
# Usage: `make test`

test: test-all

# Iterate over every service directory and execute its Gradle test task
# This keeps the output of each microservice separated for clarity.

test-all:
@for dir in $(SERVER_SERVICES); do \
echo "\n===== Running tests for $$dir ====="; \
(cd $$dir && ./gradlew --quiet test); \
done

# Convenience targets to run tests for an individual microservice

test-api-gateway:
@$(MAKE) -C server/api-gateway test

test-document-service:
@$(MAKE) -C server/document-service test

test-eureka:
@$(MAKE) -C server/eureka test

test-hello-service:
@$(MAKE) -C server/hello-service test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.tum.team_sigma.api_gateway;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
class GatewayControllerTest {

@Autowired
private MockMvc mockMvc;

@Test
@DisplayName("GET /api/gateway/health returns 200 and status UP")
void healthEndpointShouldReturnUp() throws Exception {
mockMvc.perform(get("/api/gateway/health"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status").value("UP"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Disable Eureka discovery during tests
eureka.client.enabled=false
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
spring.cloud.discovery.enabled=false
5 changes: 5 additions & 0 deletions server/document-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ dependencyManagement {

tasks.named('test') {
useJUnitPlatform()

// Exclude heavyweight container-based integration tests by default. They can
// be run separately with `./gradlew integrationTest` or by removing this
// exclusion.
exclude '**/*ContainerIntegrationTest*'
}

// Skip tests when building with -x test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public class MinioConfig {
@Value("${minio.bucket-name}")
private String bucketName;

/**
* Allows tests to disable the network call that verifies/creates the bucket.
* Defaults to <code>false</code> so production behaviour is unchanged.
*/
@Value("${minio.skip-check:false}")
private boolean skipBucketCheck;

@Bean
public MinioClient minioClient() {
try {
Expand All @@ -34,8 +41,12 @@ public MinioClient minioClient() {
.credentials(accessKey, secretKey)
.build();

// Create bucket if it doesn't exist
createBucketIfNotExists(client);
// Optionally create bucket if it doesn't exist (skipped in tests)
if (!skipBucketCheck) {
createBucketIfNotExists(client);
} else {
logger.debug("Skipping MinIO bucket existence check (minio.skip-check=true)");
}

return client;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.tum.team_sigma.document_service.controller;

import de.tum.team_sigma.document_service.service.DocumentService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(DocumentController.class)
class DocumentControllerHealthTest {

@Autowired
private MockMvc mockMvc;

// Mock service to avoid full application context and external dependencies
@MockBean
private DocumentService documentService;

@Test
@DisplayName("GET /api/documents/ returns health string")
void healthEndpointShouldReturnRunningString() throws Exception {
mockMvc.perform(get("/api/documents/"))
.andExpect(status().isOk())
.andExpect(content().string("Document Service is running!"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ eureka.client.fetch-registry=false

# Disable other unnecessary services for integration tests
spring.cloud.discovery.enabled=false
management.endpoints.enabled=false
management.endpoints.enabled=false

# ---------------- MinIO stub configuration ----------------
# Using dummy credentials and endpoint as tests should not perform real network calls.
minio.url=http://localhost:9000
minio.access-key=minio
minio.secret-key=miniopass
minio.bucket-name=testbucket
minio.skip-check=true

# ---------------- Weaviate stub configuration ----------------
weaviate.url=localhost:8081
Binary file removed server/document/.gradle/8.13/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
2 changes: 0 additions & 2 deletions server/document/.gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file not shown.
Binary file removed server/document/.gradle/file-system.probe
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Loading