Skip to content

Commit 8ccfd20

Browse files
committed
formatting
1 parent 26864e2 commit 8ccfd20

2 files changed

Lines changed: 109 additions & 109 deletions

File tree

‎spring-data-solr/src/main/java/com/baeldung/spring/data/solr/config/SolrConfig.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
@ComponentScan
1414
public class SolrConfig {
1515

16-
@Bean
17-
public SolrClient solrClient() {
18-
return new HttpSolrClient("http://localhost:8983/solr");
19-
}
16+
@Bean
17+
public SolrClient solrClient() {
18+
return new HttpSolrClient("http://localhost:8983/solr");
19+
}
2020

21-
@Bean
22-
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
23-
return new SolrTemplate(client);
24-
}
21+
@Bean
22+
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
23+
return new SolrTemplate(client);
24+
}
2525
}

‎spring-data-solr/src/test/java/com/baeldung/spring/data/solr/repo/ProductRepositoryIntegrationTest.java‎

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -21,105 +21,105 @@
2121
@RunWith(SpringJUnit4ClassRunner.class)
2222
@ContextConfiguration(classes = SolrConfig.class)
2323
public class ProductRepositoryIntegrationTest {
24-
25-
@Autowired
26-
private ProductRepository productRepository;
27-
28-
@Before
29-
public void clearSolrData() {
30-
productRepository.deleteAll();
31-
}
32-
33-
@Test
34-
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
35-
final Product product = new Product();
36-
product.setId("P000089998");
37-
product.setName("Desk");
38-
productRepository.save(product);
39-
final Product retrievedProduct = productRepository.findOne(product.getId());
40-
assertEquals(product.getId(), retrievedProduct.getId());
41-
}
42-
43-
@Test
44-
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
45-
final Product product = new Product();
46-
product.setId("P0001");
47-
product.setName("T-Shirt");
48-
49-
productRepository.save(product);
50-
51-
product.setName("Shirt");
52-
productRepository.save(product);
53-
54-
final Product retrievedProduct = productRepository.findOne(product.getId());
55-
assertEquals(product.getName(), retrievedProduct.getName());
56-
}
57-
58-
@Test
59-
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
60-
final Product product = new Product();
61-
product.setId("P0001");
62-
product.setName("Desk");
63-
productRepository.save(product);
64-
65-
productRepository.delete(product);
66-
67-
Product retrievedProduct = productRepository.findOne(product.getId());
68-
assertNull(retrievedProduct);
69-
70-
}
71-
72-
@Test
73-
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
74-
Product phone = new Product();
75-
phone.setId("P0001");
76-
phone.setName("Phone");
77-
productRepository.save(phone);
78-
79-
List<Product> retrievedProducts = productRepository.findByName("Phone");
80-
assertEquals(phone.getId(), retrievedProducts.get(0).getId());
81-
}
82-
83-
@Test
84-
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
85-
final Product phone = new Product();
86-
phone.setId("P0001");
87-
phone.setName("Smart Phone");
88-
productRepository.save(phone);
89-
90-
final Product phoneCover = new Product();
91-
phoneCover.setId("P0002");
92-
phoneCover.setName("Phone Cover");
93-
productRepository.save(phoneCover);
94-
95-
final Product wirelessCharger = new Product();
96-
wirelessCharger.setId("P0003");
97-
wirelessCharger.setName("Phone Charging Cable");
98-
productRepository.save(wirelessCharger);
99-
100-
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
101-
assertEquals(3, result.getNumberOfElements());
102-
}
103-
104-
@Test
105-
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
106-
final Product phone = new Product();
107-
phone.setId("P0001");
108-
phone.setName("Smart Phone");
109-
productRepository.save(phone);
110-
111-
final Product phoneCover = new Product();
112-
phoneCover.setId("P0002");
113-
phoneCover.setName("Phone Cover");
114-
productRepository.save(phoneCover);
115-
116-
final Product wirelessCharger = new Product();
117-
wirelessCharger.setId("P0003");
118-
wirelessCharger.setName("Phone Charging Cable");
119-
productRepository.save(wirelessCharger);
120-
121-
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
122-
assertEquals(3, result.getNumberOfElements());
123-
}
124-
24+
25+
@Autowired
26+
private ProductRepository productRepository;
27+
28+
@Before
29+
public void clearSolrData() {
30+
productRepository.deleteAll();
31+
}
32+
33+
@Test
34+
public void whenSavingProduct_thenAvailableOnRetrieval() throws Exception {
35+
final Product product = new Product();
36+
product.setId("P000089998");
37+
product.setName("Desk");
38+
productRepository.save(product);
39+
final Product retrievedProduct = productRepository.findOne(product.getId());
40+
assertEquals(product.getId(), retrievedProduct.getId());
41+
}
42+
43+
@Test
44+
public void whenUpdatingProduct_thenChangeAvailableOnRetrieval() throws Exception {
45+
final Product product = new Product();
46+
product.setId("P0001");
47+
product.setName("T-Shirt");
48+
49+
productRepository.save(product);
50+
51+
product.setName("Shirt");
52+
productRepository.save(product);
53+
54+
final Product retrievedProduct = productRepository.findOne(product.getId());
55+
assertEquals(product.getName(), retrievedProduct.getName());
56+
}
57+
58+
@Test
59+
public void whenDeletingProduct_thenNotAvailableOnRetrieval() throws Exception {
60+
final Product product = new Product();
61+
product.setId("P0001");
62+
product.setName("Desk");
63+
productRepository.save(product);
64+
65+
productRepository.delete(product);
66+
67+
Product retrievedProduct = productRepository.findOne(product.getId());
68+
assertNull(retrievedProduct);
69+
70+
}
71+
72+
@Test
73+
public void whenFindByName_thenAvailableOnRetrieval() throws Exception {
74+
Product phone = new Product();
75+
phone.setId("P0001");
76+
phone.setName("Phone");
77+
productRepository.save(phone);
78+
79+
List<Product> retrievedProducts = productRepository.findByName("Phone");
80+
assertEquals(phone.getId(), retrievedProducts.get(0).getId());
81+
}
82+
83+
@Test
84+
public void whenSearchingProductsByQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
85+
final Product phone = new Product();
86+
phone.setId("P0001");
87+
phone.setName("Smart Phone");
88+
productRepository.save(phone);
89+
90+
final Product phoneCover = new Product();
91+
phoneCover.setId("P0002");
92+
phoneCover.setName("Phone Cover");
93+
productRepository.save(phoneCover);
94+
95+
final Product wirelessCharger = new Product();
96+
wirelessCharger.setId("P0003");
97+
wirelessCharger.setName("Phone Charging Cable");
98+
productRepository.save(wirelessCharger);
99+
100+
Page<Product> result = productRepository.findByCustomQuery("Phone", new PageRequest(0, 10));
101+
assertEquals(3, result.getNumberOfElements());
102+
}
103+
104+
@Test
105+
public void whenSearchingProductsByNamedQuery_thenAllMatchingProductsShouldAvialble() throws Exception {
106+
final Product phone = new Product();
107+
phone.setId("P0001");
108+
phone.setName("Smart Phone");
109+
productRepository.save(phone);
110+
111+
final Product phoneCover = new Product();
112+
phoneCover.setId("P0002");
113+
phoneCover.setName("Phone Cover");
114+
productRepository.save(phoneCover);
115+
116+
final Product wirelessCharger = new Product();
117+
wirelessCharger.setId("P0003");
118+
wirelessCharger.setName("Phone Charging Cable");
119+
productRepository.save(wirelessCharger);
120+
121+
Page<Product> result = productRepository.findByNamedQuery("one", new PageRequest(0, 10));
122+
assertEquals(3, result.getNumberOfElements());
123+
}
124+
125125
}

0 commit comments

Comments
 (0)