Search in sources :

Example 1 with Gfsh

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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) InternalCache(org.apache.geode.internal.cache.InternalCache) Mockito.anyString(org.mockito.Mockito.anyString) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Ignore(org.junit.Ignore)

Example 2 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 3 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 4 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 5 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)40 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 IOException (java.io.IOException)11 CliMetaData (org.apache.geode.management.cli.CliMetaData)7 CliCommand (org.springframework.shell.core.annotation.CliCommand)7 TreeSet (java.util.TreeSet)6 ConnectToLocatorResult (org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult)6 File (java.io.File)5 MalformedURLException (java.net.MalformedURLException)5 Result (org.apache.geode.management.cli.Result)5 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)5 ConverterHint (org.apache.geode.management.cli.ConverterHint)3 JmxOperationInvoker (org.apache.geode.management.internal.cli.shell.JmxOperationInvoker)3 ConnectionEndpoint (org.apache.geode.management.internal.cli.util.ConnectionEndpoint)3 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)3 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)3 ExitShellRequest (org.springframework.shell.core.ExitShellRequest)3