require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Trinidad::Extensions::SandboxServerExtension do subject { Trinidad::Extensions::SandboxServerExtension.new({}) } before(:each) do @tomcat = Trinidad::Tomcat::Tomcat.new end it 'includes a default path for the sandbox' do opts = subject.prepare_options opts[:context_path].should == '/sandbox' end it 'allows to override the default path' do ext = Trinidad::Extensions::SandboxServerExtension.new({ :context_path => '/trinidad' }) ext.prepare_options[:context_path].should == '/trinidad' end it 'adds a new application to the host' do subject.configure(@tomcat) @tomcat.host.findChildren().should have(1).children end it 'gives privileges to the applications context' do subject.configure(@tomcat) @tomcat.host.findChildren().first.privileged.should be_true end it 'adds the sandbox servlet to the application context' do app = subject.configure(@tomcat) context = @tomcat.host.findChildren().first listener = context.find_lifecycle_listeners.select do |l| l.instance_of?(Trinidad::Lifecycle::Default) end.first listener.configure_defaults(context) context.findChild('SandboxServlet').should_not be_nil end it 'adds provided credentials to the servlet context' do opts = subject.prepare_options opts[:username] = 'foo' opts[:password] = 'bar' ext = Trinidad::Extensions::SandboxServerExtension.new(opts) app_ctx = ext.create_application_context(@tomcat, opts) app_ctx.servlet_context.get_attribute('sandbox_username').should == 'foo' app_ctx.servlet_context.get_attribute('sandbox_password').should == 'bar' end it 'stores the deploy token to use it for git deployment' do opts = subject.prepare_options opts[:deploy_token] = 'foobar' ext = Trinidad::Extensions::SandboxServerExtension.new(opts) app_ctx = ext.create_application_context(@tomcat, opts) app_ctx.servlet_context.get_attribute('deploy_token').should == 'foobar' end end