Skip to content

Commit a10c35f

Browse files
committed
[Test] move test package to o.e.index.mapper.attachment
Our package naming for tests is inconsistent. We should move tests from: * `o.e.index.mapper.xcontent` to `o.e.index.mapper.attachment.test.unit` * `o.e.plugin.mapper.attachments.test` to `o.e.index.mapper.attachment.test.integration` * `StandaloneRunner` class to `o.e.index.mapper.attachment.test.standalone` Also rename resource dirs to match the test name so it's definitely easier to find mappings used for each test. Closes elastic#110.
1 parent 4ffa06d commit a10c35f

37 files changed

+143
-144
lines changed

src/test/java/org/elasticsearch/index/mapper/xcontent/MapperTestUtils.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/MapperTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.mapper.xcontent;
20+
package org.elasticsearch.index.mapper.attachment.test;
2121

2222
import org.elasticsearch.Version;
2323
import org.elasticsearch.cluster.metadata.IndexMetaData;

src/test/java/org/elasticsearch/plugin/mapper/attachments/test/MultipleAttachmentIntegrationTests.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/integration/EncryptedAttachmentIntegrationTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.plugin.mapper.attachments.test;
20+
package org.elasticsearch.index.mapper.attachment.test.integration;
2121

2222
import org.elasticsearch.action.count.CountResponse;
2323
import org.elasticsearch.common.settings.ImmutableSettings;
@@ -39,7 +39,7 @@
3939
* Test case for issue https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/18
4040
*/
4141
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
42-
public class MultipleAttachmentIntegrationTests extends ElasticsearchIntegrationTest {
42+
public class EncryptedAttachmentIntegrationTests extends ElasticsearchIntegrationTest {
4343
private boolean ignore_errors = true;
4444

4545
@Override
@@ -67,9 +67,9 @@ public void testMultipleAttachmentsWithEncryptedDoc() throws Exception {
6767
logger.info("creating index [test]");
6868
createIndex("test");
6969

70-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
71-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
72-
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
70+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/encrypted/test-mapping.json");
71+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html");
72+
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/encrypted.pdf");
7373

7474
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
7575

@@ -94,9 +94,9 @@ public void testMultipleAttachmentsWithEncryptedDocNotIgnoringErrors() throws Ex
9494
logger.info("creating index [test]");
9595
createIndex("test");
9696

97-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
98-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
99-
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
97+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/encrypted/test-mapping.json");
98+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html");
99+
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/encrypted.pdf");
100100

101101
client().admin().indices()
102102
.putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();

src/test/java/org/elasticsearch/plugin/mapper/attachments/test/SimpleAttachmentIntegrationTests.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/integration/SimpleAttachmentIntegrationTests.java

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.plugin.mapper.attachments.test;
20+
package org.elasticsearch.index.mapper.attachment.test.integration;
2121

2222
import org.elasticsearch.action.count.CountResponse;
2323
import org.elasticsearch.action.search.SearchResponse;
2424
import org.elasticsearch.common.settings.ImmutableSettings;
2525
import org.elasticsearch.common.settings.Settings;
26+
import org.elasticsearch.common.text.Text;
2627
import org.elasticsearch.index.mapper.MapperParsingException;
2728
import org.elasticsearch.plugins.PluginsService;
29+
import org.elasticsearch.search.highlight.HighlightField;
2830
import org.elasticsearch.test.ElasticsearchIntegrationTest;
2931
import org.junit.Before;
3032
import org.junit.Ignore;
@@ -34,9 +36,10 @@
3436
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
3537
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
3638
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
39+
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
3740
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
38-
import static org.hamcrest.Matchers.equalTo;
39-
import static org.hamcrest.Matchers.is;
41+
import static org.hamcrest.Matchers.*;
42+
import static org.hamcrest.Matchers.containsString;
4043

4144
/**
4245
*
@@ -60,8 +63,8 @@ public void createEmptyIndex() throws Exception {
6063

6164
@Test
6265
public void testSimpleAttachment() throws Exception {
63-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
64-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html");
66+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-mapping.json");
67+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html");
6568

6669
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
6770

@@ -77,8 +80,8 @@ public void testSimpleAttachment() throws Exception {
7780

7881
@Test
7982
public void testSimpleAttachmentContentLengthLimit() throws Exception {
80-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
81-
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testContentLength.txt");
83+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-mapping.json");
84+
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testContentLength.txt");
8285
final int CONTENT_LENGTH_LIMIT = 20;
8386

8487
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
@@ -95,8 +98,8 @@ public void testSimpleAttachmentContentLengthLimit() throws Exception {
9598

9699
@Test
97100
public void testSimpleAttachmentNoContentLengthLimit() throws Exception {
98-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
99-
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testContentLength.txt");
101+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-mapping.json");
102+
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testContentLength.txt");
100103
final int CONTENT_LENGTH_LIMIT = -1;
101104

102105
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
@@ -118,7 +121,7 @@ public void testSimpleAttachmentNoContentLengthLimit() throws Exception {
118121
*/
119122
@Test(expected = MapperParsingException.class)
120123
public void testNoContent() throws Exception {
121-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
124+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-mapping.json");
122125

123126
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
124127

@@ -129,8 +132,8 @@ public void testNoContent() throws Exception {
129132
public void testContentTypeAndName() throws Exception {
130133
String dummyContentType = "text/my-dummy-content-type";
131134
String dummyName = "my-dummy-name-txt";
132-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping-store-content-type.json");
133-
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testContentLength.txt");
135+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-mapping-store-content-type.json");
136+
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testContentLength.txt");
134137

135138
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
136139

@@ -156,8 +159,8 @@ public void testContentTypeAndName() throws Exception {
156159
*/
157160
@Test @Ignore
158161
public void testCopyTo() throws Exception {
159-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/copy-to/copy-to.json");
160-
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/text-in-english.txt");
162+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/copy-to.json");
163+
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/text-in-english.txt");
161164

162165
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
163166

@@ -173,8 +176,8 @@ public void testCopyTo() throws Exception {
173176

174177
@Test
175178
public void testCopyToSubField() throws Exception {
176-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/copy-to/copy-to-subfield.json");
177-
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/text-in-english.txt");
179+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/copy-to-subfield.json");
180+
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/text-in-english.txt");
178181

179182
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
180183

@@ -188,4 +191,31 @@ public void testCopyToSubField() throws Exception {
188191
assertThat(countResponse.getCount(), equalTo(1l));
189192
}
190193

194+
@Test
195+
public void testHighlightAttachment() throws Exception {
196+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/integration/simple/test-highlight-mapping.json");
197+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html");
198+
199+
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
200+
201+
index("test", "person", jsonBuilder().startObject().field("file", html).endObject());
202+
refresh();
203+
204+
SearchResponse searchResponse = client().prepareSearch("test")
205+
.setQuery(matchQuery("file", "apache tika"))
206+
.addHighlightedField("file")
207+
.setNoFields().get();
208+
209+
logger.info("{}", searchResponse);
210+
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
211+
assertThat(searchResponse.getHits().getAt(0).getHighlightFields(), notNullValue());
212+
assertThat(searchResponse.getHits().getAt(0).getHighlightFields().keySet(), contains("file"));
213+
searchResponse.getHits().getAt(0).getHighlightFields();
214+
for (HighlightField highlightField : searchResponse.getHits().getAt(0).getHighlightFields().values()) {
215+
for (Text fragment : highlightField.getFragments()) {
216+
assertThat(fragment.string(), containsString("<em>Apache</em>"));
217+
assertThat(fragment.string(), containsString("<em>Tika</em>"));
218+
}
219+
}
220+
}
191221
}

src/test/java/org/elasticsearch/plugin/mapper/attachments/test/StandaloneRunner.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/standalone/StandaloneRunner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.plugin.mapper.attachments.test;
20+
package org.elasticsearch.index.mapper.attachment.test.standalone;
2121

2222
import org.elasticsearch.common.bytes.BytesReference;
2323
import org.elasticsearch.common.cli.CliTool;
@@ -32,7 +32,7 @@
3232
import org.elasticsearch.index.mapper.DocumentMapperParser;
3333
import org.elasticsearch.index.mapper.ParseContext;
3434
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
35-
import org.elasticsearch.index.mapper.xcontent.MapperTestUtils;
35+
import org.elasticsearch.index.mapper.attachment.test.MapperTestUtils;
3636

3737
import java.io.FileNotFoundException;
3838
import java.io.IOException;
@@ -86,7 +86,7 @@ protected TikaRunner(Terminal terminal, String url, Integer size, String base64t
8686
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
8787
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
8888

89-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
89+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/standalone/standalone-mapping.json");
9090
docMapper = mapperParser.parse(mapping);
9191
}
9292

src/test/java/org/elasticsearch/index/mapper/xcontent/DateAttachmentMapperTests.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/unit/DateAttachmentMapperTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.mapper.xcontent;
20+
package org.elasticsearch.index.mapper.attachment.test.unit;
2121

2222
import org.elasticsearch.index.mapper.DocumentMapper;
2323
import org.elasticsearch.index.mapper.DocumentMapperParser;
2424
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
25+
import org.elasticsearch.index.mapper.attachment.test.MapperTestUtils;
2526
import org.elasticsearch.index.mapper.core.StringFieldMapper;
2627
import org.elasticsearch.test.ElasticsearchTestCase;
2728
import org.junit.Before;
@@ -45,7 +46,7 @@ public void setupMapperParser() {
4546

4647
@Test
4748
public void testSimpleMappings() throws Exception {
48-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/date/date-mapping.json");
49+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/date/date-mapping.json");
4950
DocumentMapper docMapper = mapperParser.parse(mapping);
5051

5152
// Our mapping should be kept as a String

src/test/java/org/elasticsearch/index/mapper/xcontent/EncryptedDocMapperTest.java renamed to src/test/java/org/elasticsearch/index/mapper/attachment/test/unit/EncryptedDocMapperTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.mapper.xcontent;
20+
package org.elasticsearch.index.mapper.attachment.test.unit;
2121

2222
import org.elasticsearch.common.bytes.BytesReference;
2323
import org.elasticsearch.common.settings.ImmutableSettings;
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.index.mapper.MapperParsingException;
2727
import org.elasticsearch.index.mapper.ParseContext;
2828
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
29+
import org.elasticsearch.index.mapper.attachment.test.MapperTestUtils;
2930
import org.elasticsearch.test.ElasticsearchTestCase;
3031
import org.junit.Test;
3132

@@ -48,10 +49,10 @@ public void testMultipleDocsEncryptedLast() throws IOException {
4849
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
4950
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
5051

51-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
52+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
5253
DocumentMapper docMapper = mapperParser.parse(mapping);
53-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
54-
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
54+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html");
55+
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/encrypted.pdf");
5556

5657
BytesReference json = jsonBuilder()
5758
.startObject()
@@ -81,10 +82,10 @@ public void testMultipleDocsEncryptedFirst() throws IOException {
8182
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser();
8283
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
8384

84-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
85+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
8586
DocumentMapper docMapper = mapperParser.parse(mapping);
86-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
87-
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
87+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html");
88+
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/encrypted.pdf");
8889

8990
BytesReference json = jsonBuilder()
9091
.startObject()
@@ -114,10 +115,10 @@ public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
114115
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build());
115116
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
116117

117-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
118+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/encrypted/test-mapping.json");
118119
DocumentMapper docMapper = mapperParser.parse(mapping);
119-
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
120-
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
120+
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/htmlWithValidDateMeta.html");
121+
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/encrypted.pdf");
121122

122123
BytesReference json = jsonBuilder()
123124
.startObject()

0 commit comments

Comments
 (0)