Permalink
Browse files

(Hopefully) final version for release 2.0.

  • Loading branch information...
1 parent 29b7e13 commit 92542d156859797f034306ecf43ee9bf413e110b @ThomasJaspers committed Feb 20, 2012
View
@@ -96,14 +96,16 @@
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <archive>
- <manifest>
- <mainClass>org/robot/database/server/RemoteServer</mainClass>
- </manifest>
- </archive>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ <archive>
+ <manifest>
+ <mainClass>org/robot/database/server/RemoteServer</mainClass>
+ </manifest>
+ </archive>
+ <finalName>dblibrary-2.0-server</finalName>
+ <appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
Oops, something went wrong.
@@ -4,104 +4,59 @@
import java.util.Date;
import redstone.xmlrpc.simple.*;
-
public class RemoteServer {
-
- public static String className;
- public static boolean enableStopServer;
- private static Server server;
-
-
- /**
- * Remote Server main/startup method.
- * Takes input from command line for Java class library (name)
- * to load and invoke with reflection and the port to bind
- * the remote server to. Defaults to port 8270 if not supplied.
- * @param args
- *
- */
- public static void main(String[] args){// throws Exception {
- if(args.length == 0) {
- displayUsage();
- }
-
- //set defaults
- int port = 8270;
- className = "org.robotframework.remotelibrary.ExampleRemoteLibrary";
- enableStopServer = true;
-
- //parse arguments
- for(int i = 0; i < args.length; i++){
- if(args[i].equalsIgnoreCase("--port")) {
- port = Integer.parseInt(args[i+1]);
- }
- }
-
- //codebase below based on the Redstone XML-RPC with
- //Simple HTTP Server integration code example(s)
- try
- {
- server = new Server(port);
- server.getXmlRpcServer().addInvocationHandler(null, new RemoteServerMethods());
- server.start();
-
- SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm");
- Date date = new Date();
- System.out.println("");
- System.out.println("Database Library remote server started on port " + port + " at " + bartDateFormat.format(date));
- }
- catch ( Exception e )
- {
- System.out.println(
- "An exception occured when starting the server. The full stacktrace " +
- "is displayed below. Check your arguments to verify that the server port " +
- "is available and that the service classes you supplied are in the classpath " +
- "and can be instantiated.\n\n" +
- "Stacktrace:\n\n" );
- e.printStackTrace();
- }
- }
-
-
- private static void displayUsage() {
- System.out.println("");
- System.out.println("robotremoteserver - v1.0");
- System.out.println("");
- System.out.println("Usage Info:");
- System.out.println("");
- System.out.println(" java -cp xmlrpc-1.1.1.jar:simple-4.0.1.jar:simple-xmlrpc-1.0.jar org.robotframework.remotelibrary.RemoteServer --library RemoteLibraryClassName-FullyQualifiedPath [options]");
- System.out.println("");
- System.out.println(" or if everything packaged into a JAR...");
- System.out.println("");
- System.out.println(" java -jar jrobotremoteserver-1.0.jar --library RemoteLibraryClassName-FullyQualifiedPath [options]");
- System.out.println("");
- System.out.println(" Class name = keyword class w/ methods to execute, fully qualified path");
- System.out.println(" including package name, as needed. Assumes class library (class/JAR");
- System.out.println(" file) is in class path for loading & invocation. As shown, server");
- System.out.println(" requires Redstone XML-RPC w/ Simple HTTP Server (JAR) libraries.");
- //comment out doc file info, until/unless we implement where some Javadoc file is required
- //System.out.println(" Documentation file = Java documentation file for the");
- //System.out.println(" class library.");
- System.out.println("");
- //commented out info about hostname/IP until we implement that, if ever
- //System.out.println(" Optionally specify IP address to bind remote server to.");
- //System.out.println(" Default of 127.0.0.1 (localhost).");
- System.out.println("Optional options:");
- System.out.println("");
- System.out.println(" --port value\tPort to bind remote server to. Default of 8270.");
- System.out.println("");
- System.out.println(" --nostopsvr\tDisable remotely stopping the server via stop_remote_server");
- System.out.println(" \tkeyword. Default is to enable.");
- System.out.println("");
- System.out.println("Example:");
- System.out.println("");
- System.out.println(" java -cp xmlrpc-1.1.1.jar:simple-4.0.1.jar:simple-xmlrpc-1.0.jar org.robotframework.remotelibrary.RemoteServer --library org.robotframework.remotelibrary.MyClassName --port 81 --nostopsvr");
- System.out.println("");
- System.out.println(" or if everything packaged into a JAR...");
- System.out.println("");
- System.out.println(" java -jar jrobotremoteserver-1.0.jar --library org.robotframework.remotelibrary.MyClassName --port 81 --nostopsvr");
- System.out.println("");
- System.exit(0);
- }
- }
+ public static final int DEFAULT_PORT = 8270;
+
+ public static final String MESSAGE = "Database Library v2.0 remote server started";
+
+ private static Server server;
+
+ /**
+ * Remote Server main/startup method. Takes input from command line for Java
+ * class library (name) to load and invoke with reflection and the port to
+ * bind the remote server to. Defaults to port 8270 if not supplied.
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+
+ // Setting port and
+ int port = DEFAULT_PORT;
+
+ // Parse command line arguments
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equalsIgnoreCase("--port") || args[i].equalsIgnoreCase("-p")) {
+ port = Integer.parseInt(args[i + 1]);
+ }
+ if (args[i].equalsIgnoreCase("--help") || args[i].equalsIgnoreCase("-h")) {
+ displayUsage();
+ System.exit(0);
+ }
+ }
+
+ // The actual XML-RPC stuff
+ try {
+ server = new Server(port);
+ server.getXmlRpcServer().addInvocationHandler(null, new RemoteServerMethods());
+ server.start();
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm");
+ System.out.println(MESSAGE + " on port " + port + " at " + dateFormat.format(new Date()));
+ } catch (Exception e) {
+ System.out.println("An exception occured when starting the server.\n\n"
+ + "Stacktrace:\n\n");
+ e.printStackTrace();
+ }
+ }
+
+ private static void displayUsage() {
+ System.out.println("\n" + MESSAGE + "\n");
+ System.out.println("Usage Info:\n");
+ System.out.println("Ensure that the dblibrary-2.0-server.jar JAR and your JDBC driver JAR is in the classpath, e.g.:\n");
+ System.out.println("set CLASSPATH=%CLASSPATH%;./dblibrary-2.0-server.jar;./mysql-connector-java-5.1.6.jar\n\n");
+ System.out.println("The start the server as follows:\n");
+ System.out.println("java org.robot.database.server.RemoteServer --port <port> --help");
+ System.out.println("");
+ }
+}
@@ -8,7 +8,11 @@
public class RemoteServerMethods {
- private static final String[] SUPPORTED_METHODS = new String[]{"connect_to_database",
+ /**
+ * Define available methods.
+ */
+ private static final String[] SUPPORTED_METHODS = new String[]{
+ "connect_to_database",
"disconnect_from_database",
"table_must_exist",
"table_must_be_empty",
@@ -24,19 +28,31 @@
"get_transaction_isolation_level",
"check_primary_key_columns_for_table",
"get_primary_key_columns_for_table",
- "execute_sql", "execute_sql_from_file",
+ "execute_sql",
+ "execute_sql_from_file",
"execute_sql_from_file_ignore_errors",
"verify_number_of_rows_matching_where",
- "row_should_not_exist_in_table",
- "test_remote_lib"};
+ "row_should_not_exist_in_table",
+ "store_query_result_to_file",
+ "compare_query_result_to_file"};
private DatabaseLibrary dbLibrary = new DatabaseLibrary();
+ /**
+ * Returns the list of supported keywords.
+ * @return Array containing keywords.
+ */
public String[] get_keyword_names(){
return SUPPORTED_METHODS;
}
-
+
+ /**
+ * Executed the given keyword and returns the result.
+ * @param keyword Name of the keyword.
+ * @param args Arguments-Array
+ * @return Result-Map
+ */
public Map<String, String> run_keyword(String keyword, List<String> args) {
Map<String, String> returnRPC = new HashMap<String, String>();
@@ -46,49 +62,51 @@
String returnObject = "";
if (keyword.equals("connect_to_database")) {
- dbLibrary.connect_to_database(args.get(0), args.get(1), args.get(2), args.get(3));
+ dbLibrary.connectToDatabase(args.get(0), args.get(1), args.get(2), args.get(3));
} else if (keyword.equals("disconnect_from_database")) {
- dbLibrary.disconnect_from_database();
+ dbLibrary.disconnectFromDatabase();
} else if (keyword.equals("table_must_exist")) {
- dbLibrary.table_must_exist(args.get(0));
+ dbLibrary.tableMustExist(args.get(0));
} else if (keyword.equals("table_must_be_empty")) {
- dbLibrary.table_must_be_empty(args.get(0));
+ dbLibrary.tableMustBeEmpty(args.get(0));
} else if (keyword.equals("delete_all_rows_from_table")) {
- dbLibrary.delete_all_rows_from_table(args.get(0));
+ dbLibrary.deleteAllRowsFromTable(args.get(0));
} else if (keyword.equals("table_must_contain_number_of_rows")) {
- dbLibrary.table_must_contain_number_of_rows(args.get(0), args.get(1));
+ dbLibrary.tableMustContainNumberOfRows(args.get(0), args.get(1));
} else if (keyword.equals("table_must_contain_more_than_number_of_rows")) {
- dbLibrary.table_must_contain_more_than_number_of_rows(args.get(0), args.get(1));
+ dbLibrary.tableMustContainMoreThanNumberOfRows(args.get(0), args.get(1));
} else if (keyword.equals("table_must_contain_less_than_number_of_rows")) {
- dbLibrary.table_must_contain_less_than_number_of_rows(args.get(0), args.get(1));
+ dbLibrary.tableMustContainLessThanNumberOfRows(args.get(0), args.get(1));
} else if (keyword.equals("tables_must_contain_same_amount_of_rows")) {
- dbLibrary.tables_must_contain_same_amount_of_rows(args.get(0), args.get(1));
+ dbLibrary.tablesMustContainSameAmountOfRows(args.get(0), args.get(1));
} else if (keyword.equals("check_content_for_row_identified_by_rownum")) {
- dbLibrary.check_content_for_row_identified_by_rownum(args.get(0), args.get(1), args.get(2), args.get(3));
+ dbLibrary.checkContentForRowIdentifiedByRownum(args.get(0), args.get(1), args.get(2), args.get(3));
} else if (keyword.equals("check_content_for_row_identified_by_where_clause")) {
- dbLibrary.check_content_for_row_identified_by_where_clause(args.get(0), args.get(1), args.get(2), args.get(3));
+ dbLibrary.checkContentForRowIdentifiedByWhereClause(args.get(0), args.get(1), args.get(2), args.get(3));
} else if (keyword.equals("read_single_value_from_table")) {
- dbLibrary.read_single_value_from_table(args.get(0), args.get(1), args.get(2));
+ returnObject = dbLibrary.readSingleValueFromTable(args.get(0), args.get(1), args.get(2));
} else if (keyword.equals("transaction_isolation_level_must_be")) {
- dbLibrary.transaction_isolation_level_must_be(args.get(0));
+ dbLibrary.transactionIsolationLevelMustBe(args.get(0));
} else if (keyword.equals("get_transaction_isolation_level")) {
- dbLibrary.get_transaction_isolation_level();
+ returnObject = dbLibrary.getTransactionIsolationLevel();
} else if (keyword.equals("check_primary_key_columns_for_table")) {
- dbLibrary.check_primary_key_columns_for_table(args.get(0), args.get(1));
+ dbLibrary.checkPrimaryKeyColumnsForTable(args.get(0), args.get(1));
} else if (keyword.equals("get_primary_key_columns_for_table")) {
- dbLibrary.get_primary_key_columns_for_table(args.get(0));
+ returnObject = dbLibrary.getPrimaryKeyColumnsForTable(args.get(0));
} else if (keyword.equals("execute_sql")) {
- dbLibrary.execute_sql(args.get(0));
+ dbLibrary.executeSql(args.get(0));
} else if (keyword.equals("execute_sql_from_file")) {
- dbLibrary.execute_sql_from_file(args.get(0));
+ dbLibrary.executeSqlFromFile(args.get(0));
} else if (keyword.equals("execute_sql_from_file_ignore_errors")) {
- dbLibrary.execute_sql_from_file_ignore_errors(args.get(0));
+ dbLibrary.executeSqlFromFileIgnoreErrors(args.get(0));
} else if (keyword.equals("verify_number_of_rows_matching_where")) {
- dbLibrary.verify_number_of_rows_matching_where(args.get(0), args.get(1), args.get(2));
+ dbLibrary.verifyNumberOfRowsMatchingWhere(args.get(0), args.get(1), args.get(2));
} else if (keyword.equals("row_should_not_exist_in_table")) {
- dbLibrary.row_should_not_exist_in_table(args.get(0), args.get(1));
- } else if (keyword.equals("test_remote_lib")) {
- dbLibrary.test_remote_lib(args.get(0));
+ dbLibrary.rowShouldNotExistInTable(args.get(0), args.get(1));
+ } else if (keyword.equals("store_query_result_to_file")) {
+ dbLibrary.storeQueryResultToFile(args.get(0), args.get(1));
+ } else if (keyword.equals("compare_query_result_to_file")) {
+ dbLibrary.compareQueryResultToFile(args.get(0), args.get(1));
} else {
throw new RemoteAccessException("The keyword " + keyword + "does not exist in the Database Library Remote Server.");
}
@@ -117,7 +135,12 @@
return returnRPC;
}
-
+
+ /**
+ * Returns the arguments required by the given keyword.
+ * @param keyword Keyword
+ * @return Argument-Array
+ */
public String[] get_keyword_arguments(String keyword){
String[] argumentList;
@@ -164,16 +187,28 @@
argumentList = new String[]{"tableName", "where", "rowNumValue"};
} else if (keyword.equals("row_should_not_exist_in_table")) {
argumentList = new String[]{"tableName", "whereClause"};
- } else if (keyword.equals("test_remote_lib")) {
- argumentList = new String[]{"value"};
+ } else if (keyword.equals("store_query_result_to_file")) {
+ argumentList = new String[]{"sqlString", "fileName"};
+ } else if (keyword.equals("compare_query_result_to_file")) {
+ argumentList = new String[]{"sqlString", "fileName"};
} else {
argumentList = new String[]{};
}
return argumentList;
}
+ /**
+ * Returns the documentation for the given keyword.
+ * @param keyword Keyword
+ * @return Documentation
+ */
public String get_keyword_documentation(String keyword){
- return "empty";
+
+ if (DatabaseLibrary.documentation.containsValue(keyword)) {
+ return DatabaseLibrary.documentation.get(keyword);
+ } else {
+ return "Sorry, no documentation available.";
+ }
}
}
@@ -33,14 +33,14 @@ public void setUpTest() throws Exception {
@Test
public void checkConnectToDatabase() throws Exception {
- databaseLibrary.connect_to_database(HSQL_DRIVER_CLASSNAME,
+ databaseLibrary.connectToDatabase(HSQL_DRIVER_CLASSNAME,
HSQL_URL, HSQL_USER, HSQL_PASSWORD);
}
@Test
public void checkConnectToDatabaseWithWrongUsername() {
try {
- databaseLibrary.connect_to_database(HSQL_DRIVER_CLASSNAME,
+ databaseLibrary.connectToDatabase(HSQL_DRIVER_CLASSNAME,
HSQL_URL, "xyz", HSQL_PASSWORD);
} catch (SQLException e) {
if (!e.getMessage().contains("not found")) {
@@ -55,14 +55,14 @@ public void checkConnectToDatabaseWithWrongUsername() {
@Test
public void checkDisconnectFromDatabase() throws Exception {
- databaseLibrary.connect_to_database(HSQL_DRIVER_CLASSNAME,
+ databaseLibrary.connectToDatabase(HSQL_DRIVER_CLASSNAME,
HSQL_URL, HSQL_USER, HSQL_PASSWORD);
- databaseLibrary.disconnect_from_database();
+ databaseLibrary.disconnectFromDatabase();
}
@Test(expected=IllegalStateException.class)
public void checkIllegalStateExceptionWithoutConnect() throws Exception {
- databaseLibrary.table_must_be_empty("NoConnection");
+ databaseLibrary.tableMustBeEmpty("NoConnection");
}
}
Oops, something went wrong.

0 comments on commit 92542d1

Please sign in to comment.