Skip to content

Commit 692ae6b

Browse files
committed
Article Repository Tests
1 parent 57f6934 commit 692ae6b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.springframework.data.elasticsearch.repositories;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.data.elasticsearch.entities.Article;
7+
import org.springframework.test.context.ContextConfiguration;
8+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9+
10+
import javax.annotation.Resource;
11+
12+
import static org.hamcrest.CoreMatchers.is;
13+
import static org.hamcrest.CoreMatchers.notNullValue;
14+
import static org.junit.Assert.assertThat;
15+
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
@ContextConfiguration("classpath:/springContext-test.xml")
18+
public class SampleArticleRepositoryTest {
19+
20+
@Resource
21+
private SampleArticleRepository sampleArticleRepository;
22+
23+
@Before
24+
public void emptyData(){
25+
sampleArticleRepository.deleteAll();
26+
}
27+
28+
@Test
29+
public void shouldIndexSingleBookEntity(){
30+
31+
Article article = new Article();
32+
article.setId("123455");
33+
article.setTitle("Spring Data Elasticsearch");
34+
//Indexing using sampleArticleRepository
35+
sampleArticleRepository.save(article);
36+
//lets try to search same record in elasticsearch
37+
Article indexedArticle = sampleArticleRepository.findOne(article.getId());
38+
assertThat(indexedArticle,is(notNullValue()));
39+
assertThat(indexedArticle.getId(),is(article.getId()));
40+
}
41+
}

0 commit comments

Comments
 (0)