use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class LuceneCommandsSecurityDUnitTest method verifySearchIndexPermissions.
@Test
@Parameters(method = "getSearchIndexUserNameAndExpectedResponses")
public void verifySearchIndexPermissions(UserNameAndExpectedResponse user) throws Exception {
// Create index and region
createIndexAndRegion();
// Connect gfsh
this.gfshShell.secureConnectAndVerify(this.locator.getPort(), GfshShellConnectionRule.PortType.locator, user.getUserName(), user.getUserName());
// Attempt to search lucene index
CommandResult result = this.gfshShell.executeCommand(getSearchIndexCommand());
// Verify result
verifyResult(user, result);
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class LuceneCommandsSecurityDUnitTest method verifyDestroyIndexPermissions.
@Test
@Parameters(method = "getDestroyIndexUserNameAndExpectedResponses")
public void verifyDestroyIndexPermissions(UserNameAndExpectedResponse user) throws Exception {
// Create index and region
createIndexAndRegion();
// Connect gfsh
this.gfshShell.secureConnectAndVerify(this.locator.getPort(), GfshShellConnectionRule.PortType.locator, user.getUserName(), user.getUserName());
// Attempt to search lucene index
CommandResult result = this.gfshShell.executeCommand(getDestroyIndexCommand());
// Verify result
verifyResult(user, result);
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class LuceneIndexCommandsDUnitTest method testDestroyNonExistentSingleIndex.
@Test
public void testDestroyNonExistentSingleIndex() throws Exception {
final VM vm1 = Host.getHost(0).getVM(1);
vm1.invoke(() -> createRegion());
CommandResult result = createAndExecuteDestroyIndexCommand(INDEX_NAME, REGION_NAME);
String resultAsString = commandResultToString(result);
String expectedStatus = LocalizedStrings.LuceneService_INDEX_0_NOT_FOUND_IN_REGION_1.toLocalizedString(new Object[] { INDEX_NAME, '/' + REGION_NAME });
assertTrue(resultAsString.contains(expectedStatus));
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testSearchIndex.
@Test
public void testSearchIndex() throws Exception {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
final List<Set<LuceneSearchResults>> queryResultsList = new ArrayList<>();
HashSet<LuceneSearchResults> queryResults = new HashSet<>();
queryResults.add(createQueryResults("A", "Result1", Float.valueOf("1.3")));
queryResults.add(createQueryResults("B", "Result1", Float.valueOf("1.2")));
queryResults.add(createQueryResults("C", "Result1", Float.valueOf("1.1")));
queryResultsList.add(queryResults);
doReturn(mockResultCollector).when(commands).executeSearch(isA(LuceneQueryInfo.class));
doReturn(queryResultsList).when(mockResultCollector).getResult();
CommandResult result = (CommandResult) commands.searchIndex("index", "region", "Result1", "field1", -1, false);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("C", "B", "A"), data.retrieveAllValues("key"));
assertEquals(Arrays.asList("Result1", "Result1", "Result1"), data.retrieveAllValues("value"));
assertEquals(Arrays.asList("1.1", "1.2", "1.3"), data.retrieveAllValues("score"));
}
use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testListIndexWithoutStats.
@Test
public void testListIndexWithoutStats() {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final AbstractExecution mockFunctionExecutor = mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, true, serverName);
final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, false, serverName);
final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, true, serverName);
final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
results.add(CollectionUtils.asSet(indexDetails2, indexDetails1, indexDetails3));
when(mockFunctionExecutor.execute(isA(LuceneListIndexFunction.class))).thenReturn(mockResultCollector);
when(mockResultCollector.getResult()).thenReturn(results);
final LuceneIndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
CommandResult result = (CommandResult) commands.listIndex(false);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("memberFive", "memberSix", "memberTen"), data.retrieveAllValues("Index Name"));
assertEquals(Arrays.asList("/Employees", "/Employees", "/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Arrays.asList("[field1, field2, field3]", "[field1, field2, field3]", "[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Arrays.asList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Arrays.asList("Initialized", "Defined", "Initialized"), data.retrieveAllValues("Status"));
}
Aggregations