CompanyIndexFactory implements ElasticsearchConfigurationObserver, IndexContributorReceiver,
			   IndexFactory { @Override public void createIndices(IndicesClient indicesClient, long companyId) { String indexName = getIndexName(companyId); if (hasIndex(indicesClient, indexName)) { return; } createIndex(indexName, indicesClient); }  @Override void addIndexContributor(IndexContributor indexContributor); @Override int compareTo(
		ElasticsearchConfigurationObserver elasticsearchConfigurationObserver); @Override void createIndices(IndicesClient indicesClient, long companyId); @Override void deleteIndices(IndicesClient indicesClient, long companyId); @Override int getPriority(); @Override void onElasticsearchConfigurationUpdate(); @Override synchronized void registerCompanyId(long companyId); @Override void removeIndexContributor(IndexContributor indexContributor); @Override synchronized void unregisterCompanyId(long companyId);  }
@Test public void testAdditionalIndexConfigurations() throws Exception { Mockito.when( _elasticsearchConfigurationWrapper.additionalIndexConfigurations() ).thenReturn( "index.number_of_replicas: 1\nindex.number_of_shards: 2" ); createIndices(); Settings settings = getIndexSettings(); Assert.assertEquals("1", settings.get("index.number_of_replicas")); Assert.assertEquals("2", settings.get("index.number_of_shards")); }
@Test public void testCreateIndicesWithBlankStrings() throws Exception { Mockito.when( _elasticsearchConfigurationWrapper.additionalIndexConfigurations() ).thenReturn( StringPool.BLANK ); Mockito.when( _elasticsearchConfigurationWrapper.additionalTypeMappings() ).thenReturn( StringPool.SPACE ); Mockito.when( _elasticsearchConfigurationWrapper.indexNumberOfReplicas() ).thenReturn( StringPool.BLANK ); Mockito.when( _elasticsearchConfigurationWrapper.indexNumberOfShards() ).thenReturn( StringPool.SPACE ); createIndices(); }
@Test public void testCreateIndicesWithEmptyConfiguration() throws Exception { createIndices(); }
@Test public void testDefaultIndexSettings() throws Exception { createIndices(); Settings settings = getIndexSettings(); Assert.assertEquals("0", settings.get("index.number_of_replicas")); Assert.assertEquals("1", settings.get("index.number_of_shards")); }
@Test public void testDefaultIndices() throws Exception { createIndices(); assertMappings(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME); }
@Test public void testIndexConfigurations() throws Exception { Mockito.when( _elasticsearchConfigurationWrapper.indexNumberOfReplicas() ).thenReturn( "1" ); Mockito.when( _elasticsearchConfigurationWrapper.indexNumberOfShards() ).thenReturn( "2" ); createIndices(); Settings settings = getIndexSettings(); Assert.assertEquals("1", settings.get("index.number_of_replicas")); Assert.assertEquals("2", settings.get("index.number_of_shards")); }
@Test public void testOverrideTypeMappings() throws Exception { Mockito.when( _elasticsearchConfigurationWrapper.additionalIndexConfigurations() ).thenReturn( loadAdditionalAnalyzers() ); Mockito.when( _elasticsearchConfigurationWrapper.overrideTypeMappings() ).thenReturn( loadOverrideTypeMappings() ); createIndices(); String field1 = "title"; indexOneDocument(field1); assertAnalyzer(field1, "kuromoji_liferay_custom"); String field2 = "description"; indexOneDocument(field2); assertNoAnalyzer(field2); }
@Test public void testOverrideTypeMappingsHonorDefaultIndices() throws Exception { Mockito.when( _elasticsearchConfigurationWrapper.additionalIndexConfigurations() ).thenReturn( loadAdditionalAnalyzers() ); Mockito.when( _elasticsearchConfigurationWrapper.overrideTypeMappings() ).thenReturn( loadOverrideTypeMappings() ); createIndices(); assertMappings(Field.TITLE); }