Java and Spring fixes for javaee namespace and use of AnnotationConfigWebApplicationContext

- Fixing Spring autoconfig fails when app is using AnnotationConfigWebApplicationContext (CF-11)

 - Handle javaee (or other) namespace if present correctly for all Java based plugins.

Change-Id: I738b10fe02217c804defc92801d7021ca2c5d6bb
This commit is contained in:
Thomas Risberg 2012-04-10 13:55:12 -04:00
Родитель 0766153826
Коммит ddb8f52d22
28 изменённых файлов: 487 добавлений и 20 удалений

Просмотреть файл

@ -8,7 +8,7 @@ gem 'nats', :require => 'nats/client'
# VCAP common components
gem 'vcap_common', :require => ['vcap/common', 'vcap/component']
gem 'vcap_logging', :require => ['vcap/logging']
gem 'vcap_staging', '~> 0.1.58'
gem 'vcap_staging', '~> 0.1.59'
gem 'cf-uaa-client', '~> 0.0.10', :git => 'git://github.com/cloudfoundry/uaa.git', :ref => '0000f736'
# For queuing staging tasks

Просмотреть файл

@ -151,7 +151,7 @@ GEM
thin (~> 1.3.1)
yajl-ruby (~> 0.8.3)
vcap_logging (1.0.1)
vcap_staging (0.1.58)
vcap_staging (0.1.59)
nokogiri (>= 1.4.4)
rake
rspec
@ -192,5 +192,5 @@ DEPENDENCIES
uuidtools (~> 2.1.2)
vcap_common
vcap_logging
vcap_staging (~> 0.1.58)
vcap_staging (~> 0.1.59)
yajl-ruby (~> 0.8.3)

Двоичный файл не отображается.

Просмотреть файл

@ -7,7 +7,7 @@ gem 'yajl-ruby', '>= 0.7.9'
gem 'vcap_common', '~> 1.0.8'
gem 'vcap_logging', '>= 0.1.3'
gem 'vcap_staging', '~> 0.1.58'
gem 'vcap_staging', '~> 0.1.59'
gem 'vcap-concurrency', '~> 0.0.1'
gem 'stager-client', '~> 0.0.2'

Просмотреть файл

@ -49,7 +49,7 @@ GEM
yajl-ruby (~> 0.8.3)
vcap_logging (1.0.1)
rake
vcap_staging (0.1.58)
vcap_staging (0.1.59)
nokogiri (>= 1.4.4)
rake
rspec
@ -75,6 +75,6 @@ DEPENDENCIES
vcap-concurrency (~> 0.0.1)
vcap_common (~> 1.0.8)
vcap_logging (>= 0.1.3)
vcap_staging (~> 0.1.58)
vcap_staging (~> 0.1.59)
webmock
yajl-ruby (>= 0.7.9)

Двоичный файл не отображается.

Просмотреть файл

@ -1,7 +1,7 @@
PATH
remote: .
specs:
vcap_staging (0.1.58)
vcap_staging (0.1.59)
nokogiri (>= 1.4.4)
rake
rspec

Просмотреть файл

@ -25,7 +25,7 @@ class GrailsPlugin < JavaWebPlugin
def vmc_plugin_present grails_config_file
grails_config = Nokogiri::XML(open(grails_config_file))
prefix = grails_config.root.namespace ? "xmlns:" : ''
prefix = Tomcat.get_namespace_prefix(grails_config)
plugins = grails_config.xpath("//#{prefix}plugins/#{prefix}plugin[contains(normalize-space(), '#{VMC_GRAILS_PLUGIN}')]")
if (plugins == nil || plugins.empty?)
return false

Просмотреть файл

@ -1,5 +1,5 @@
module JavaAutoconfig
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.3.jar'
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.4.jar'
def copy_autostaging_jar(dest)
FileUtils.mkdir_p dest

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -4,6 +4,7 @@ require 'fileutils'
class Tomcat
DEFAULT_APP_CONTEXT = "/WEB-INF/applicationContext.xml"
DEFAULT_SERVLET_CONTEXT_SUFFIX = "-servlet.xml"
ANNOTATION_CONTEXT_CLASS = "org.springframework.web.context.support.AnnotationConfigWebApplicationContext"
def self.resource_dir
File.join(File.dirname(__FILE__), 'resources')
@ -22,6 +23,19 @@ class Tomcat
webapp_path
end
def self.get_namespace_prefix(webapp_config)
name_space = webapp_config.root.namespace
if name_space
if name_space.prefix
prefix = name_space.prefix
else
prefix = "xmlns:"
end
else
prefix = ''
end
end
# The staging modifications that are common to one or more framework plugins e.g. ['spring' & 'grails'
# requiring autostaging context_param & autostaging servlet updates and 'spring', 'grails' & 'lift'
# requiring the copying of the autostaging jar etc] are handled below to avoid duplication.
@ -41,10 +55,22 @@ class Tomcat
autostaging_context_param_node = autostaging_context.xpath("//context-param[param-name='contextConfigLocation']").first
autostaging_context_param_name_node = autostaging_context_param_node.xpath("param-name").first
autostaging_context_param_name = autostaging_context_param_name_node.content.strip
autostaging_context_param_value_node = autostaging_context_param_node.xpath("param-value").first
autostaging_context_param_value_xml_node = autostaging_context.xpath("//context-param/param-value").first
prefix = get_namespace_prefix(webapp_config)
autostaging_context_param_anno_node = autostaging_context.xpath("//context-param[param-name='contextConfigLocationAnnotationConfig']").first
if autostaging_context_param_anno_node
autostaging_context_param_value_anno_node = autostaging_context_param_anno_node.xpath("param-value").first
else
autostaging_context_param_value_anno_node = nil
end
cc = webapp_config.xpath("//#{prefix}context-param[contains(normalize-space(#{prefix}param-name), normalize-space('contextClass'))]")
if autostaging_context_param_value_anno_node && cc.xpath("#{prefix}param-value").text == ANNOTATION_CONTEXT_CLASS
autostaging_context_param_value_node = autostaging_context_param_value_anno_node
else
autostaging_context_param_value_node = autostaging_context_param_value_xml_node
end
autostaging_context_param_value = autostaging_context_param_value_node.content
prefix = webapp_config.root.namespace ? "xmlns:" : ''
context_param_nodes = webapp_config.xpath("//#{prefix}context-param")
if (context_param_nodes != nil && context_param_nodes.length > 0)
context_param_node = webapp_config.xpath("//#{prefix}context-param[contains(normalize-space(#{prefix}param-name), normalize-space('#{autostaging_context_param_name}'))]").first
@ -80,10 +106,22 @@ class Tomcat
autostaging_servlet_class = autostaging_context.xpath("//servlet-class").first.content.strip
autostaging_init_param_name_node = autostaging_context.xpath("//servlet/init-param/param-name").first
autostaging_init_param_name = autostaging_init_param_name_node.content.strip
autostaging_init_param_value_node = autostaging_context.xpath("//servlet/init-param/param-value").first
autostaging_init_param_value_xml_node = autostaging_context.xpath("//servlet/init-param/param-value").first
autostaging_init_param_anno_node = autostaging_context.xpath("//servlet/init-param[param-name='contextConfigLocationAnnotationConfig']").first
if autostaging_init_param_anno_node
autostaging_init_param_value_anno_node = autostaging_init_param_anno_node.xpath("param-value").first
else
autostaging_init_param_value_anno_node = nil
end
prefix = get_namespace_prefix(webapp_config)
cc = webapp_config.xpath("//#{prefix}servlet/#{prefix}init-param[contains(normalize-space(#{prefix}param-name), normalize-space('contextClass'))]")
if autostaging_init_param_value_anno_node && cc.xpath("#{prefix}param-value").text == ANNOTATION_CONTEXT_CLASS
autostaging_init_param_value_node = autostaging_init_param_value_anno_node
else
autostaging_init_param_value_node = autostaging_init_param_value_xml_node
end
autostaging_init_param_value = autostaging_init_param_value_node.content
prefix = webapp_config.root.namespace ? "xmlns:" : ''
dispatcher_servlet_nodes = webapp_config.xpath("//#{prefix}servlet[contains(normalize-space(#{prefix}servlet-class), normalize-space('#{autostaging_servlet_class}'))]")
if (dispatcher_servlet_nodes != nil && !dispatcher_servlet_nodes.empty?)
dispatcher_servlet_nodes.each do |dispatcher_servlet_node|

Просмотреть файл

@ -34,7 +34,7 @@ class LiftPlugin < JavaWebPlugin
# information of the services used by the application.
def configure_cf_lift_servlet_context_listener(webapp_path)
web_config = Tomcat.get_web_config(webapp_path)
prefix = web_config.root.namespace ? "xmlns:" : ''
prefix = Tomcat.get_namespace_prefix(web_config)
lift_filter = web_config.xpath("//web-app/filter[contains(
normalize-space(#{prefix}filter-class),
'#{LIFT_FILTER_CLASS}')]")

Просмотреть файл

@ -3,6 +3,10 @@
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocationAnnotationConfig</param-name>
<param-value>org.cloudfoundry.reconfiguration.spring.web.CloudAppAnnotationConfigAutoReconfig</param-value>
</context-param>
<context-param>
<param-name>contextInitializerClasses</param-name>
@ -16,6 +20,10 @@
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocationAnnotationConfig</param-name>
<param-value>org.cloudfoundry.reconfiguration.spring.web.CloudAppAnnotationConfigAutoReconfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>

Просмотреть файл

@ -29,7 +29,7 @@ class SpringPlugin < JavaWebPlugin
autostaging_context_param_value_node = autostaging_context_param_node.xpath("param-value").first
autostaging_context_param_value = autostaging_context_param_value_node.content
prefix = webapp_config.root.namespace ? "xmlns:" : ''
prefix = Tomcat.get_namespace_prefix(webapp_config)
context_param_node = webapp_config.xpath("//#{prefix}context-param[#{prefix}param-name='contextInitializerClasses']").first
if (context_param_node == nil)
context_param_node = Nokogiri::XML::Node.new 'context-param', webapp_config

Просмотреть файл

@ -1,5 +1,5 @@
module VCAP
module Staging
VERSION = '0.1.58'
VERSION = '0.1.59'
end
end

Двоичные данные
staging/spec/fixtures/apps/grails_default_appcontext_and_servlet/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_context_config_and_servletcontext/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_context_config_and_servletcontext_empty/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_context_config_and_servletcontext_ns/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_context_config_empty_with_servletcontext/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_context_config_foo/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
staging/spec/fixtures/apps/spring_annotation_servletcontext_no_context_config/source.war поставляемый Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -1,7 +1,7 @@
require 'tmpdir'
module StagingSpecHelpers
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.3.jar'
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.4.jar'
MYSQL_DRIVER_JAR = 'mysql-connector-java-5.1.12-bin.jar'
POSTGRESQL_DRIVER_JAR = 'postgresql-9.0-801.jdbc4.jar'
INSIGHT_AGENT = 'cf-tomcat-agent-javaagent-1.7.1.RELEASE'

Просмотреть файл

@ -83,3 +83,59 @@ describe "A Grails application being staged without a context-param in its web c
end
end
describe "A Grails application being staged without a context-param in its web config and with a grails servlet specified without an init-param" do
before(:all) do
app_fixture :grails_default_appcontext_and_servlet
end
it "should have a context-param in its web config after staging" do
stage :grails do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
File.exist?(web_config_file).should == true
web_config = Nokogiri::XML(open(web_config_file))
context_param_node = web_config.xpath("//context-param")
context_param_node.length.should_not == 0
end
end
it "should have a 'contextConfigLocation' where the default application context precedes the auto-reconfiguration context" do
stage :grails do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
context_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
context_param_name_node.length.should_not == 0
context_param_value_node = context_param_name_node.first.xpath("param-value")
context_param_value_node.length.should_not == 0
context_param_value = context_param_value_node.first.content
default_context_index = context_param_value.index('/WEB-INF/applicationContext.xml')
default_context_index.should_not == nil
auto_reconfiguration_context_index = context_param_value.index('classpath:META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml')
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > default_context_index + "/WEB-INF/applicationContext.xml".length
end
end
it "should not have a 'contextInitializerClasses' context-param" do
stage :grails do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
context_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextInitializerClasses'))]")
context_param_name_node.length.should == 0
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :grails do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end

Просмотреть файл

@ -1,6 +1,7 @@
require 'spec_helper'
CLOUD_APPLICATION_CONTEXT_INITIALIZER = 'org.cloudfoundry.reconfiguration.spring.CloudApplicationContextInitializer'
CLOUD_APP_ANNOTATION_CONFIG_CLASS = 'org.cloudfoundry.reconfiguration.spring.web.CloudAppAnnotationConfigAutoReconfig'
describe "A Spring application being staged" do
before do
@ -556,13 +557,377 @@ describe "A Spring web application being staged with 2 Spring DispatcherServlets
end
end
def assert_context_param staged_dir, param_name, param_value
describe "A Spring web application being staged using an AnnotationConfigWebApplicationContext in its web config and a contextConfigLocation of 'foo' specified" do
before(:all) do
app_fixture :spring_annotation_context_config_foo
end
it "should have the 'foo' context precede the AnnotationConfigWebApplicationContext in the 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
foo_index = init_param_value.index('foo')
foo_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > foo_index + "foo".length
auto_reconfiguration_context_index.should < foo_index + 5
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
describe "A Spring web application being staged using an AnnotationConfigWebApplicationContext in its web config and a contextConfigLocation of 'foo' specified plus has a servlet init-param using an AnnotationConfigWebApplicationContext and a contextConfigLocation of 'bar'" do
before(:all) do
app_fixture :spring_annotation_context_config_and_servletcontext
end
it "should have the 'foo' context precede the AnnotationConfigWebApplicationContext in the 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
foo_index = init_param_value.index('foo')
foo_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > foo_index + "foo".length
auto_reconfiguration_context_index.should < foo_index + 5
end
end
it "should have the 'bar' context precede the AnnotationConfigWebApplicationContext in the DispatcherServlet's 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//init-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
bar_index = init_param_value.index('bar')
bar_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > bar_index + "bar".length
auto_reconfiguration_context_index.should < bar_index + 5
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
describe "A Spring web application being staged using a namespace and an AnnotationConfigWebApplicationContext in its web config and a contextConfigLocation of 'foo' specified plus has a servlet init-param using an AnnotationConfigWebApplicationContext and a contextConfigLocation of 'bar'" do
before(:all) do
app_fixture :spring_annotation_context_config_and_servletcontext_ns
end
it "should have the 'foo' context precede the AnnotationConfigWebApplicationContext in the 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//xmlns:context-param[contains(normalize-space(xmlns:param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("xmlns:param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
foo_index = init_param_value.index('foo')
foo_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > foo_index + "foo".length
auto_reconfiguration_context_index.should < foo_index + 5
end
end
it "should have the 'bar' context precede the AnnotationConfigWebApplicationContext in the DispatcherServlet's 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//xmlns:init-param[contains(normalize-space(xmlns:param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("xmlns:param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
bar_index = init_param_value.index('bar')
bar_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > bar_index + "bar".length
auto_reconfiguration_context_index.should < bar_index + 5
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER, "xmlns:"
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
describe "A Spring web application being staged using an AnnotationConfigWebApplicationContext in its web config and a dispatcher servlet that does not have a default servlet 'init-param' config" do
before(:all) do
app_fixture :spring_annotation_context_config_and_servletcontext_empty
end
it "should have the 'foo' context precede the AnnotationConfigWebApplicationContext in the 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
foo_index = init_param_value.index('foo')
foo_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > foo_index + "foo".length
auto_reconfiguration_context_index.should < foo_index + 5
end
end
it "should have a init-param in its web config after staging" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
File.exist?(web_config_file).should == true
web_config = Nokogiri::XML(open(web_config_file))
init_param_node = web_config.xpath("//init-param")
init_param_node.length.should_not == 0
end
end
it "should have the default servlet context precede the auto-reconfiguration context in the DispatcherServlet's 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//init-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
dispatcher_servlet_index = init_param_value.index('/WEB-INF/dispatcher-servlet.xml')
dispatcher_servlet_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index('classpath:META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml')
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > dispatcher_servlet_index + "/WEB-INF/dispatcher-servlet.xml".length
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
describe "A Spring web application being staged with a context-param but without a 'contextConfigLocation' param-name in its web config and using a dispatcher servlet that does have an 'init-param' config with an AnnotationConfigWebApplicationContext" do
before(:all) do
app_fixture :spring_annotation_context_config_empty_with_servletcontext
end
it "should have a 'contextConfigLocation' where the default application context precedes the auto-reconfiguration context" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
context_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
context_param_name_node.length.should_not == 0
context_param_value_node = context_param_name_node.first.xpath("param-value")
context_param_value_node.length.should_not == 0
context_param_value = context_param_value_node.first.content
default_context_index = context_param_value.index('/WEB-INF/applicationContext.xml')
default_context_index.should_not == nil
auto_reconfiguration_context_index = context_param_value.index('classpath:META-INF/cloud/cloudfoundry-auto-reconfiguration-context.xml')
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > default_context_index + "/WEB-INF/applicationContext.xml".length
end
end
it "should have the 'bar' context precede the AnnotationConfigWebApplicationContext in the DispatcherServlet's 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//init-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
bar_index = init_param_value.index('bar')
bar_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > bar_index + "bar".length
auto_reconfiguration_context_index.should < bar_index + 5
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
describe "A Spring web application being staged using an AnnotationConfigWebApplicationContext in its servlet init-param and a contextConfigLocation of 'bar' specified" do
before(:all) do
app_fixture :spring_annotation_servletcontext_no_context_config
end
it "should have the 'bar' context precede the AnnotationConfigWebApplicationContext in the DispatcherServlet's 'contextConfigLocation' param-value" do
stage :spring do |staged_dir|
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
init_param_name_node = web_config.xpath("//init-param[contains(normalize-space(param-name), normalize-space('contextConfigLocation'))]")
init_param_name_node.length.should_not == 0
init_param_value_node = init_param_name_node.xpath("param-value")
init_param_value_node.length.should_not == 0
init_param_value = init_param_value_node.first.content
bar_index = init_param_value.index('bar')
bar_index.should_not == nil
auto_reconfiguration_context_index = init_param_value.index(CLOUD_APP_ANNOTATION_CONFIG_CLASS)
auto_reconfiguration_context_index.should_not == nil
auto_reconfiguration_context_index.should > bar_index + "bar".length
auto_reconfiguration_context_index.should < bar_index + 5
end
end
it "should have a 'contextInitializerClasses' context-param with only the CloudApplicationContextInitializer" do
stage :spring do |staged_dir|
assert_context_param staged_dir, 'contextInitializerClasses', CLOUD_APPLICATION_CONTEXT_INITIALIZER
end
end
it "should have the auto reconfiguration jar in the webapp lib path" do
stage :spring do |staged_dir|
auto_reconfig_jar_relative_path = "tomcat/webapps/ROOT/WEB-INF/lib/#{AUTOSTAGING_JAR}"
auto_reconfiguration_jar_path = File.join(staged_dir, auto_reconfig_jar_relative_path)
File.exist?(auto_reconfiguration_jar_path).should == true
end
end
end
def assert_context_param staged_dir, param_name, param_value, prefix=""
web_config_file = File.join(staged_dir, 'tomcat/webapps/ROOT/WEB-INF/web.xml')
web_config = Nokogiri::XML(open(web_config_file))
context_param_name_node = web_config.xpath("//context-param[contains(normalize-space(param-name), normalize-space('#{param_name}'))]")
context_param_name_node = web_config.xpath("//#{prefix}context-param[contains(normalize-space(#{prefix}param-name), normalize-space('#{param_name}'))]")
context_param_name_node.length.should_not == 0
context_param_value_node = context_param_name_node.first.xpath("param-value")
context_param_value_node = context_param_name_node.first.xpath("#{prefix}param-value")
context_param_value_node.length.should_not == 0
context_param_value = context_param_value_node.first.content