diff --git a/pom.xml b/pom.xml index 65919de..e85c7f8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,80 +1,96 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.0 - - - com.CSO2 - product-catalogue-service - 0.0.1-SNAPSHOT - product-catalogue-service - product-catalogue-service of CSO2 - - 17 - 1.18.42 - - - - org.springframework.boot - spring-boot-starter-data-mongodb - - - org.springframework.boot - spring-boot-starter-web - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + com.CSO2 + product-catalogue-service + 0.0.1-SNAPSHOT + product-catalogue-service + product-catalogue-service of CSO2 + + 17 + 1.18.42 + 2023.0.0 - - org.projectlombok - lombok - ${lombok.version} - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-devtools - runtime - true - - + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - ${lombok.version} - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - + + + org.springframework.cloud + spring-cloud-starter-vault-config + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f444e17..4101c4c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,7 @@ spring.application.name=product-catalogue-service server.port=${SERVER_PORT:8082} -# MongoDB Configuration (override via env vars in production) +# MongoDB Configuration +# URI is injected at runtime from HashiCorp Vault (secret/cso2/services/product-catalogue-service-mongo) +# In K8s: DATABASE_PASSWORD env var is populated from Vault, then MONGODB_URI is constructed spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/CSO2_product_catalogue_service} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..ffb7626 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,29 @@ +# --- Product Catalogue Service --- +spring: + application: + name: product-catalogue-service + + # 1. Load Vault + config: + import: "optional:vault://" + + # 2. Vault Config + cloud: + vault: + enabled: true + uri: http://localhost:8200 + token: my-root-token + kv: + enabled: true + backend: kv + default-context: cs02-app + authentication: TOKEN + + # 3. MongoDB Config (Using a unique key for this service) + data: + mongodb: + uri: ${product_mongodb_uri:mongodb://localhost:27017/CSO2_product_catalogue_service} + +# --- Server Port --- +server: + port: 8082 \ No newline at end of file diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java index d6881d8..8808e09 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/BuilderControllerTest.java @@ -3,7 +3,7 @@ import com.CSO2.product_catalogue_service.dto.request.CompatibilityCheckRequest; import com.CSO2.product_catalogue_service.dto.response.BuilderSuggestionDTO; import com.CSO2.product_catalogue_service.service.BuilderService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java index 17afcca..2bb35d7 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/CategoryControllerTest.java @@ -2,7 +2,7 @@ import com.CSO2.product_catalogue_service.model.Category; import com.CSO2.product_catalogue_service.service.CategoryService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java index 702a140..ede1b94 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/ProductControllerTest.java @@ -5,7 +5,8 @@ import com.CSO2.product_catalogue_service.dto.response.ProductListDTO; import com.CSO2.product_catalogue_service.model.Product; import com.CSO2.product_catalogue_service.service.ProductService; -import tools.jackson.databind.ObjectMapper; +// ✅ FIXED: Using the standard Jackson library +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -130,8 +131,8 @@ void createProduct_ShouldReturnCreatedProduct() throws Exception { when(productService.createProduct(any(ProductCreateRequest.class))).thenReturn(product); mockMvc.perform(post("/api/products") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request))) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").value("1")) .andExpect(jsonPath("$.name").value("New Product")); @@ -162,4 +163,4 @@ protected void writeInternal(Object o, HttpOutputMessage outputMessage) objectMapper.writeValue(outputMessage.getBody(), o); } } -} +} \ No newline at end of file diff --git a/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java b/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java index e5fd389..e1d74a3 100644 --- a/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java +++ b/src/test/java/com/CSO2/product_catalogue_service/controller/ReviewControllerTest.java @@ -4,7 +4,7 @@ import com.CSO2.product_catalogue_service.model.Review; import com.CSO2.product_catalogue_service.repository.ReviewRepository; import com.CSO2.product_catalogue_service.service.ReviewService; -import tools.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith;