Repository: incubator-rya Updated Branches: refs/heads/master 7b571d43a -> 31e06cb1b
RYA-104 Integration tests with Mongo for the shell. Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/00800b68 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/00800b68 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/00800b68 Branch: refs/heads/master Commit: 00800b68e9eccfaf9303e7a750c862907593c820 Parents: 913d7b0 Author: kchilton2 <kevin.e.chil...@gmail.com> Authored: Fri Dec 29 17:56:48 2017 -0500 Committer: kchilton2 <kevin.e.chil...@gmail.com> Committed: Fri Jan 5 16:48:40 2018 -0500 ---------------------------------------------------------------------- .../client/mongo/MongoConnectionDetails.java | 3 +- .../client/mongo/MongoExecuteSparqlQueryIT.java | 4 +- .../client/mongo/MongoGetInstanceDetailsIT.java | 4 +- .../rya/api/client/mongo/MongoInstallIT.java | 4 +- .../api/client/mongo/MongoInstanceExistsIT.java | 4 +- .../api/client/mongo/MongoListInstancesIT.java | 4 +- .../client/mongo/MongoLoadStatementsFileIT.java | 4 +- .../api/client/mongo/MongoLoadStatementsIT.java | 4 +- .../rya/api/client/mongo/MongoUninstallIT.java | 4 +- extras/shell/pom.xml | 6 + .../apache/rya/shell/RyaConnectionCommands.java | 14 +- .../shell/AccumuloRyaConnectionCommandsIT.java | 226 ++++++++++++++ .../org/apache/rya/shell/MongoRyaShellIT.java | 194 ++++++++++++ .../rya/shell/RyaConnectionCommandsIT.java | 297 ------------------- .../rya/shell/RyaShellAccumuloITBase.java | 102 +++++++ .../org/apache/rya/shell/RyaShellITBase.java | 102 ------- .../apache/rya/shell/RyaShellMongoITBase.java | 71 +++++ 17 files changed, 623 insertions(+), 424 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java index b48bb9f..acce15f 100644 --- a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java @@ -112,8 +112,7 @@ public class MongoConnectionDetails { conf.setMongoPassword( new String(password.get()) ); } - // Both of these are ways to configure the collection prefixes. - //TODO these should not be explicitly set + // Default to having a table prefix of "rya", otherwise the app doesn't work for some reason. conf.setTablePrefix("rya"); return conf; } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoExecuteSparqlQueryIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoExecuteSparqlQueryIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoExecuteSparqlQueryIT.java index 1d38410..5c14112 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoExecuteSparqlQueryIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoExecuteSparqlQueryIT.java @@ -28,7 +28,7 @@ import org.apache.rya.api.client.Install.DuplicateInstanceNameException; import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import org.openrdf.model.Statement; import org.openrdf.model.ValueFactory; @@ -39,7 +39,7 @@ import com.mongodb.MongoException; /** * Integration tests the methods of {@link }. */ -public class MongoExecuteSparqlQueryIT extends MongoTestBase { +public class MongoExecuteSparqlQueryIT extends MongoITBase { @Test public void ExecuteSparqlQuery_exec() throws MongoException, DuplicateInstanceNameException, RyaClientException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java index e68ec49..b3d96f6 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java @@ -37,7 +37,7 @@ import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; import org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import com.google.common.base.Optional; @@ -46,7 +46,7 @@ import com.mongodb.MongoException; /** * Tests the methods of {@link MongoGetInstanceDetails}. */ -public class MongoGetInstanceDetailsIT extends MongoTestBase { +public class MongoGetInstanceDetailsIT extends MongoITBase { @Test public void getDetails() throws MongoException, RyaClientException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java index 16991c7..e3df916 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java @@ -33,13 +33,13 @@ import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.InstanceExists; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; /** * Integration tests the methods of {@link MongoInstall}. */ -public class MongoInstallIT extends MongoTestBase { +public class MongoInstallIT extends MongoITBase { @Test public void install() throws DuplicateInstanceNameException, RyaClientException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java index a2e8e25..c27df2c 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.apache.accumulo.core.client.TableExistsException; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository; import org.junit.Test; @@ -32,7 +32,7 @@ import com.mongodb.MongoException; /** * Integration tests the methods of {@link MongoInstanceExistsExists}. */ -public class MongoInstanceExistsIT extends MongoTestBase { +public class MongoInstanceExistsIT extends MongoITBase { @Test public void exists_ryaDetailsTable() throws MongoException, TableExistsException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java index c66670e..6a5b1d6 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java @@ -30,7 +30,7 @@ import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.ListInstances; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import com.google.common.collect.Lists; @@ -39,7 +39,7 @@ import com.mongodb.MongoException; /** * Integration tests the methods of {@link MongoListInstances}. */ -public class MongoListInstancesIT extends MongoTestBase { +public class MongoListInstancesIT extends MongoITBase { @Test public void listInstances_hasRyaDetailsTable() throws MongoException, DuplicateInstanceNameException, RyaClientException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java index 674a806..2ecaec0 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java @@ -28,7 +28,7 @@ import org.apache.rya.api.client.Install; import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.InstanceDoesNotExistException; import org.apache.rya.api.client.RyaClient; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.bson.Document; import org.junit.Test; import org.openrdf.model.Statement; @@ -40,7 +40,7 @@ import com.mongodb.client.MongoCursor; /** * Integration tests the methods of {@link MongoLoadStatementsFile}. */ -public class MongoLoadStatementsFileIT extends MongoTestBase { +public class MongoLoadStatementsFileIT extends MongoITBase { @Test(expected = InstanceDoesNotExistException.class) public void instanceDoesNotExist() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsIT.java index b0d0e5b..57e4b76 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsIT.java @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.InstanceDoesNotExistException; import org.apache.rya.api.client.RyaClient; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.bson.Document; import org.junit.Test; import org.openrdf.model.Statement; @@ -38,7 +38,7 @@ import com.mongodb.client.MongoCursor; /** * Integration tests the methods of {@link MongoLoadStatements}. */ -public class MongoLoadStatementsIT extends MongoTestBase { +public class MongoLoadStatementsIT extends MongoITBase { private static final ValueFactory VF = new ValueFactoryImpl(); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java index 6c9d4fd..d9d1a6d 100644 --- a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java @@ -30,7 +30,7 @@ import org.apache.rya.api.client.InstanceExists; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; import org.apache.rya.api.client.Uninstall; -import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.MongoITBase; import org.junit.Test; import com.mongodb.MongoException; @@ -38,7 +38,7 @@ import com.mongodb.MongoException; /** * Integration tests the methods of {@link MongoUninstall}. */ -public class MongoUninstallIT extends MongoTestBase { +public class MongoUninstallIT extends MongoITBase { @Test public void uninstall() throws MongoException, RyaClientException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/pom.xml ---------------------------------------------------------------------- diff --git a/extras/shell/pom.xml b/extras/shell/pom.xml index a2aedbc..1a07400 100644 --- a/extras/shell/pom.xml +++ b/extras/shell/pom.xml @@ -99,6 +99,12 @@ <type>test-jar</type> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.rya</groupId> + <artifactId>mongodb.rya</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/main/java/org/apache/rya/shell/RyaConnectionCommands.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/main/java/org/apache/rya/shell/RyaConnectionCommands.java b/extras/shell/src/main/java/org/apache/rya/shell/RyaConnectionCommands.java index c6bdbb3..d5b7117 100644 --- a/extras/shell/src/main/java/org/apache/rya/shell/RyaConnectionCommands.java +++ b/extras/shell/src/main/java/org/apache/rya/shell/RyaConnectionCommands.java @@ -88,11 +88,11 @@ public class RyaConnectionCommands implements CommandMarker { @CliAvailabilityIndicator({CONNECT_INSTANCE_CMD}) public boolean isConnectToInstanceAvailable() { switch(sharedState.getShellState().getConnectionState()) { - case CONNECTED_TO_STORAGE: - case CONNECTED_TO_INSTANCE: - return true; - default: - return false; + case CONNECTED_TO_STORAGE: + case CONNECTED_TO_INSTANCE: + return true; + default: + return false; } } @@ -122,12 +122,12 @@ public class RyaConnectionCommands implements CommandMarker { final MongoConnectionDetails mongoDetails = sharedState.getShellState().getMongoDetails().get(); final StringBuilder message = new StringBuilder() - .append("The shell is connected to an instance of MongoDB using the following parameters:\\n") + .append("The shell is connected to an instance of MongoDB using the following parameters:\n") .append(" Hostname: " + mongoDetails.getHostname() + "\n") .append(" Port: " + mongoDetails.getPort() + "\n"); if(mongoDetails.getUsername().isPresent()) { - message.append(" Username:" + mongoDetails.getUsername().get()); + message.append(" Username: " + mongoDetails.getUsername().get() + "\n"); } return message.toString(); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/AccumuloRyaConnectionCommandsIT.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/AccumuloRyaConnectionCommandsIT.java b/extras/shell/src/test/java/org/apache/rya/shell/AccumuloRyaConnectionCommandsIT.java new file mode 100644 index 0000000..98fb64c --- /dev/null +++ b/extras/shell/src/test/java/org/apache/rya/shell/AccumuloRyaConnectionCommandsIT.java @@ -0,0 +1,226 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.shell; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.shell.SharedShellState.ConnectionState; +import org.apache.rya.shell.SharedShellState.ShellState; +import org.apache.rya.shell.util.InstallPrompt; +import org.apache.rya.shell.util.PasswordPrompt; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.CommandResult; +import org.springframework.shell.core.JLineShellComponent; + +/** + * Integration tests the methods of {@link RyaConnectionCommands}. + */ +public class AccumuloRyaConnectionCommandsIT extends RyaShellAccumuloITBase { + + @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() ); + } + + @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() ); + } + + @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); + } + + @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); + } + + @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()); + } + + @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() ); + } + + @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() ); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/MongoRyaShellIT.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/MongoRyaShellIT.java b/extras/shell/src/test/java/org/apache/rya/shell/MongoRyaShellIT.java new file mode 100644 index 0000000..79fe95d --- /dev/null +++ b/extras/shell/src/test/java/org/apache/rya/shell/MongoRyaShellIT.java @@ -0,0 +1,194 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.shell; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.shell.SharedShellState.ConnectionState; +import org.apache.rya.shell.SharedShellState.ShellState; +import org.apache.rya.shell.util.InstallPrompt; +import org.apache.rya.shell.util.PasswordPrompt; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.CommandResult; +import org.springframework.shell.core.JLineShellComponent; + +/** + * Integration tests the functions of the Mongo Rya Shell. + */ +public class MongoRyaShellIT extends RyaShellMongoITBase { + + @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.conf.getMongoHostname() + " " + + "--port " + super.conf.getMongoPort(); + + final CommandResult connectResult = shell.executeCommand(cmd); + + // Ensure the connection was successful. + assertTrue(connectResult.isSuccess()); + } + + @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); + } + + @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.conf.getMongoHostname() + " " + + "--port " + super.conf.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.conf.getMongoHostname() + "\n" + + " Port: " + super.conf.getMongoPort() + "\n"; + assertEquals(expected, msg); + } + + @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.conf.getMongoHostname() + " " + + "--port " + super.conf.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.conf.getMongoHostname() + "\n" + + " Port: " + super.conf.getMongoPort() + "\n" + + " Username: bob\n"; + assertEquals(expected, msg); + } + + @Test + public void connectToInstance_instanceDoesNotExist() throws IOException { + final JLineShellComponent shell = getTestShell(); + + // Connect to the Mongo instance. + String cmd = + RyaConnectionCommands.CONNECT_MONGO_CMD + " " + + "--hostname " + super.conf.getMongoHostname() + " " + + "--port " + super.conf.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() ); + } + + @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.conf.getMongoHostname() + " " + + "--port " + super.conf.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()); + } + + @Test + public void disconnect() throws IOException { + final JLineShellComponent shell = getTestShell(); + + // Connect to the Mongo instance. + final String cmd = + RyaConnectionCommands.CONNECT_MONGO_CMD + " " + + "--hostname " + super.conf.getMongoHostname() + " " + + "--port " + super.conf.getMongoPort(); + shell.executeCommand(cmd); + + // Disconnect from it. + final CommandResult disconnectResult = shell.executeCommand( RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD ); + assertTrue( disconnectResult.isSuccess() ); + } + + // TODO the rest of them? +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java deleted file mode 100644 index 45bfced..0000000 --- a/extras/shell/src/test/java/org/apache/rya/shell/RyaConnectionCommandsIT.java +++ /dev/null @@ -1,297 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.shell; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -import java.io.IOException; - -import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.rya.api.client.Install.InstallConfiguration; -import org.apache.rya.shell.SharedShellState.ConnectionState; -import org.apache.rya.shell.SharedShellState.ShellState; -import org.apache.rya.shell.util.InstallPrompt; -import org.apache.rya.shell.util.PasswordPrompt; -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.shell.Bootstrap; -import org.springframework.shell.core.CommandResult; -import org.springframework.shell.core.JLineShellComponent; - -/** - * Integration tests the methods of {@link RyaConnectionCommands}. - */ -public class RyaConnectionCommandsIT extends RyaShellITBase { - - @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() ); - } - - @Test - public void connectMongo() throws IOException { - // FIXME create mongo client/server here - 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_MONGO_CMD + " " + - "--username root " + - "--hostname " + "localhost" + " " + - "--port " + "999"; - - final CommandResult connectResult = shell.executeCommand(cmd); - - // Ensure the connection was successful. - assertTrue(connectResult.isSuccess()); - } - - @Test - public void connectAccumulo_noAuths() 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 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() ); - } - - @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() ); - } - - @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); - } - - @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); - } - - @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()); - } - - @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() ); - } - - @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() ); - } - - @Test - public void connectMongo_noAuths() throws IOException { - // FIXME make Mongo connection here - 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 command - final String cmd = RyaConnectionCommands.CONNECT_MONGO_CMD + " " + - "--username root " + - "--hostname " + "localhost" + " " + - "--port " + "999"; // FIXME - - final CommandResult connectResult = shell.executeCommand(cmd); - - // Ensure the connection was successful. - assertTrue( connectResult.isSuccess() ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/RyaShellAccumuloITBase.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaShellAccumuloITBase.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaShellAccumuloITBase.java new file mode 100644 index 0000000..a115639 --- /dev/null +++ b/extras/shell/src/test/java/org/apache/rya/shell/RyaShellAccumuloITBase.java @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.shell; + +import java.io.IOException; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.rya.accumulo.MiniAccumuloSingleton; +import org.apache.rya.accumulo.RyaTestInstanceRule; +import org.apache.zookeeper.ClientCnxn; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.JLineShellComponent; + +import org.apache.rya.accumulo.MiniAccumuloClusterInstance; + +/** + * All Rya Shell integration tests should extend this one. It provides startup + * and shutdown hooks for a Mini Accumulo Cluster when you start and stop testing. + * It also creates a new shell to test with between each test. + */ +public class RyaShellAccumuloITBase { + + /** + * The bootstrap that was used to initialize the Shell that will be tested. + */ + private Bootstrap bootstrap; + + /** + * The shell that will be tested. + */ + private JLineShellComponent shell; + + @Rule + public RyaTestInstanceRule testInstance = new RyaTestInstanceRule(false); + + @BeforeClass + public static void killLoudLogs() { + Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR); + } + + @Before + public void startShell() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException { + // Bootstrap the shell with the test bean configuration. + bootstrap = new Bootstrap(new String[]{}, new String[]{"file:src/test/resources/RyaShellTest-context.xml"}); + shell = bootstrap.getJLineShellComponent(); + } + + @After + public void stopShell() throws IOException, InterruptedException { + shell.stop(); + } + + /** + * @return The bootstrap that was used to initialize the Shell that will be tested. + */ + public Bootstrap getTestBootstrap() { + return bootstrap; + } + + /** + * @return The shell that will be tested. + */ + public JLineShellComponent getTestShell() { + return shell; + } + + /** + * @return The cluster that is hosting the test. + */ + public MiniAccumuloCluster getCluster() { + return MiniAccumuloSingleton.getInstance().getCluster(); + } + + public String getInstanceName() { + return testInstance.getRyaInstanceName(); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/RyaShellITBase.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaShellITBase.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaShellITBase.java deleted file mode 100644 index bcbaa5b..0000000 --- a/extras/shell/src/test/java/org/apache/rya/shell/RyaShellITBase.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.rya.shell; - -import java.io.IOException; - -import org.apache.accumulo.core.client.AccumuloException; -import org.apache.accumulo.core.client.AccumuloSecurityException; -import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.rya.accumulo.MiniAccumuloSingleton; -import org.apache.rya.accumulo.RyaTestInstanceRule; -import org.apache.zookeeper.ClientCnxn; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.springframework.shell.Bootstrap; -import org.springframework.shell.core.JLineShellComponent; - -import org.apache.rya.accumulo.MiniAccumuloClusterInstance; - -/** - * All Rya Shell integration tests should extend this one. It provides startup - * and shutdown hooks for a Mini Accumulo Cluster when you start and stop testing. - * It also creates a new shell to test with between each test. - */ -public class RyaShellITBase { - - /** - * The bootstrap that was used to initialize the Shell that will be tested. - */ - private Bootstrap bootstrap; - - /** - * The shell that will be tested. - */ - private JLineShellComponent shell; - - @Rule - public RyaTestInstanceRule testInstance = new RyaTestInstanceRule(false); - - @BeforeClass - public static void killLoudLogs() { - Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR); - } - - @Before - public void startShell() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException { - // Bootstrap the shell with the test bean configuration. - bootstrap = new Bootstrap(new String[]{}, new String[]{"file:src/test/resources/RyaShellTest-context.xml"}); - shell = bootstrap.getJLineShellComponent(); - } - - @After - public void stopShell() throws IOException, InterruptedException { - shell.stop(); - } - - /** - * @return The bootstrap that was used to initialize the Shell that will be tested. - */ - public Bootstrap getTestBootstrap() { - return bootstrap; - } - - /** - * @return The shell that will be tested. - */ - public JLineShellComponent getTestShell() { - return shell; - } - - /** - * @return The cluster that is hosting the test. - */ - public MiniAccumuloCluster getCluster() { - return MiniAccumuloSingleton.getInstance().getCluster(); - } - - public String getInstanceName() { - return testInstance.getRyaInstanceName(); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/00800b68/extras/shell/src/test/java/org/apache/rya/shell/RyaShellMongoITBase.java ---------------------------------------------------------------------- diff --git a/extras/shell/src/test/java/org/apache/rya/shell/RyaShellMongoITBase.java b/extras/shell/src/test/java/org/apache/rya/shell/RyaShellMongoITBase.java new file mode 100644 index 0000000..7e83dbf --- /dev/null +++ b/extras/shell/src/test/java/org/apache/rya/shell/RyaShellMongoITBase.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.shell; + +import java.io.IOException; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.rya.mongodb.MongoITBase; +import org.junit.After; +import org.junit.Before; +import org.springframework.shell.Bootstrap; +import org.springframework.shell.core.JLineShellComponent; + +/** + * All Rya Shell integration tests should extend this one if they are testing against Mongo DB. + */ +public class RyaShellMongoITBase extends MongoITBase { + + /** + * The bootstrap that was used to initialize the Shell that will be tested. + */ + private Bootstrap bootstrap; + + /** + * The shell that will be tested. + */ + private JLineShellComponent shell; + + @Before + public void startShell() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException { + // Bootstrap the shell with the test bean configuration. + bootstrap = new Bootstrap(new String[]{}, new String[]{"file:src/test/resources/RyaShellTest-context.xml"}); + shell = bootstrap.getJLineShellComponent(); + } + + @After + public void stopShell() throws IOException, InterruptedException { + shell.stop(); + } + + /** + * @return The bootstrap that was used to initialize the Shell that will be tested. + */ + public Bootstrap getTestBootstrap() { + return bootstrap; + } + + /** + * @return The shell that will be tested. + */ + public JLineShellComponent getTestShell() { + return shell; + } +} \ No newline at end of file