bifurcate tests to reflect both apache nvelocity and castle nvelocity libs; re-enable apache nvelocity tests

This commit is contained in:
Steve Bohlen
2015-04-19 10:32:07 -04:00
parent b2e9b58b05
commit cc30cbecb6
6 changed files with 211 additions and 7 deletions

View File

@@ -565,7 +565,7 @@ Commandline Examples:
<nant buildfile="test/Spring/Spring.Messaging.Nms.Integration.Tests/Spring.Messaging.Nms.Integration.Tests.build" target="test" if="${build-nms}"/>
<nant buildfile="test/Spring/Spring.Scheduling.Quartz2.Tests/Spring.Scheduling.Quartz2.Tests.build" target="test" if="${build-quartz}"/>
<nant buildfile="test/Spring/Spring.Messaging.Tests/Spring.Messaging.Tests.build" target="test" if="${build-msmq}"/>
<!-- <nant buildfile="test/Spring/Spring.Template.Velocity.Tests/Spring.Template.Velocity.Tests.build" target="test" if="${build-velocity}"/> -->
<nant buildfile="test/Spring/Spring.Template.Velocity.Tests/Spring.Template.Velocity.Tests.build" target="test" if="${build-velocity}"/>
<nant buildfile="test/Spring/Spring.Template.Velocity.Castle.Tests/Spring.Template.Velocity.Castle.Tests.build" target="test" if="${build-velocity}"/>
<!--"Spring.ConversationWA.NH*.Tests.dll" should be at last to prevent the other tests are compiled with reference to this-->

View File

@@ -60,9 +60,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Spring.Template.Velocity.Tests\Template\Velocity\Config\TemplateNamespaceParserTests.cs">
<Link>Template\Velocity\Config\TemplateNamespaceParserTests.cs</Link>
</Compile>
<Compile Include="..\Spring.Template.Velocity.Tests\Template\Velocity\VelocityEngineFactoryObjectTests.cs">
<Link>Template\Velocity\VelocityEngineFactoryObjectTests.cs</Link>
</Compile>
@@ -72,6 +69,7 @@
<Compile Include="..\Spring.Template.Velocity.Tests\VelocityCompilerOptionsTests.cs">
<Link>VelocityCompilerOptionsTests.cs</Link>
</Compile>
<Compile Include="Template\Velocity\Config\TemplateNamespaceParserTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2010.csproj">

View File

@@ -38,6 +38,7 @@
<include name="**/*.cs" />
<include name="../Spring.Template.Velocity.Tests/**/*.cs" />
<include name="../CommonAssemblyInfo.cs" />
<exclude name="../Spring.Template.Velocity.Tests/Template/Velocity/Config/TemplateNamespaceParserTests.cs" />
</sources>
<references>
<include name="mscorlib.dll"/>

View File

@@ -0,0 +1,205 @@
#region License
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed 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.
*/
#endregion
#region Imports
using System.Collections;
using System.IO;
using System.Text;
using Commons.Collections;
using NUnit.Framework;
using NVelocity.App;
using NVelocity.Runtime;
using NVelocity.Runtime.Resource;
using NVelocity.Runtime.Resource.Loader;
using Spring.Core.IO;
using Spring.Template.Velocity.Config;
#endregion
namespace Spring.Template.Velocity.Config {
/// <summary>
/// This class contains tests for the template namespace configuration parser
/// </summary>
/// <author>Erez Mazor</author>
[TestFixture]
public class TemplateNamespaceParserTests : VelocityEngineTestBase {
#region convinience properties aliases
private const string PropertyModificationCheck =
TemplateDefinitionConstants.PropertyResourceLoaderModificationCheckInterval;
private const string PropertyResourceLoaderCachce =
TemplateDefinitionConstants.PropertyResourceLoaderCaching;
#endregion
#region test constants
private const int DEFAULT_CACHE_SIZE = 200;
private const int DEFAULT_MOD_CHECK = 30;
private const bool DEFAULT_CACHE_FLAG = true;
#endregion
/// <summary>
/// Test a full file-base configuration
/// </summary>
[Test]
public void TestFileBasedConfig() {
VelocityEngine velocityEngine = appContext.GetObject("cnFileVelocityEngine") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
Assert.AreEqual(VelocityConstants.File, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual(TemplateDefinitionConstants.FileResourceLoaderClass, getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.File, VelocityConstants.Class)), "incorrect resource loader type");
Assert.AreEqual(new string[]{"Template/Velocity/", "Template/"}, velocityEngine.GetProperty(
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.File, VelocityConstants.Path)), "incorrect resource loader path");
Assert.AreEqual(DEFAULT_CACHE_SIZE, velocityEngine.GetProperty(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE), "incorrect default cache size");
Assert.AreEqual(DEFAULT_MOD_CHECK, velocityEngine.GetProperty(
VelocityConstants.File + VelocityConstants.Separator + PropertyModificationCheck), "incorrect mod check interval");
Assert.AreEqual(DEFAULT_CACHE_FLAG, velocityEngine.GetProperty(VelocityConstants.File + VelocityConstants.Separator + PropertyResourceLoaderCachce),
"incorrect caching flag");
AssertMergedValue(velocityEngine, "SimpleTemplate.vm");
}
/// <summary>
/// Test a full aaembly-based configuration
/// </summary>
[Test]
public void TestAssemblyBasedConfig() {
VelocityEngine velocityEngine = appContext.GetObject("cnAssemblyVelocityEngine") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
Assert.AreEqual(VelocityConstants.Assembly, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual(TemplateDefinitionConstants.AssemblyResourceLoaderClass, getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly, VelocityConstants.Class)), "incorrect resource loader type");
Assert.AreEqual("Spring.Template.Velocity.Castle.Tests", getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly,VelocityConstants.Assembly)), "incorrect resource loader path");
Assert.AreEqual(DEFAULT_CACHE_SIZE, velocityEngine.GetProperty(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE), "incorrect default cache size");
Assert.AreEqual(DEFAULT_CACHE_FLAG, velocityEngine.GetProperty(VelocityConstants.Assembly + VelocityConstants.Separator + PropertyResourceLoaderCachce),
"incorrect caching flag");
AssertMergedValue(velocityEngine, "Spring.Template.Velocity.SimpleTemplate.vm");
}
/// <summary>
/// Test a full aaembly-based configuration
/// </summary>
[Test]
public void TestSpringBasedConfig() {
VelocityEngine velocityEngine = appContext.GetObject("cnSpringVelocityEngine") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
const string PropertySpring = TemplateDefinitionConstants.Spring;
Assert.AreEqual(PropertySpring, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual(TemplateDefinitionConstants.SpringResourceLoaderClass, getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(PropertySpring, VelocityConstants.Class)), "incorrect resource loader type");
// no way to test the path property other than trying to actually perform a merge (it is set in velocity engine as an application attribute which is not exposed)
Assert.AreEqual(DEFAULT_CACHE_SIZE, velocityEngine.GetProperty(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE), "incorrect default cache size");
Assert.AreEqual(DEFAULT_CACHE_FLAG, velocityEngine.GetProperty(PropertySpring + VelocityConstants.Separator + PropertyResourceLoaderCachce),
"incorrect caching flag");
AssertMergedValue(velocityEngine, "SimpleTemplate.vm");
AssertMergedValue(velocityEngine, "EmbeddedTemplate.vm");
}
/// <summary>
/// Test using an external configuration properties definition
/// </summary>
[Test]
public void TestGlobalConfig() {
VelocityEngine velocityEngine = appContext.GetObject("cnVelocityEngineConfig") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
string classProp = TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly, VelocityConstants.Class);
string descProp = TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly, VelocityConstants.Description);
Assert.AreEqual(VelocityConstants.Assembly, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual("NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader",
getSingleProperty(velocityEngine,classProp), "incorrect resource loader type");
Assert.AreEqual("TestDescription", getSingleProperty(velocityEngine, descProp), "incorrect description");
}
/// <summary>
/// Test using local config.
/// </summary>
[Test]
public void TestLocalConfig() {
VelocityEngine velocityEngine = appContext.GetObject("cnVelocityEngineLocalConfig") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
Assert.AreEqual(Encoding.UTF8.WebName.ToUpper(), getSingleProperty(velocityEngine, RuntimeConstants.INPUT_ENCODING), "incorrect input encoding value");
Assert.AreEqual(TEST_VALUE, getSingleProperty(velocityEngine, "myproperty.mysubproperty"), "incorrect custom property value");
}
/// <summary>
/// Test a custom resource loader definition
/// </summary>
[Test]
public void TestCustomResourceLoader() {
VelocityEngine velocityEngine = appContext.GetObject("cnVelocityEngingCustomResourceLoader") as VelocityEngine;
Assert.IsNotNull(velocityEngine, "velocity engine is null");
const string PropertyMyResourceLoader = "myResourceLoader";
string classProp = TemplateNamespaceParser.getResourceLoaderProperty(PropertyMyResourceLoader, VelocityConstants.Class);
string descProp = TemplateNamespaceParser.getResourceLoaderProperty(PropertyMyResourceLoader, VelocityConstants.Description);
Assert.AreEqual(PropertyMyResourceLoader, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual("Spring.Template.Velocity.Config.TestCustomResourceLoader; Spring.Template.Velocity.Castle.Tests",
getSingleProperty(velocityEngine, classProp), "incorrect resource loader type");
Assert.AreEqual(PropertyMyResourceLoader, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual("A custom resource loader",
getSingleProperty(velocityEngine, descProp), "incorrect resource loader description");
Assert.AreEqual("Template/Velocity/", getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(PropertyMyResourceLoader, VelocityConstants.Path)), "incorrect resource loader path");
AssertMergedValue(velocityEngine, "Template/Velocity/SimpleTemplate.vm");
}
#region internal test methods
/// <summary>
/// Grab a single property from (if it's an array return the first value) from the velocityEngine
/// </summary>
private string getSingleProperty(VelocityEngine velocityEngine, string prop) {
object property = velocityEngine.GetProperty(prop);
if (property is ArrayList) {
ArrayList list = (ArrayList)property;
return (string)list[0];
}
return (string)property;
}
#endregion
}
#region test classes
/// <summary>
/// Test class for a custom resource loader class
/// </summary>
internal sealed class TestCustomResourceLoader : ResourceLoader {
public override void Init(ExtendedProperties configuration) {
}
public override Stream GetResourceStream(string source) {
return new ConfigurableResourceLoader().GetResource(source).InputStream;
}
public override bool IsSourceModified(Resource resource) {
return false;
}
public override long GetLastModified(Resource resource) {
return resource.LastModified;
}
}
#endregion
}

View File

@@ -58,7 +58,7 @@
<include name="**/*.config" />
</resources>
</csc>
<copy todir="${current.bin.dir}" failonerror="true">
<copy todir="${current.bin.dir}" overwrite="true failonerror="true">
<fileset basedir="${project::get-base-directory()}">
<include name="**/*.xml" />
<include name="**/*.xsd" />

View File

@@ -85,7 +85,7 @@ namespace Spring.Template.Velocity.Config {
Assert.AreEqual(VelocityConstants.Assembly, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual(TemplateDefinitionConstants.AssemblyResourceLoaderClass, getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly, VelocityConstants.Class)), "incorrect resource loader type");
Assert.AreEqual("Spring.Template.Velocity.Castle.Tests", getSingleProperty(velocityEngine,
Assert.AreEqual("Spring.Template.Velocity.Tests", getSingleProperty(velocityEngine,
TemplateNamespaceParser.getResourceLoaderProperty(VelocityConstants.Assembly,VelocityConstants.Assembly)), "incorrect resource loader path");
Assert.AreEqual(DEFAULT_CACHE_SIZE, velocityEngine.GetProperty(RuntimeConstants.RESOURCE_MANAGER_DEFAULTCACHE_SIZE), "incorrect default cache size");
Assert.AreEqual(DEFAULT_CACHE_FLAG, velocityEngine.GetProperty(VelocityConstants.Assembly + VelocityConstants.Separator + PropertyResourceLoaderCachce),
@@ -155,7 +155,7 @@ namespace Spring.Template.Velocity.Config {
Assert.AreEqual(PropertyMyResourceLoader, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual("Spring.Template.Velocity.Config.TestCustomResourceLoader; Spring.Template.Velocity.Castle.Tests",
Assert.AreEqual("Spring.Template.Velocity.Config.TestCustomResourceLoader; Spring.Template.Velocity.Tests",
getSingleProperty(velocityEngine, classProp), "incorrect resource loader type");
Assert.AreEqual(PropertyMyResourceLoader, getSingleProperty(velocityEngine, RuntimeConstants.RESOURCE_LOADER), "incorrect resource loader");
Assert.AreEqual("A custom resource loader",