}
@Test
public void testReadConfiguration() throws Exception
{
ProjectPaths projectPaths = new Maven2DirectoryProjectPaths(
new File("src/test/configuration"));
UnitDescriptor unitDescriptor = new UnitDescriptor(
UnitDescriptor.Packaging.DIRECTORY,
projectPaths,
new DefaultTorqueGeneratorPaths());
UnitConfigurationReader configurationReader
= new UnitConfigurationReader();
ConfigurationHandlers configurationHandlers
= new ConfigurationHandlers();
UnitConfiguration unitConfiguration
= configurationReader.read(
unitDescriptor,
configurationHandlers);
{
File defaultTargetDirectory
= unitConfiguration.getOutputDirectory(null);
File expected = new File(
"src/test/configuration/target/generated-sources");
assertEquals(expected, defaultTargetDirectory);
}
{
File modifiableTargetDirectory
= unitConfiguration.getOutputDirectory("modifiable");
File expected = new File(
"src/test/configuration/src/main/generated-java");
assertEquals(expected, modifiableTargetDirectory);
}
try
{
unitConfiguration.getOutputDirectory("notExistingKey");
fail("Exception expected");
}
catch (IllegalStateException e)
{
// expected
}
assertEquals(Loglevel.DEBUG, unitConfiguration.getLoglevel());
{
Options expectedOptions = new Options();
Set<Option> expectedOptionSet = new HashSet<Option>();
expectedOptionSet.add(new OptionImpl(
new QualifiedName("org.apache.torque.generator.optionWithNamespace"),
"optionWithNamespaceValue"));
expectedOptionSet.add(new OptionImpl(
new QualifiedName("org.apache.optionWithNamespace"),
"org.apache.optionWithNamespaceValue"));
expectedOptionSet.add(new OptionImpl(
new QualifiedName("optionWithoutNamespace", ""),
"optionWithoutNamespaceValue"));
expectedOptionSet.add(new OptionImpl(
new QualifiedName("optionPrecedenceLastFile"),
"value from xml"));
expectedOptionSet.add(new OptionImpl(
new QualifiedName("jdbcUrl"),
"jdbc.url.option.value"));
expectedOptionSet.add(new OptionImpl(
new QualifiedName("jdbcDriver"),
"jdbc.driver.option.value"));
expectedOptions.addGlobalOptions(expectedOptionSet);
assertOptionsEquals(
expectedOptions,
unitConfiguration.getOptions());
}
{
EntityReferences entityReferences
= unitConfiguration.getEntityReferences();
Map<String, byte[]> actual = entityReferences.getEntityReferences();
assertEquals(2, actual.size());
assertArrayEquals(
FileUtils.readFileToByteArray(
new File("src/test/configuration/src/main/torque-gen/resources/override.xsd")),
actual.get("http://db.apache.org/torque/some.xsd"));
assertArrayEquals(
FileUtils.readFileToByteArray(
new File("src/test/configuration/src/main/torque-gen/resources/new.xsd")),
actual.get("http://db.apache.org/torque/new.xsd"));
}
{
List<Output> outputFiles = unitConfiguration.getOutputList();
assertEquals(3, outputFiles.size());
{
Output output = outputFiles.get(0);
assertEquals(
new QualifiedName("org.apache.torque.generator.firstOutput"),
output.getName());
assertEquals(
"skip",
output.getExistingTargetStrategy());
assertEquals(
null,
output.getOutputDirKey());
assertNull(output.getFilename());
{
OutletReference outletConfiguration
= output.getContentOutlet();
assertEquals(
new QualifiedName(
"org.apache.torque.generator.test.readConfiguration.javaOutlet"),
outletConfiguration.getName());
}
{
JavaOutlet filenameOutlet
= (JavaOutlet) output.getFilenameOutlet();
assertEquals("Foo", filenameOutlet.getFoo());
assertEquals("Bar", filenameOutlet.getBar());
assertEquals(
new QualifiedName(
"org.apache.torque.generator.configuration.filenameOutlet"),
filenameOutlet.getName());
}
{
Fileset sourceFileset = new Fileset(
projectPaths.getDefaultSourcePath(),
new HashSet<String>(),
new HashSet<String>());
FileSourceProvider sourceProvider = new FileSourceProvider(
new XmlSourceFormat(),
sourceFileset,
null);
sourceProvider.init(
configurationHandlers,
controllerState);
output.getSourceProvider().init(
configurationHandlers,
controllerState);
assertFileSourceProviderEquals(
sourceProvider,
(FileSourceProvider) output.getSourceProvider());
}
assertSourceProcessConfigurationEquals(
new SourceProcessConfiguration(),
output.getSourceProcessConfiguration());
}
{
Output output = outputFiles.get(1);
assertEquals(
new QualifiedName("secondOutput"),
output.getName());
assertEquals(
"replace",
output.getExistingTargetStrategy());
assertEquals(
"secondOutputDirKey",
output.getOutputDirKey());
assertNull(output.getFilename());
{
OutletReference outletConfiguration
= output.getContentOutlet();
assertEquals(
new QualifiedName(
"org.apache.torque.generator.test.readConfiguration.anotherOutlet"),
outletConfiguration.getName());
}
{
VelocityOutlet filenameOutlet
= (VelocityOutlet) output.getFilenameOutlet();
String templateContent
= filenameOutlet.getContent(controllerState);
// remove License from template by comparing only
// the last line
String templateContentLicenseRemoved
= StringUtils.substringAfterLast(templateContent, "\r\n");
assertEquals(
"test template output",
templateContentLicenseRemoved);
assertEquals(
new QualifiedName(
"org.apache.torque.generator.configuration.filenameOutlet"),
filenameOutlet.getName());
assertTrue(filenameOutlet.isOptionsInContext());
assertTrue(filenameOutlet.isSourceAttributesInContext());
assertTrue(filenameOutlet.isVariablesInContext());
}
{
Fileset sourceFileset = new Fileset(
projectPaths.getDefaultSourcePath(),
createSetFrom("second.source.path.properties"),
createSetFrom("second.excluded.properties"));
FileSourceProvider sourceProvider = new FileSourceProvider(
new PropertiesSourceFormat(),
sourceFileset,