Skip to content

Commit 95e24da

Browse files
Merge branch 'master' into sla-pr/1272-testng
2 parents d1f0b2e + 6590e02 commit 95e24da

289 files changed

Lines changed: 10284 additions & 230 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎JGit/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Relevant articles:
2+
3+
- [A Guide to JGit](http://www.baeldung.com/jgit)

‎algorithms/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Relevant articles:
2+
3+
- [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra)
4+
- [Introduction to Cobertura](http://www.baeldung.com/cobertura)

‎algorithms/pom.xml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,23 @@
4141
</plugins>
4242
</pluginManagement>
4343
</build>
44-
</project>
44+
<reporting>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.codehaus.mojo</groupId>
48+
<artifactId>cobertura-maven-plugin</artifactId>
49+
<version>2.7</version>
50+
<configuration>
51+
<instrumentation>
52+
<ignores>
53+
<ignore>com/baeldung/algorithms/dijkstra/*</ignore>
54+
</ignores>
55+
<excludes>
56+
<exclude>com/baeldung/algorithms/dijkstra/*</exclude>
57+
</excludes>
58+
</instrumentation>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</reporting>
63+
</project>

‎apache-bval/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Relevant Articles:
2+
- [Intro to Apache BVal](http://www.baeldung.com/apache-bval)

‎apache-solrj/pom.xml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>apache-solrj</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<name>apache-solrj</name>
9+
10+
<properties>
11+
<junit.version>4.12</junit.version>
12+
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.apache.solr</groupId>
18+
<artifactId>solr-solrj</artifactId>
19+
<version>6.4.0</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>${junit.version}</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>2.3.2</version>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-surefire-plugin</artifactId>
38+
<version>${maven-surefire-plugin.version}</version>
39+
<configuration>
40+
<source>1.8</source>
41+
<target>1.8</target>
42+
<excludes>
43+
<exclude>**/*IntegrationTest.java</exclude>
44+
<exclude>**/*LiveTest.java</exclude>
45+
</excludes>
46+
</configuration>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung.solrjava;
2+
3+
import org.apache.solr.client.solrj.beans.Field;
4+
5+
public class ProductBean {
6+
7+
String id;
8+
String name;
9+
String price;
10+
11+
public ProductBean(String id, String name, String price) {
12+
super();
13+
this.id = id;
14+
this.name = name;
15+
this.price = price;
16+
}
17+
18+
public String getId() {
19+
return id;
20+
}
21+
22+
@Field("id")
23+
protected void setId(String id) {
24+
this.id = id;
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
@Field("name")
32+
protected void setName(String name) {
33+
this.name = name;
34+
}
35+
36+
public String getPrice() {
37+
return price;
38+
}
39+
40+
@Field("price")
41+
protected void setPrice(String price) {
42+
this.price = price;
43+
}
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.solrjava;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.solr.client.solrj.SolrServerException;
6+
import org.apache.solr.client.solrj.impl.HttpSolrClient;
7+
import org.apache.solr.client.solrj.impl.XMLResponseParser;
8+
import org.apache.solr.common.SolrInputDocument;
9+
10+
public class SolrJavaIntegration {
11+
12+
private HttpSolrClient solrClient;
13+
14+
public SolrJavaIntegration(String clientUrl) {
15+
16+
solrClient = new HttpSolrClient.Builder(clientUrl).build();
17+
solrClient.setParser(new XMLResponseParser());
18+
}
19+
20+
public void addProductBean(ProductBean pBean) throws IOException, SolrServerException {
21+
22+
solrClient.addBean(pBean);
23+
solrClient.commit();
24+
}
25+
26+
public void addSolrDocument(String documentId, String itemName, String itemPrice) throws SolrServerException, IOException {
27+
28+
SolrInputDocument document = new SolrInputDocument();
29+
document.addField("id", documentId);
30+
document.addField("name", itemName);
31+
document.addField("price", itemPrice);
32+
solrClient.add(document);
33+
solrClient.commit();
34+
}
35+
36+
public void deleteSolrDocumentById(String documentId) throws SolrServerException, IOException {
37+
38+
solrClient.deleteById(documentId);
39+
solrClient.commit();
40+
}
41+
42+
public void deleteSolrDocumentByQuery(String query) throws SolrServerException, IOException {
43+
44+
solrClient.deleteByQuery(query);
45+
solrClient.commit();
46+
}
47+
48+
protected HttpSolrClient getSolrClient() {
49+
return solrClient;
50+
}
51+
52+
protected void setSolrClient(HttpSolrClient solrClient) {
53+
this.solrClient = solrClient;
54+
}
55+
56+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.baeldung.solrjava;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.IOException;
6+
7+
import org.apache.solr.client.solrj.SolrQuery;
8+
import org.apache.solr.client.solrj.SolrServerException;
9+
import org.apache.solr.client.solrj.response.QueryResponse;
10+
import org.apache.solr.common.SolrDocument;
11+
import org.apache.solr.common.SolrDocumentList;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
15+
public class SolrJavaIntegrationTest {
16+
17+
private SolrJavaIntegration solrJavaIntegration;
18+
19+
@Before
20+
public void setUp() throws Exception {
21+
22+
solrJavaIntegration = new SolrJavaIntegration("http://localhost:8983/solr/bigboxstore");
23+
solrJavaIntegration.addSolrDocument("123456", "Kenmore Dishwasher", "599.99");
24+
}
25+
26+
@Test
27+
public void whenAdd_thenVerifyAddedByQueryOnId() throws SolrServerException, IOException {
28+
29+
SolrQuery query = new SolrQuery();
30+
query.set("q", "id:123456");
31+
QueryResponse response = null;
32+
33+
response = solrJavaIntegration.getSolrClient().query(query);
34+
35+
SolrDocumentList docList = response.getResults();
36+
assertEquals(docList.getNumFound(), 1);
37+
38+
for (SolrDocument doc : docList) {
39+
assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name"));
40+
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
41+
}
42+
}
43+
44+
@Test
45+
public void whenAdd_thenVerifyAddedByQueryOnPrice() throws SolrServerException, IOException {
46+
47+
SolrQuery query = new SolrQuery();
48+
query.set("q", "price:599.99");
49+
QueryResponse response = null;
50+
51+
response = solrJavaIntegration.getSolrClient().query(query);
52+
53+
SolrDocumentList docList = response.getResults();
54+
assertEquals(1, docList.getNumFound());
55+
56+
for (SolrDocument doc : docList) {
57+
assertEquals("123456", (String) doc.getFieldValue("id"));
58+
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
59+
}
60+
}
61+
62+
@Test
63+
public void whenAdd_thenVerifyAddedByQuery() throws SolrServerException, IOException {
64+
65+
SolrDocument doc = solrJavaIntegration.getSolrClient().getById("123456");
66+
assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name"));
67+
assertEquals((Double) 599.99, (Double) doc.getFieldValue("price"));
68+
}
69+
70+
@Test
71+
public void whenAddBean_thenVerifyAddedByQuery() throws SolrServerException, IOException {
72+
73+
ProductBean pBean = new ProductBean("888", "Apple iPhone 6s", "299.99");
74+
solrJavaIntegration.addProductBean(pBean);
75+
76+
SolrDocument doc = solrJavaIntegration.getSolrClient().getById("888");
77+
assertEquals("Apple iPhone 6s", (String) doc.getFieldValue("name"));
78+
assertEquals((Double) 299.99, (Double) doc.getFieldValue("price"));
79+
}
80+
81+
@Test
82+
public void whenDeleteById_thenVerifyDeleted() throws SolrServerException, IOException {
83+
84+
solrJavaIntegration.deleteSolrDocumentById("123456");
85+
86+
SolrQuery query = new SolrQuery();
87+
query.set("q", "id:123456");
88+
QueryResponse response = solrJavaIntegration.getSolrClient().query(query);
89+
90+
SolrDocumentList docList = response.getResults();
91+
assertEquals(0, docList.getNumFound());
92+
}
93+
94+
@Test
95+
public void whenDeleteByQuery_thenVerifyDeleted() throws SolrServerException, IOException {
96+
97+
solrJavaIntegration.deleteSolrDocumentByQuery("name:Kenmore Dishwasher");
98+
99+
SolrQuery query = new SolrQuery();
100+
query.set("q", "id:123456");
101+
QueryResponse response = null;
102+
103+
response = solrJavaIntegration.getSolrClient().query(query);
104+
105+
SolrDocumentList docList = response.getResults();
106+
assertEquals(0, docList.getNumFound());
107+
}
108+
}

‎apache-thrift/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Relevant articles:
2+
3+
- [Working with Apache Thrift](http://www.baeldung.com/apache-thrift)

‎apache-velocity/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Relevant articles:
2+
3+
- [Introduction to Apache Velocity](http://www.baeldung.com/apache-velocity)

0 commit comments

Comments
 (0)