1818import com .baeldung .spring .data .solr .model .Product ;
1919import com .baeldung .spring .data .solr .repository .ProductRepository ;
2020
21-
2221@ RunWith (SpringJUnit4ClassRunner .class )
2322@ ContextConfiguration (classes = SolrConfig .class )
2423public class ProductRepositoryIntegrationTest {
25-
24+
2625 @ Autowired
2726 private ProductRepository productRepository ;
28-
27+
2928 @ Before
30- public void clearSolrData (){
29+ public void clearSolrData () {
3130 productRepository .deleteAll ();
3231 }
33-
32+
3433 @ Test
35- public void whenSavingProduct_thenAvailableOnRetrieval () throws Exception {
36- final Product product = new Product ("P00001" ,"Desk" ,"Furniture" );
34+ public void whenSavingProduct_thenAvailableOnRetrieval () throws Exception {
35+ final Product product = new Product ("P00001" , "Desk" , "Furniture" );
3736 product .setDescription ("New Desk" );
3837 productRepository .save (product );
3938 final Product retrievedProduct = productRepository .findOne (product .getId ());
40- assertEquals (product .getId (),retrievedProduct .getId ());
39+ assertEquals (product .getId (), retrievedProduct .getId ());
4140 }
42-
41+
4342 @ Test
4443 public void whenUpdatingProduct_thenChangeAvailableOnRetrieval () throws Exception {
45- final Product product = new Product ("P0001" , "T-Shirt" ,"Kitchen" );
44+ final Product product = new Product ("P0001" , "T-Shirt" , "Kitchen" );
4645 product .setDescription ("New T-Shirt" );
4746 productRepository .save (product );
48-
47+
4948 product .setCategory ("Clothes" );
5049 productRepository .save (product );
51-
50+
5251 final Product retrievedProduct = productRepository .findOne (product .getId ());
5352 assertEquals (product .getCategory (), retrievedProduct .getCategory ());
5453 }
55-
56-
57-
54+
5855 @ Test
5956 public void whenDeletingProduct_thenNotAvailableOnRetrieval () throws Exception {
60- final Product product = new Product ("P0001" , "Desk" ,"Furniture" );
57+ final Product product = new Product ("P0001" , "Desk" , "Furniture" );
6158 product .setDescription ("New Desk" );
6259 productRepository .save (product );
63-
60+
6461 productRepository .delete (product );
65-
66- Product retrievedProduct = productRepository .findOne (product .getId ());
62+
63+ Product retrievedProduct = productRepository .findOne (product .getId ());
6764 assertNull (retrievedProduct );
68-
65+
6966 }
70-
67+
7168 @ Test
72- public void whenFindByName_thenAvailableOnRetrieval () throws Exception {
73- final Product phone = new Product ("P0001" , "Phone" , "Electronics" );
69+ public void whenFindByName_thenAvailableOnRetrieval () throws Exception {
70+ Product phone = new Product ("P0001" , "Phone" , "Electronics" );
7471 phone .setDescription ("New Phone" );
7572 productRepository .save (phone );
7673
@@ -92,7 +89,7 @@ public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble()
9289 wirelessCharger .setDescription ("Wireless Charger for Phone" );
9390 productRepository .save (wirelessCharger );
9491
95- Page <Product > result = productRepository .findByCustomQuery ("Pho " , new PageRequest (0 , 10 ));
92+ Page <Product > result = productRepository .findByCustomQuery ("Phone " , new PageRequest (0 , 10 ));
9693 assertEquals (3 , result .getNumberOfElements ());
9794 }
9895
0 commit comments