BAEL-3201 - Unit testing with Redis test containers (#12441)
* BAEL-3201 - Unit testing with Redis test containers * BAEL-3201 - Updated test method names Co-authored-by: Abhinav Pandey <Abhinav2.Pandey@airtel.com>
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.redistestcontainers;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RedisTestcontainersApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RedisTestcontainersApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.redistestcontainers.hash;
|
||||
|
||||
import org.springframework.data.redis.core.RedisHash;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@RedisHash("product")
|
||||
public class Product implements Serializable {
|
||||
private String id;
|
||||
private String name;
|
||||
private double price;
|
||||
|
||||
// Constructor, getters and setters
|
||||
public Product() {
|
||||
}
|
||||
|
||||
public Product(String id, String name, double price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Product{" +
|
||||
"id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", price=" + price +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.redistestcontainers.repository;
|
||||
|
||||
import com.baeldung.redistestcontainers.hash.Product;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductRepository extends CrudRepository<Product, String> {
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.redistestcontainers.service;
|
||||
|
||||
import com.baeldung.redistestcontainers.hash.Product;
|
||||
import com.baeldung.redistestcontainers.repository.ProductRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ProductService {
|
||||
|
||||
private final ProductRepository productRepository;
|
||||
|
||||
public ProductService(ProductRepository productRepository) {
|
||||
this.productRepository = productRepository;
|
||||
}
|
||||
|
||||
public Product getProduct(String id) {
|
||||
return productRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
void createProduct(Product product) {
|
||||
productRepository.save(product);
|
||||
}
|
||||
|
||||
void updateProduct(Product product) {
|
||||
productRepository.save(product);
|
||||
}
|
||||
|
||||
void deleteProduct(String id) {
|
||||
productRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user