Skip to content

Commit

Permalink
Minor test related fixes for mapping get/put actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cihat Keser committed May 23, 2013
1 parent 470c716 commit 7a6672c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 11 deletions.
71 changes: 68 additions & 3 deletions src/test/java/io/searchbox/indices/GetMappingIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import com.github.tlrx.elasticsearch.test.annotations.*;
import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
import com.google.gson.JsonObject;
import io.searchbox.Action;
import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import io.searchbox.indices.mapping.GetMapping;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

/**
* @author cihat keser
Expand Down Expand Up @@ -77,4 +77,69 @@ public void testWithSingleIndex() throws IOException {
jsonResult.contains(INDEX_1_NAME));
}

@Test
@ElasticsearchIndexes(indexes = {
@ElasticsearchIndex(indexName = INDEX_1_NAME, mappings = {
@ElasticsearchMapping(typeName = "science-fiction",
properties = {
@ElasticsearchMappingField(name = "title", store = ElasticsearchMappingField.Store.Yes, type = ElasticsearchMappingField.Types.String),
@ElasticsearchMappingField(name = "author", store = ElasticsearchMappingField.Store.Yes, type = ElasticsearchMappingField.Types.String)
})
}),
@ElasticsearchIndex(indexName = INDEX_2_NAME),
@ElasticsearchIndex(indexName = "irrelevant")}
)
public void testWithMultipleIndices() throws IOException {
Action getMapping = new GetMapping.Builder().addIndexName(INDEX_2_NAME).addIndexName(INDEX_1_NAME).build();
JestResult result = client.execute(getMapping);
assertNotNull(result);
JsonObject resultJsonObject = result.getJsonObject();
assertTrue("Get-mapping result should contain mapping for the added index name(s).",
resultJsonObject.has(INDEX_1_NAME));
assertTrue("Get-mapping result should contain mapping for the added index name(s).",
resultJsonObject.has(INDEX_2_NAME));
}

/**
* An interesting edge-case (?) test...
* elasticsearch returns mapping of only the first index even if you specify "_all" as index name.
* @see <a href="http://elasticsearch-users.115913.n3.nabble.com/TypeMissingException-type-all-missing-td3638313.html"></a>
*
* But the mapping api docs kinda contradicts with said behaviour...
* @see <a href="http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/"></a>
*
* @throws IOException
*/
@Ignore
@Test
@ElasticsearchIndexes(indexes = {
@ElasticsearchIndex(indexName = INDEX_1_NAME),
@ElasticsearchIndex(indexName = INDEX_2_NAME, mappings = {
@ElasticsearchMapping(typeName = "science-fiction", compress = false,
properties = {
@ElasticsearchMappingField(name = "title", store = ElasticsearchMappingField.Store.No, type = ElasticsearchMappingField.Types.String),
@ElasticsearchMappingField(name = "author", store = ElasticsearchMappingField.Store.No, type = ElasticsearchMappingField.Types.String)
}
)
}),
@ElasticsearchIndex(indexName = "irrelevant", mappings = {
@ElasticsearchMapping(typeName = "science-fiction", compress = false,
properties = {
@ElasticsearchMappingField(name = "ccc", store = ElasticsearchMappingField.Store.No, type = ElasticsearchMappingField.Types.String),
@ElasticsearchMappingField(name = "cccccc", store = ElasticsearchMappingField.Store.No, type = ElasticsearchMappingField.Types.String)
}
)
})}
)
public void testWithMultipleTypes() throws IOException {
Action getMapping = new GetMapping.Builder().addIndexType("science-fiction").build();
JestResult result = client.execute(getMapping);
assertNotNull(result);
JsonObject resultJsonObject = result.getJsonObject();
assertTrue("Get-mapping result should contain mapping for the added index name(s).",
resultJsonObject.has(INDEX_1_NAME));
assertTrue("Get-mapping result should contain mapping for the added index name(s).",
resultJsonObject.has(INDEX_2_NAME));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner;
import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import io.searchbox.indices.mapping.GetMapping;
import io.searchbox.indices.mapping.PutMapping;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
Expand Down Expand Up @@ -65,14 +66,14 @@ public void testPutMappingWithDocumentMapperBuilder() {
fail("Test failed while executing creating index with default settings");
}

// try {
// JestResult result = client.execute(new GetMapping(INDEX_NAME, INDEX_TYPE));
// assertNotNull(result);
// assertTrue(result.isSucceeded());
// assertEquals("Actual mapping JSON does not match with the expected mapping", expectedMappingSource, result.getJsonString());
// } catch (IOException e) {
// fail("Test failed while retrieving mapping information");
// }
try {
JestResult result = client.execute(new GetMapping.Builder().addIndexName(INDEX_NAME).addIndexType(INDEX_TYPE).build());
assertNotNull(result);
assertTrue(result.isSucceeded());
assertEquals("Actual mapping JSON does not match with the expected mapping", expectedMappingSource, result.getJsonString());
} catch (IOException e) {
fail("Test failed while retrieving mapping information");
}
}

}

0 comments on commit 7a6672c

Please sign in to comment.