From 2bca32bb8682f56bb234e4a406937c9c636717cb Mon Sep 17 00:00:00 2001 From: Artur Konczak Date: Fri, 8 Aug 2014 09:32:35 +0100 Subject: [PATCH] DATAES-93 Added test to validate SpEL for indexName --- .../data/elasticsearch/SpELEntityTest.java | 68 +++++++++++++++++++ .../elasticsearch/entities/SpELEntity.java | 39 +++++++++++ .../repositories/spel/SpELRepository.java | 27 ++++++++ src/test/resources/spel-repository-test.xml | 19 ++++++ 4 files changed, 153 insertions(+) create mode 100644 src/test/java/org/springframework/data/elasticsearch/SpELEntityTest.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/entities/SpELEntity.java create mode 100644 src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELRepository.java create mode 100644 src/test/resources/spel-repository-test.xml diff --git a/src/test/java/org/springframework/data/elasticsearch/SpELEntityTest.java b/src/test/java/org/springframework/data/elasticsearch/SpELEntityTest.java new file mode 100644 index 000000000..c14e46207 --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/SpELEntityTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.elasticsearch; + +import static org.hamcrest.core.Is.*; +import static org.junit.Assert.*; + +import org.elasticsearch.index.query.QueryBuilders; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.entities.SpELEntity; +import org.springframework.data.elasticsearch.repositories.spel.SpELRepository; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * User: akonczak@gmail.com + * Date: 07/08/14 + * Time: 22:35 + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:/spel-repository-test.xml") +public class SpELEntityTest { + + + @Autowired + private SpELRepository repository; + + @Autowired + private ElasticsearchTemplate template; + + @Before + public void init() { + repository.deleteAll(); + } + + @Test + public void shouldDo() { + //Given + repository.save(new SpELEntity()); + repository.save(new SpELEntity()); + //When + + //Then + NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery()); + nativeSearchQuery.addIndices("abz-entity"); + long count = template.count(nativeSearchQuery); + assertThat(count, is(2L)); + } +} diff --git a/src/test/java/org/springframework/data/elasticsearch/entities/SpELEntity.java b/src/test/java/org/springframework/data/elasticsearch/entities/SpELEntity.java new file mode 100644 index 000000000..a6805502e --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/entities/SpELEntity.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.elasticsearch.entities; + +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; + +/** + * User: akonczak@gmail.com + * Date: 07/08/14 + * Time: 22:26 + */ +@Document(indexName = "#{'abz'+'-'+'entity'}", type = "spel", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1") +public class SpELEntity { + + @Id + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELRepository.java new file mode 100644 index 000000000..62756773b --- /dev/null +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.elasticsearch.repositories.spel; + +import org.springframework.data.elasticsearch.entities.SpELEntity; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +/** + * @author Rizwan Idrees + * @author Mohsin Husen + */ +public interface SpELRepository extends ElasticsearchRepository { + +} diff --git a/src/test/resources/spel-repository-test.xml b/src/test/resources/spel-repository-test.xml new file mode 100644 index 000000000..99cf7426f --- /dev/null +++ b/src/test/resources/spel-repository-test.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file