use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testSearchIndexWithPaging.
@Ignore
public void testSearchIndexWithPaging() throws Exception {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final Gfsh mockGfsh = mock(Gfsh.class);
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
ArgumentCaptor<String> resultCaptor = ArgumentCaptor.forClass(String.class);
LuceneSearchResults result1 = createQueryResults("A", "Result1", Float.valueOf("1.7"));
LuceneSearchResults result2 = createQueryResults("B", "Result1", Float.valueOf("1.6"));
LuceneSearchResults result3 = createQueryResults("C", "Result1", Float.valueOf("1.5"));
LuceneSearchResults result4 = createQueryResults("D", "Result1", Float.valueOf("1.4"));
LuceneSearchResults result5 = createQueryResults("E", "Result1", Float.valueOf("1.3"));
LuceneSearchResults result6 = createQueryResults("F", "Result1", Float.valueOf("1.2"));
LuceneSearchResults result7 = createQueryResults("G", "Result1", Float.valueOf("1.1"));
final List<Set<LuceneSearchResults>> queryResultsList = getSearchResults(result1, result2, result3, result4, result5, result6, result7);
doReturn(mockResultCollector).when(commands).executeSearch(any(LuceneQueryInfo.class));
doReturn(queryResultsList).when(mockResultCollector).getResult();
doReturn(mockGfsh).when(commands).initGfsh();
when(mockGfsh.interact(anyString())).thenReturn("n").thenReturn("n").thenReturn("n").thenReturn("n").thenReturn("p").thenReturn("p").thenReturn("p").thenReturn("p").thenReturn("p").thenReturn("n").thenReturn("q");
LuceneSearchResults[] expectedResults = new LuceneSearchResults[] { result7, result6, result5, result4, result3, result2, result1 };
String expectedPage1 = getPage(expectedResults, new int[] { 0, 1 });
String expectedPage2 = getPage(expectedResults, new int[] { 2, 3 });
String expectedPage3 = getPage(expectedResults, new int[] { 4, 5 });
String expectedPage4 = getPage(expectedResults, new int[] { 6 });
commands.searchIndex("index", "region", "Result1", "field1", -1, false);
verify(mockGfsh, times(20)).printAsInfo(resultCaptor.capture());
List<String> actualPageResults = resultCaptor.getAllValues();
assertEquals(expectedPage1, actualPageResults.get(0));
assertEquals("\t\tPage 1 of 4", actualPageResults.get(1));
assertEquals(expectedPage2, actualPageResults.get(2));
assertEquals("\t\tPage 2 of 4", actualPageResults.get(3));
assertEquals(expectedPage3, actualPageResults.get(4));
assertEquals("\t\tPage 3 of 4", actualPageResults.get(5));
assertEquals(expectedPage4, actualPageResults.get(6));
assertEquals("\t\tPage 4 of 4", actualPageResults.get(7));
assertEquals("No more results to display.", actualPageResults.get(8));
assertEquals(expectedPage4, actualPageResults.get(9));
assertEquals("\t\tPage 4 of 4", actualPageResults.get(10));
assertEquals(expectedPage3, actualPageResults.get(11));
assertEquals("\t\tPage 3 of 4", actualPageResults.get(12));
assertEquals(expectedPage2, actualPageResults.get(13));
assertEquals("\t\tPage 2 of 4", actualPageResults.get(14));
assertEquals(expectedPage1, actualPageResults.get(15));
assertEquals("\t\tPage 1 of 4", actualPageResults.get(16));
assertEquals("At the top of the search results.", actualPageResults.get(17));
assertEquals(expectedPage1, actualPageResults.get(18));
assertEquals("\t\tPage 1 of 4", actualPageResults.get(19));
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEchoWithMultipleVariables.
@Test
public void testEchoWithMultipleVariables() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testEcho command gfshInstance is null");
}
gfshInstance.setEnvProperty("TESTSYS", "SYS_VALUE");
printAllEnvs(gfshInstance);
String command = "echo --string=\"${TESTSYS} Hello World! This is Pivotal ${TESTSYS}\"";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertTrue(stringResult.contains("SYS_VALUE Hello World! This is Pivotal SYS_VALUE"));
} else {
fail("testEchoWithMultipleVariables failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testHistoryWithEntry.
@Test
public void testHistoryWithEntry() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testHistory command gfshInstance is null");
}
gfshInstance.setDebug(false);
// Generate a line of history
executeCommand("help");
executeCommand("connect");
String command = "history";
CommandResult cmdResult = executeCommand(command);
String result = printCommandOutput(cmdResult);
assertEquals(" 1 0: help\n 2 1: connect\n\n\n", result);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
} else {
fail("testHistory failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEmptyHistory.
@Test
public void testEmptyHistory() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testHistory command gfshInstance is null");
}
gfshInstance.setDebug(false);
String command = "history";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
cmdResult.resetToFirstLine();
assertEquals("", cmdResult.nextLine());
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
} else {
fail("testHistory failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEchoWithVariableAtStart.
@Test
public void testEchoWithVariableAtStart() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testEcho command gfshInstance is null");
}
gfshInstance.setEnvProperty("TESTSYS", "SYS_VALUE");
printAllEnvs(gfshInstance);
String command = "echo --string=\"${TESTSYS} Hello World! This is Pivotal\"";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertTrue(stringResult.contains("SYS_VALUE Hello World! This is Pivotal"));
} else {
fail("testEchoWithVariableAtStart failed");
}
}
Aggregations