Skip to content

Commit 2bca32b

Browse files
committed
DATAES-93 Added test to validate SpEL for indexName
1 parent 873dcca commit 2bca32b

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2013-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch;
17+
18+
import static org.hamcrest.core.Is.*;
19+
import static org.junit.Assert.*;
20+
21+
import org.elasticsearch.index.query.QueryBuilders;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
27+
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
28+
import org.springframework.data.elasticsearch.entities.SpELEntity;
29+
import org.springframework.data.elasticsearch.repositories.spel.SpELRepository;
30+
import org.springframework.test.context.ContextConfiguration;
31+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
32+
33+
/**
34+
35+
* Date: 07/08/14
36+
* Time: 22:35
37+
*/
38+
39+
@RunWith(SpringJUnit4ClassRunner.class)
40+
@ContextConfiguration("classpath:/spel-repository-test.xml")
41+
public class SpELEntityTest {
42+
43+
44+
@Autowired
45+
private SpELRepository repository;
46+
47+
@Autowired
48+
private ElasticsearchTemplate template;
49+
50+
@Before
51+
public void init() {
52+
repository.deleteAll();
53+
}
54+
55+
@Test
56+
public void shouldDo() {
57+
//Given
58+
repository.save(new SpELEntity());
59+
repository.save(new SpELEntity());
60+
//When
61+
62+
//Then
63+
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
64+
nativeSearchQuery.addIndices("abz-entity");
65+
long count = template.count(nativeSearchQuery);
66+
assertThat(count, is(2L));
67+
}
68+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2013-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch.entities;
17+
18+
import org.springframework.data.annotation.Id;
19+
import org.springframework.data.elasticsearch.annotations.Document;
20+
21+
/**
22+
23+
* Date: 07/08/14
24+
* Time: 22:26
25+
*/
26+
@Document(indexName = "#{'abz'+'-'+'entity'}", type = "spel", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
27+
public class SpELEntity {
28+
29+
@Id
30+
private String id;
31+
32+
public String getId() {
33+
return id;
34+
}
35+
36+
public void setId(String id) {
37+
this.id = id;
38+
}
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2013-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch.repositories.spel;
17+
18+
import org.springframework.data.elasticsearch.entities.SpELEntity;
19+
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
20+
21+
/**
22+
* @author Rizwan Idrees
23+
* @author Mohsin Husen
24+
*/
25+
public interface SpELRepository extends ElasticsearchRepository<SpELEntity, String> {
26+
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
5+
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
6+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
7+
8+
<import resource="infrastructure.xml"/>
9+
10+
<bean name="elasticsearchTemplate"
11+
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
12+
<constructor-arg name="client" ref="client"/>
13+
</bean>
14+
15+
16+
<elasticsearch:repositories
17+
base-package="org.springframework.data.elasticsearch.repositories.spel"/>
18+
19+
</beans>

0 commit comments

Comments
 (0)