diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml
index 8bb103879d..7de135cdb6 100644
--- a/persistence-modules/spring-data-cosmosdb/pom.xml
+++ b/persistence-modules/spring-data-cosmosdb/pom.xml
@@ -1,48 +1,52 @@
- 4.0.0
- spring-data-cosmosdb
- spring-data-cosmos-db
- tutorial for spring-data-cosmosdb
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+ spring-data-cosmosdb
+ spring-data-cosmos-db
+ tutorial for spring-data-cosmosdb
-
- com.baeldung
- parent-boot-2
- 0.0.1-SNAPSHOT
- ../../parent-boot-2
-
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../../parent-boot-2
+
-
- 1.8
-
+
+ 1.8
+ 2.3.0
+
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- com.microsoft.azure
- spring-data-cosmosdb
- 2.3.0
-
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ com.microsoft.azure
+ spring-data-cosmosdb
+ ${cosmodb.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.projectlombok
+ lombok
+
+
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java
index c1e38c9601..fe02be88ff 100644
--- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java
+++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java
@@ -22,9 +22,13 @@ import java.util.Optional;
@RequestMapping("/products")
public class ProductController {
- @Autowired
private ProductService productService;
+ @Autowired
+ public ProductController(ProductService productService) {
+ this.productService = productService;
+ }
+
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void create(@RequestBody Product product) {
@@ -46,8 +50,8 @@ public class ProductController {
return productService.findProductByName(name);
}
- @GetMapping(value = "/category/{category}")
- public List getByCategory(@PathVariable String category) {
+ @GetMapping(value = "/category")
+ public List getByCategory(@RequestParam String category) {
return productService.getProductsOfCategory(category);
}
diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java
index 07bb8889f5..10bbe1b9ae 100644
--- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java
+++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java
@@ -5,6 +5,11 @@ import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import org.springframework.data.annotation.Id;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
@Document(collection = "products")
public class Product {
@@ -18,41 +23,4 @@ public class Product {
@PartitionKey
private String productCategory;
- public String getProductid() {
- return productid;
- }
-
- public void setProductid(String productid) {
- this.productid = productid;
- }
-
- public String getProductName() {
- return productName;
- }
-
- public void setProductName(String productName) {
- this.productName = productName;
- }
-
- public String getProductCategory() {
- return productCategory;
- }
-
- public void setProductCategory(String productCategory) {
- this.productCategory = productCategory;
- }
-
- public double getPrice() {
- return price;
- }
-
- public void setPrice(double price) {
- this.price = price;
- }
-
- @Override
- public String toString() {
- return "Product [productid=" + productid + ", productName=" + productName + ", price=" + price + ", productCategory=" + productCategory + "]";
- }
-
}
diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java
index 6846d5205c..03f3ba39cd 100644
--- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java
+++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java
@@ -25,8 +25,7 @@ public class ProductService {
}
public List getProductsOfCategory(String category) {
- List products = repository.findByProductCategory(category);
- return products;
+ return repository.findByProductCategory(category);
}
public void saveProduct(Product product) {
diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java
similarity index 70%
rename from persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java
rename to persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java
index 0ef6af15e1..80cf17284a 100644
--- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java
+++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java
@@ -14,14 +14,14 @@ import java.util.Optional;
//Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties
//to run the integration test
//@SpringBootTest
-public class AzurecosmodbApplicationIntegrationTest {
+public class AzurecosmodbApplicationManualTest {
@Autowired
ProductRepository productRepository;
// Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties
// to run the integration test
- // @Test
+ //@Test
public void givenProductIsCreated_whenCallFindById_thenProductIsFound() {
Product product = new Product();
product.setProductid("1001");
@@ -29,11 +29,9 @@ public class AzurecosmodbApplicationIntegrationTest {
product.setPrice(110.0);
product.setProductName("Blue Shirt");
- // Uncomment these lines when configured URI and keys for Azure Cosmos DB in application.properties
- // to run the integration test
- // productRepository.save(product);
- // Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"));
- // Assert.notNull(retrievedProduct, "Retrieved Product is Null");
+ productRepository.save(product);
+ Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt"));
+ Assert.notNull(retrievedProduct, "Retrieved Product is Null");
}