Fix bugs in mock Index logic regarding (mock) Region references.
This commit is contained in:
@@ -163,6 +163,7 @@ import org.apache.geode.pdx.PdxSerializer;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
import org.springframework.data.gemfire.RegionShortcutWrapper;
|
||||
import org.springframework.data.gemfire.client.ClientRegionShortcutWrapper;
|
||||
@@ -2318,13 +2319,34 @@ public abstract class GemFireMockObjectsSupport extends MockObjectsSupport {
|
||||
when(mockIndex.getFromClause()).thenReturn(fromClause);
|
||||
when(mockIndex.getIndexedExpression()).thenReturn(expression);
|
||||
when(mockIndex.getProjectionAttributes()).thenReturn(expression);
|
||||
when(mockIndex.getRegion()).thenAnswer(invocation -> regions.get(fromClause));
|
||||
when(mockIndex.getStatistics()).thenReturn(mockIndexStaticts);
|
||||
when(mockIndex.getType()).thenReturn(indexType.getGemfireIndexType());
|
||||
|
||||
doAnswer(invocation -> {
|
||||
|
||||
String regionName = fromClauseToRegionPath(fromClause);
|
||||
|
||||
return regions.get(regionName);
|
||||
|
||||
}).when(mockIndex).getRegion();
|
||||
|
||||
return mockIndex;
|
||||
}
|
||||
|
||||
private static String fromClauseToRegionPath(String fromClause) {
|
||||
|
||||
String regionName = String.valueOf(fromClause);
|
||||
|
||||
int indexOfDot = regionName.indexOf(".");
|
||||
int indexOfSpace = regionName.indexOf(" ");
|
||||
|
||||
regionName = regionName.startsWith(Region.SEPARATOR) ? regionName : GemfireUtils.toRegionPath(regionName);
|
||||
regionName = indexOfSpace > -1 ? regionName.substring(0, indexOfSpace) : regionName;
|
||||
regionName = indexOfDot > -1 ? regionName.substring(0, indexOfDot) : regionName;
|
||||
|
||||
return regionName;
|
||||
}
|
||||
|
||||
private static IndexStatistics mockIndexStatistics(String name) {
|
||||
return mock(IndexStatistics.class, mockObjectIdentifier(name));
|
||||
}
|
||||
|
||||
@@ -40,10 +40,13 @@ import org.apache.geode.cache.lucene.LuceneIndex;
|
||||
import org.apache.geode.cache.lucene.LuceneIndexFactory;
|
||||
import org.apache.geode.cache.lucene.LuceneSerializer;
|
||||
import org.apache.geode.cache.lucene.LuceneService;
|
||||
import org.apache.geode.cache.query.Index;
|
||||
import org.apache.geode.cache.server.ClientSubscriptionConfig;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
|
||||
/**
|
||||
* Unit Tests for {@link GemFireMockObjectsSupport}.
|
||||
*
|
||||
@@ -139,7 +142,32 @@ public class GemFireMockObjectsSupportUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockLuceneFunctionality() {
|
||||
public void mockIndexIsCorrect() {
|
||||
|
||||
RegionService mockRegionService = mock(RegionService.class);
|
||||
|
||||
RegionAttributes<?, ?> mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
Region<?, ?> mockRegion =
|
||||
GemFireMockObjectsSupport.mockRegion(mockRegionService, "MockIndexRegion", mockRegionAttributes);
|
||||
|
||||
assertThat(mockRegion).isNotNull();
|
||||
|
||||
Index mockIndex = GemFireMockObjectsSupport
|
||||
.mockIndex("MockIndex", "*", "/MockIndexRegion alias", IndexType.FUNCTIONAL);
|
||||
|
||||
assertThat(mockIndex).isNotNull();
|
||||
assertThat(mockIndex.getName()).isEqualTo("MockIndex");
|
||||
assertThat(mockIndex.getRegion()).isNotNull();
|
||||
assertThat(mockIndex.getRegion()).isEqualTo(mockRegion);
|
||||
assertThat(mockIndex.getRegion().getName()).isEqualTo("MockIndexRegion");
|
||||
assertThat(mockIndex.getFromClause()).isEqualTo("/MockIndexRegion alias");
|
||||
assertThat(mockIndex.getIndexedExpression()).isEqualTo("*");
|
||||
assertThat(mockIndex.getType()).isEqualTo(IndexType.FUNCTIONAL.getGemfireIndexType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockLuceneFunctionalityIsCorrect() {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user