BAEL-3683: Rename ProductMultipleDB entity to Product (#8557)

This commit is contained in:
kwoyke 2020-01-21 10:28:22 +01:00 committed by Grzegorz Piwowarek
parent 0caf728a2f
commit 1a67e0a280
3 changed files with 28 additions and 28 deletions

View File

@ -5,9 +5,9 @@ import java.util.List;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.PagingAndSortingRepository;
import com.baeldung.multipledb.model.product.ProductMultipleDB; import com.baeldung.multipledb.model.product.Product;
public interface ProductRepository extends PagingAndSortingRepository<ProductMultipleDB, Integer> { public interface ProductRepository extends PagingAndSortingRepository<Product, Integer> {
List<ProductMultipleDB> findAllByPrice(double price, Pageable pageable); List<Product> findAllByPrice(double price, Pageable pageable);
} }

View File

@ -6,7 +6,7 @@ import javax.persistence.Table;
@Entity @Entity
@Table(schema = "products") @Table(schema = "products")
public class ProductMultipleDB { public class Product {
@Id @Id
private int id; private int id;
@ -15,19 +15,19 @@ public class ProductMultipleDB {
private double price; private double price;
public ProductMultipleDB() { public Product() {
super(); super();
} }
private ProductMultipleDB(int id, String name, double price) { private Product(int id, String name, double price) {
super(); super();
this.id = id; this.id = id;
this.name = name; this.name = name;
this.price = price; this.price = price;
} }
public static ProductMultipleDB from(int id, String name, double price) { public static Product from(int id, String name, double price) {
return new ProductMultipleDB(id, name, price); return new Product(id, name, price);
} }
public int getId() { public int getId() {

View File

@ -23,7 +23,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.baeldung.multipledb.dao.product.ProductRepository; import com.baeldung.multipledb.dao.product.ProductRepository;
import com.baeldung.multipledb.model.product.ProductMultipleDB; import com.baeldung.multipledb.model.product.Product;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes=MultipleDbApplication.class) @SpringBootTest(classes=MultipleDbApplication.class)
@ -36,22 +36,22 @@ public class ProductRepositoryIntegrationTest {
@Before @Before
@Transactional("productTransactionManager") @Transactional("productTransactionManager")
public void setUp() { public void setUp() {
productRepository.save(ProductMultipleDB.from(1001, "Book", 21)); productRepository.save(Product.from(1001, "Book", 21));
productRepository.save(ProductMultipleDB.from(1002, "Coffee", 10)); productRepository.save(Product.from(1002, "Coffee", 10));
productRepository.save(ProductMultipleDB.from(1003, "Jeans", 30)); productRepository.save(Product.from(1003, "Jeans", 30));
productRepository.save(ProductMultipleDB.from(1004, "Shirt", 32)); productRepository.save(Product.from(1004, "Shirt", 32));
productRepository.save(ProductMultipleDB.from(1005, "Bacon", 10)); productRepository.save(Product.from(1005, "Bacon", 10));
} }
@Test @Test
public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() {
Pageable pageRequest = PageRequest.of(0, 2); Pageable pageRequest = PageRequest.of(0, 2);
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(2)); assertThat(result.getContent(), hasSize(2));
assertTrue(result.stream() assertTrue(result.stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.allMatch(id -> Arrays.asList(1001, 1002) .allMatch(id -> Arrays.asList(1001, 1002)
.contains(id))); .contains(id)));
} }
@ -60,11 +60,11 @@ public class ProductRepositoryIntegrationTest {
public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() {
Pageable pageRequest = PageRequest.of(1, 2); Pageable pageRequest = PageRequest.of(1, 2);
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(2)); assertThat(result.getContent(), hasSize(2));
assertTrue(result.stream() assertTrue(result.stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.allMatch(id -> Arrays.asList(1003, 1004) .allMatch(id -> Arrays.asList(1003, 1004)
.contains(id))); .contains(id)));
} }
@ -73,11 +73,11 @@ public class ProductRepositoryIntegrationTest {
public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { public void whenRequestingLastPage_ThenReturnLastPageWithRemData() {
Pageable pageRequest = PageRequest.of(2, 2); Pageable pageRequest = PageRequest.of(2, 2);
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(1)); assertThat(result.getContent(), hasSize(1));
assertTrue(result.stream() assertTrue(result.stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.allMatch(id -> Arrays.asList(1005) .allMatch(id -> Arrays.asList(1005)
.contains(id))); .contains(id)));
} }
@ -86,12 +86,12 @@ public class ProductRepositoryIntegrationTest {
public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() {
Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name"));
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent() assertThat(result.getContent()
.stream() .stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002)));
} }
@ -101,12 +101,12 @@ public class ProductRepositoryIntegrationTest {
Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price")
.descending()); .descending());
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent() assertThat(result.getContent()
.stream() .stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001)));
} }
@ -117,12 +117,12 @@ public class ProductRepositoryIntegrationTest {
.descending() .descending()
.and(Sort.by("name"))); .and(Sort.by("name")));
Page<ProductMultipleDB> result = productRepository.findAll(pageRequest); Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(5)); assertThat(result.getContent(), hasSize(5));
assertThat(result.getContent() assertThat(result.getContent()
.stream() .stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002)));
} }
@ -131,11 +131,11 @@ public class ProductRepositoryIntegrationTest {
public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() {
Pageable pageRequest = PageRequest.of(0, 2); Pageable pageRequest = PageRequest.of(0, 2);
List<ProductMultipleDB> result = productRepository.findAllByPrice(10, pageRequest); List<Product> result = productRepository.findAllByPrice(10, pageRequest);
assertThat(result, hasSize(2)); assertThat(result, hasSize(2));
assertTrue(result.stream() assertTrue(result.stream()
.map(ProductMultipleDB::getId) .map(Product::getId)
.allMatch(id -> Arrays.asList(1002, 1005) .allMatch(id -> Arrays.asList(1002, 1005)
.contains(id))); .contains(id)));
} }