org.springframework.shell.core.JLineShellComponent Java Examples

The following examples show how to use org.springframework.shell.core.JLineShellComponent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void disconnect() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD );
    assertTrue( disconnectResult.isSuccess() );
}
 
Example #2
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectToInstance_instanceDoesNotExist() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Try to connect to a non-existing instance.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance doesNotExist";
    final CommandResult result = shell.executeCommand(cmd);
    assertFalse( result.isSuccess() );
}
 
Example #3
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo_wrongCredentials() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the wrong password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("asjifo[ijwa".toCharArray());

    // Execute the command
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the command failed.
    assertFalse( connectResult.isSuccess() );
}
 
Example #4
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Execute the connect command.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the connection was successful.
    assertTrue( connectResult.isSuccess() );
}
 
Example #5
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void printConnectionDetails_connectedToMongo_noAuths() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of MongoDB using the following parameters:\n" +
            "    Hostname: " + super.getMongoHostname() + "\n" +
            "    Port: " + super.getMongoPort() + "\n";
    assertEquals(expected, msg);
}
 
Example #6
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void connectToInstance_instanceDoesNotExist() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Try to connect to a non-existing instance.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance doesNotExist";
    final CommandResult result = shell.executeCommand(cmd);
    assertFalse( result.isSuccess() );
}
 
Example #7
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void connectToInstance_noAuths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final ApplicationContext context = bootstrap.getApplicationContext();
    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    CommandResult result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
 
Example #8
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void connectMongo_noAuth() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();

    final CommandResult connectResult = shell.executeCommand(cmd);

    // Ensure the connection was successful.
    assertTrue(connectResult.isSuccess());
}
 
Example #9
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToAccumulo() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of Accumulo using the following parameters:\n" +
            "    Username: root\n" +
            "    Instance Name: " + cluster.getInstanceName() + "\n" +
            "    Zookeepers: " + cluster.getZooKeepers();
    assertEquals(expected, msg);
}
 
Example #10
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_notConnected() {
    final JLineShellComponent shell = getTestShell();

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected = "The shell is not connected to anything.";
    assertEquals(expected, msg);
}
 
Example #11
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_notConnected() {
    final JLineShellComponent shell = getTestShell();

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected = "The shell is not connected to anything.";
    assertEquals(expected, msg);
}
 
Example #12
Source File: LensInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private void closeShell(JLineShell shell) {
  if (shell instanceof LensJLineShellComponent) {
    ((LensJLineShellComponent) shell).stop();
  } else {
    ((JLineShellComponent) shell).stop();
  }
}
 
Example #13
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void printConnectionDetails_connectedToMongo_auths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort() + " " +
                    "--username bob";
    shell.executeCommand(cmd);

    // Run the print connection details command.
    final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD );
    final String msg = (String) printResult.getResult();

    final String expected =
            "The shell is connected to an instance of MongoDB using the following parameters:\n" +
            "    Hostname: " + super.getMongoHostname() + "\n" +
            "    Port: " + super.getMongoPort() + "\n" +
            "    Username: bob\n";
    assertEquals(expected, msg);
}
 
Example #14
Source File: BootShim.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
public ExitShellRequest run() {
	sw.start();
	String[] commandsToExecuteAndThenQuit = commandLine.getShellCommandsToExecute();
	JLineShellComponent shell = (JLineShellComponent) this.ctx.getBean("shell", JLineShellComponent.class);
	ExitShellRequest exitShellRequest;
	if (null != commandsToExecuteAndThenQuit) {
		boolean successful = false;
		exitShellRequest = ExitShellRequest.FATAL_EXIT;
		String[] arr$ = commandsToExecuteAndThenQuit;
		int len$ = commandsToExecuteAndThenQuit.length;

		for (int i$ = 0; i$ < len$; ++i$) {
			String cmd = arr$[i$];
			successful = shell.executeCommand(cmd).isSuccess();
			if (!successful) {
				break;
			}
		}

		if (successful) {
			exitShellRequest = ExitShellRequest.NORMAL_EXIT;
		}
	} else {
		shell.start();
		shell.promptLoop();
		exitShellRequest = shell.getExitShellRequest();
		if (exitShellRequest == null) {
			exitShellRequest = ExitShellRequest.NORMAL_EXIT;
		}

		shell.waitForComplete();
	}

	sw.stop();
	if (shell.isDevelopmentMode()) {
		System.out.println("Total execution time: " + sw.getLastTaskTimeMillis() + " ms");
	}

	return exitShellRequest;
}
 
Example #15
Source File: TaskScheduleCommandTemplate.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
public TaskScheduleCommandTemplate(JLineShellComponent dataFlowShell, ApplicationContext applicationContext) {
	this.dataFlowShell = dataFlowShell;

	ConfigurableListableBeanFactory beanFactory = ((AnnotationConfigServletWebServerApplicationContext) applicationContext)
			.getBeanFactory();
	schedule = Mockito.mock(SchedulerService.class);
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TaskSchedulerController.class);
	builder.addConstructorArgValue(schedule);
	DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) beanFactory;
	listableBeanFactory.setAllowBeanDefinitionOverriding(true);
	listableBeanFactory.registerBeanDefinition("taskSchedulerController", builder.getBeanDefinition());
}
 
Example #16
Source File: MongoRyaShellIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void disconnect() throws IOException {
    final JLineShellComponent shell = getTestShell();

    // Connect to the Mongo instance.
    final String cmd =
            RyaConnectionCommands.CONNECT_MONGO_CMD + " " +
                    "--hostname " + super.getMongoHostname() + " " +
                    "--port " + super.getMongoPort();
    shell.executeCommand(cmd);

    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD );
    assertTrue( disconnectResult.isSuccess() );
}
 
Example #17
Source File: AbstractShellIntegrationTest.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startUp() {
	if (applicationContext == null) {
		if (System.getProperty(SHUTDOWN_AFTER_RUN) != null) {
			shutdownAfterRun = Boolean.getBoolean(SHUTDOWN_AFTER_RUN);
		}

		SpringApplication application = new SpringApplicationBuilder(TestConfig.class).build();

		int randomPort = SocketUtils.findAvailableTcpPort();
		String dataFlowUri = String.format("--dataflow.uri=http://localhost:%s", serverPort);
		String dataSourceUrl = String.format("jdbc:h2:tcp://localhost:%s/mem:dataflow", randomPort);
		applicationContext = application.run(String.format("--server.port=%s", serverPort), dataFlowUri,
				"--spring.jmx.default-domain=" + System.currentTimeMillis(), "--spring.jmx.enabled=false",
				"--security.basic.enabled=false", "--spring.main.show_banner=false",
				"--spring.cloud.config.enabled=false",
				"--spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration,org.springframework.cloud.deployer.spi.kubernetes.KubernetesAutoConfiguration",
				"--spring.datasource.url=" + dataSourceUrl,
				"--spring.cloud.dataflow.features.schedules-enabled=true");

		JLineShellComponent shell = applicationContext.getBean(JLineShellComponent.class);

		skipperClient = applicationContext.getBean(SkipperClient.class);

		if (!shell.isRunning()) {
			shell.start();
		}
		dataFlowShell = new DataFlowShell(shell);
	}
}
 
Example #18
Source File: AbstractShellIntegrationTest.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startUp() throws InterruptedException, IOException {
	if (applicationContext == null) {
		if (System.getProperty(SHUTDOWN_AFTER_RUN) != null) {
			shutdownAfterRun = Boolean.getBoolean(SHUTDOWN_AFTER_RUN);
		}

		SpringApplication application = new SpringApplicationBuilder(TestConfig.class).build();

		int randomPort = SocketUtils.findAvailableTcpPort();
		String dataFlowUri = String.format("--dataflow.uri=http://localhost:%s", serverPort);
		String dataSourceUrl = String.format("jdbc:h2:tcp://localhost:%s/mem:dataflow", randomPort);
		applicationContext = application.run(
				String.format("--server.port=%s", serverPort),
				dataFlowUri,
				"--spring.jmx.default-domain=" + System.currentTimeMillis(),
				"--spring.jmx.enabled=false",
				"--security.basic.enabled=false",
				"--spring.main.show_banner=false",
				"--spring.cloud.config.enabled=false",
				"--spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.session.SessionAutoConfiguration",
				"--spring.datasource.url=" + dataSourceUrl);

		JLineShellComponent shell = applicationContext.getBean(JLineShellComponent.class);
		if (!shell.isRunning()) {
			shell.start();
		}
		dataFlowShell = new DataFlowShell(shell);
	}
}
 
Example #19
Source File: ContextCommandsTest.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public void exists() throws Exception {
    Bootstrap bootstrap = new Bootstrap();

    JLineShellComponent shell = bootstrap.getJLineShellComponent();

    CommandResult cr = shell.executeCommand("exists /analytics");
    assertEquals(true, cr.isSuccess());
}
 
Example #20
Source File: BootShim.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public ExitShellRequest run() throws IllegalAccessException {
    sw.start();
    String[] commandsToExecuteAndThenQuit = commandLine.getShellCommandsToExecute();
    JLineShellComponent shell = this.ctx.getBean("shell", JLineShellComponent.class);
    ExitShellRequest exitShellRequest;
    if (null != commandsToExecuteAndThenQuit) {
        boolean successful = false;
        exitShellRequest = ExitShellRequest.FATAL_EXIT;
        for (String cmd : commandsToExecuteAndThenQuit) {
            successful = shell.executeCommand(cmd).isSuccess();
            if (!successful) {
                break;
            }
        }
        if (successful) {
            exitShellRequest = ExitShellRequest.NORMAL_EXIT;
        }
    } else {
        shell.start();
        shell.promptLoop();
        exitShellRequest = shell.getExitShellRequest();
        if (exitShellRequest == null) {
            exitShellRequest = ExitShellRequest.NORMAL_EXIT;
        }
        shell.waitForComplete();
    }
    sw.stop();
    if (shell.isDevelopmentMode()) {
        System.out.println("Total execution time: " + sw.getLastTaskTimeMillis() + " ms");
    }
    return exitShellRequest;
}
 
Example #21
Source File: SimpleCLIIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
public static JLineShellComponent getShell() {
    return shell;
}
 
Example #22
Source File: RyaShellMongoITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * @return The shell that will be tested.
 */
public JLineShellComponent getTestShell() {
    return shell;
}
 
Example #23
Source File: ShellConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean(name = "shell")
JLineShellComponent shell() {
  return new JLineShellComponent();
}
 
Example #24
Source File: InstallProgress.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
public InstallProgress(JLineShellComponent shell, AmbariClient client, boolean exit) {
  super(shell, FlashType.INSTALL);
  this.client = client;
  this.exit = exit;
}
 
Example #25
Source File: FlashService.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Autowired
public FlashService(AmbariClient client, JLineShellComponent shell, ExecutorService executorService) {
  this.client = client;
  this.shell = shell;
  this.executorService = executorService;
}
 
Example #26
Source File: AbstractFlash.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
protected AbstractFlash(JLineShellComponent shell, FlashType flashType) {
  this.shell = shell;
  this.flashType = flashType;
}
 
Example #27
Source File: BootShim.java    From hdfs-shell with Apache License 2.0 4 votes vote down vote up
private void configureApplicationContext(ConfigurableApplicationContext annctx) {
    this.createAndRegisterBeanDefinition(annctx, JLineShellComponent.class, "shell");
    annctx.getBeanFactory().registerSingleton("commandLine", commandLine);
}
 
Example #28
Source File: AccumuloRyaConnectionCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void connectToInstance() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean( SharedShellState.class );
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
 
Example #29
Source File: AccumuloRyaCommandsIT.java    From rya with Apache License 2.0 4 votes vote down vote up
@Test
public void loadsAndQueryData() throws Exception {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();

    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class );
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());

    // Connect to the mini accumulo instance.
    String cmd =
            RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " +
                    "--username root " +
                    "--instanceName " + cluster.getInstanceName() + " "+
                    "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);

    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();

    final InstallPrompt installPrompt = context.getBean( InstallPrompt.class );
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn( installConf );
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);

    result = shell.executeCommand( RyaAdminCommands.INSTALL_CMD );
    assertTrue( result.isSuccess() );

    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Load a statements file into the instance.
    cmd = RyaCommands.LOAD_DATA_CMD + " --file src/test/resources/test-statements.nt";
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );

    // Query for all of the statements that were loaded.
    final SparqlPrompt sparqlPrompt = context.getBean(SparqlPrompt.class);
    when(sparqlPrompt.getSparql()).thenReturn(Optional.of("select * where { ?s ?p ?o .}"));

    cmd = RyaCommands.SPARQL_QUERY_CMD;
    result = shell.executeCommand(cmd);
    assertTrue( result.isSuccess() );
}
 
Example #30
Source File: RyaShellAccumuloITBase.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * @return The shell that will be tested.
 */
public JLineShellComponent getTestShell() {
    return shell;
}