test cases and model fixes

This commit is contained in:
mujah 2016-11-09 18:28:01 +08:00
parent b3976c7fb5
commit c50338720f
2 changed files with 73 additions and 41 deletions

View File

@ -1,31 +1,33 @@
package com.baeldung.spring.data.solr.model;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.solr.core.mapping.Indexed;
import org.springframework.data.solr.core.mapping.SolrDocument;
@SolrDocument(solrCoreName = "product")
public class Product {
@Id
@Field("id")
@Indexed(name="id",type = "string")
private String id;
@Field("name")
@Indexed(name="name",type = "string")
private String name;
@Field("category")
@Indexed(name="category",type = "string")
private String category;
@Field("description")
@Indexed(name="description",type = "string")
private String description;
public Product(String id, String name, String category) {
this.id = id;
this.name = name;
this.category = category;
public Product(){
}
public String getId() {
return id;
}

View File

@ -32,7 +32,10 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
final Product product = new Product("P00001", "Desk", "Furniture");
final Product product = new Product();
product.setId("P000089998");
product.setName("Desk");
product.setCategory("Furniture");
product.setDescription("New Desk");
productRepository.save(product);
final Product retrievedProduct = productRepository.findOne(product.getId());
@ -41,7 +44,10 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
final Product product = new Product("P0001", "T-Shirt", "Kitchen");
final Product product = new Product();
product.setId("P0001");
product.setName("T-Shirt");
product.setCategory("Kitchen");
product.setDescription("New T-Shirt");
productRepository.save(product);
@ -54,7 +60,10 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
final Product product = new Product("P0001", "Desk", "Furniture");
final Product product = new Product();
product.setId("P0001");
product.setName("Desk");
product.setCategory("Furniture");
product.setDescription("New Desk");
productRepository.save(product);
@ -67,7 +76,10 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
Product phone = new Product("P0001", "Phone", "Electronics");
Product phone = new Product();
phone.setId("P0001");
phone.setName("Phone");
phone.setCategory("Electronics");
phone.setDescription("New Phone");
productRepository.save(phone);
@ -77,15 +89,24 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
final Product phone = new Product("P0001", "Smart Phone", "Electronics");
final Product phone = new Product();
phone.setId("P0001");
phone.setName("Smart Phone");
phone.setCategory("Electronics");
phone.setDescription("New Item");
productRepository.save(phone);
final Product phoneCover = new Product("P0002", "Cover", "Phone");
final Product phoneCover = new Product();
phoneCover.setId("P0002");
phoneCover.setName("Cover");
phoneCover.setCategory("Phone");
phoneCover.setDescription("New Product");
productRepository.save(phoneCover);
final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable");
final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003");
wirelessCharger.setName("Charging Cable");
wirelessCharger.setCategory("Cable");
wirelessCharger.setDescription("Wireless Charger for Phone");
productRepository.save(wirelessCharger);
@ -95,15 +116,24 @@ public class ProductRepositoryIntegrationTest {
@Test
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
final Product phone = new Product("P0001", "Smart Phone", "Electronics");
final Product phone = new Product();
phone.setId("P0001");
phone.setName("Smart Phone");
phone.setCategory("Electronics");
phone.setDescription("New Item");
productRepository.save(phone);
final Product phoneCover = new Product("P0002", "Cover", "Phone");
final Product phoneCover = new Product();
phoneCover.setId("P0002");
phoneCover.setName("Cover");
phoneCover.setCategory("Phone");
phoneCover.setDescription("New Product");
productRepository.save(phoneCover);
final Product wirelessCharger = new Product("P0003", "Charging Cable", "Cable");
final Product wirelessCharger = new Product();
wirelessCharger.setId("P0003");
wirelessCharger.setName("Charging Cable");
wirelessCharger.setCategory("Cable");
wirelessCharger.setDescription("Wireless Charger for Phone");
productRepository.save(wirelessCharger);