Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add rspec tests

  • Loading branch information...
commit e5e6e5a9ac6cc2732b5a8a190c00934d76853278 1 parent 3c7fb2e
mguymon authored
2  .gitignore
View
@@ -1,3 +1,5 @@
+tmp
+
# rcov generated
coverage
coverage.data
3  Gemfile
View
@@ -4,7 +4,8 @@ gem "lock_jar", "~> 0.5.2"
gem "thor", "> 0.14.0"
group :development do
- gem "rspec", "~> 2.11.0"
+ gem 'rsolr', "~> 1.0.0"
+ gem "rspec", "~> 2.11.0"
gem "bundler", "~> 1.1.4"
gem "jeweler", "~> 1.8.4"
end
4 Gemfile.lock
View
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ builder (3.0.0)
diff-lcs (1.1.3)
git (1.2.5)
jeweler (1.8.4)
@@ -16,6 +17,8 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rsolr (1.0.8)
+ builder (>= 2.1.2)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
@@ -33,5 +36,6 @@ DEPENDENCIES
bundler (~> 1.1.4)
jeweler (~> 1.8.4)
lock_jar (~> 0.5.2)
+ rsolr (~> 1.0.0)
rspec (~> 2.11.0)
thor (> 0.14.0)
18 src/main/java/com/tobedevoured/solrsail/JettyServer.java
View
@@ -28,6 +28,7 @@
private String solrHome;
private String contextPath;
private int port;
+ private Server server;
/**
* Create new instance
@@ -45,14 +46,18 @@ public JettyServer() {
* @throws Exception
*/
@Command
- public void start() throws Exception {
+ public void start() throws Exception {
+ start(true);
+ }
+
+ public void start(boolean join) throws Exception {
System.setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");
System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");
System.setProperty("org.apache.jasper.compiler.disablejsr199", "true" );
- Server server = new Server(getPort());
+ server = new Server(getPort());
String webDir = JettyServer.class.getClassLoader().getResource("webapp").toExternalForm();
@@ -70,7 +75,14 @@ public void start() throws Exception {
logger.info( "starting Jetty" );
server.start();
- server.join();
+
+ if ( join ) {
+ server.join();
+ }
+ }
+
+ public void stop() throws Exception {
+ server.stop();
}
public String getContextPath() {
30 src/main/ruby/solr_sail.rb
View
@@ -2,26 +2,16 @@
require 'lock_jar'
require 'java'
+require 'solr_sail/version'
+
module SolrSail
- @@version = IO.read("VERSION").strip
- @@jar = File.expand_path("#{File.dirname(__FILE__)}/../solr_sail-#{@@version}.jar")
- @@lockfile = File.expand_path("#{File.dirname(__FILE__)}/../Jarfile.lock")
-
- def self.version
- @@version
- end
- # Find lockjar relative to the gem install
- def self.default_lockfile
- @@lockfile
- end
-
- def self.default_jar
- @@jar
- end
+ DEFAULT_JAR_NAME = "solr_sail-#{SolrSail::VERSION}.jar"
+ DEFAULT_JAR = File.expand_path("#{File.dirname(__FILE__)}/../#{DEFAULT_JAR_NAME}")
+ DEFAULT_LOCKFILE = File.expand_path("#{File.dirname(__FILE__)}/../Jarfile.lock")
def self.install_config( opts )
- opts = { :jar => default_jar, :lockfile => default_lockfile }.merge( opts )
+ opts = { :jar => DEFAULT_JAR, :lockfile => DEFAULT_LOCKFILE }.merge( opts )
lockfile = opts.delete(:lockfile)
jar = opts.delete(:jar)
@@ -36,7 +26,7 @@ def self.install_config( opts )
end
def self.start( opts )
- opts = { :jar => default_jar, :lockfile => default_lockfile }.merge( opts )
+ opts = { :jar => DEFAULT_JAR, :lockfile => DEFAULT_LOCKFILE, :join => true }.merge( opts )
lockfile = opts.delete(:lockfile)
jar = opts.delete(:jar)
@@ -45,7 +35,9 @@ def self.start( opts )
LockJar.load( lockfile, opts )
- jetty = com.tobedevoured.solrsail.JettyServer.new
- jetty.start
+ jetty = com.tobedevoured.solrsail.JettyServer.new()
+ jetty.start(opts[:join])
+
+ jetty
end
end
5 src/main/ruby/solr_sail/cli.rb
View
@@ -15,5 +15,10 @@ def install
def start
SolrSail.start( :dest => options[:dest] )
end
+
+ desc "version", "Version"
+ def version
+ puts SolrSail::VERSION
+ end
end
end
3  src/main/ruby/solr_sail/version.rb
View
@@ -0,0 +1,3 @@
+module SolrSail
+ VERSION = IO.read("VERSION").strip
+end
56 src/test/spec/solr_sail_spec.rb
View
@@ -0,0 +1,56 @@
+require 'rubygems'
+require 'rsolr'
+require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
+require 'src/main/ruby/solr_sail'
+require 'src/main/ruby/solr_sail/version'
+require 'fileutils'
+
+describe SolrSail do
+ describe "Module" do
+ it "should have a DEFAULT_LOCKJAR" do
+ SolrSail::DEFAULT_LOCKFILE.should eql File.expand_path( "src/main/Jarfile.lock" )
+ end
+
+ it "should have a DEFAULT JAR NAME" do
+ SolrSail::DEFAULT_JAR_NAME.should eql "solr_sail-#{SolrSail::VERSION}.jar"
+ end
+
+ it "should have a DEFAULT_JAR" do
+ SolrSail::DEFAULT_JAR.should eql File.expand_path( "src/main/#{SolrSail::DEFAULT_JAR_NAME}" )
+ end
+
+ it "should install config" do
+ if File.exists? 'tmp/solr'
+ FileUtils.rm_rf( 'tmp/solr' )
+ end
+
+ SolrSail.install_config( :dest => 'tmp/solr', :lockfile => 'Jarfile.lock', :jar => "target/#{SolrSail::DEFAULT_JAR_NAME}" )
+
+ File.exists?( 'tmp/solr/solr.xml').should be_true
+ File.exists?( 'tmp/solr/conf').should be_true
+ end
+
+ context "start" do
+ before(:all) do
+ @server = SolrSail.start( :join => false, :dest => 'tmp/solr', :lockfile => 'Jarfile.lock', :jar => "target/#{SolrSail::DEFAULT_JAR_NAME}" )
+ @solr = RSolr.connect( :url => 'http://localhost:8080/solr' )
+ end
+
+ after(:all) do
+ @server.stop()
+ end
+
+ it "should be able to connect" do
+ @solr = RSolr.connect :url => 'http://localhost:8080/solr'
+ end
+
+ it "should be able to add and query a document" do
+ @solr.add :id=>1, :price=>1.00
+
+ result = @solr.get('select', :params => {:q=>'id:1'})
+ result["response"]["docs"].should eql [{"id"=>"1", "price"=>1.0, "price_c"=>"1.0,USD"}]
+ end
+
+ end
+ end
+end
22 src/test/spec/spec_helper.rb
View
@@ -0,0 +1,22 @@
+$:.unshift File.expand_path('.')
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '../../../'))
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '../../../src/main/ruby'))
+
+
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = 'random'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.