-
Notifications
You must be signed in to change notification settings - Fork 933
NH-4052 - Collect schema validation exceptions #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
namespace="NHibernate.Test.Tools.hbm2ddl.SchemaValidator" | ||
assembly="NHibernate.Test"> | ||
|
||
<class name="Version"> | ||
<id name="Id"> | ||
<generator class="NHibernate.Id.TableHiLoGenerator"> | ||
<param name="table">id_table</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Altered table name for generator. |
||
<param name="column">next_hi_value_column</param> | ||
</generator> | ||
</id> | ||
<property name="Description"/> | ||
<property name="Name"/> | ||
<property name="Title"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more missing column. |
||
</class> | ||
</hibernate-mapping> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,36 @@ namespace NHibernate.Test.Tools.hbm2ddl.SchemaValidator | |
[TestFixture] | ||
public class SchemaValidateFixture | ||
{ | ||
[Test] | ||
public void ShouldVerifySameTable() | ||
private const string _resourcesPrefix = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator."; | ||
private const string _version1Resource = _resourcesPrefix + "1_Version.hbm.xml"; | ||
private const string _version2Resource = _resourcesPrefix + "2_Version.hbm.xml"; | ||
private const string _version3Resource = _resourcesPrefix + "3_Version.hbm.xml"; | ||
private Configuration _configuration1; | ||
private SchemaExport _export1; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetUp() | ||
{ | ||
const string resource = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml"; | ||
var cfg = BuildConfiguration(resource); | ||
_configuration1 = BuildConfiguration(_version1Resource); | ||
} | ||
|
||
new SchemaExport(cfg).Execute(true, true, false); | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_export1 = new SchemaExport(_configuration1); | ||
_export1.Create(true, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a wrapper more explicit than |
||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_export1.Drop(true, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was not dropping previously. |
||
} | ||
|
||
var validator = new Tool.hbm2ddl.SchemaValidator((cfg)); | ||
[Test] | ||
public void ShouldVerifySameTable() | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator((_configuration1)); | ||
validator.Validate(); | ||
} | ||
|
||
|
@@ -34,36 +55,49 @@ public void ShouldVerifySameTableTurkish() | |
var v = new Version(); | ||
Assert.That(v.Id, Is.TypeOf<int>()); | ||
|
||
var cfg = BuildConfiguration(_version1Resource); | ||
|
||
const string resource = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml"; | ||
var cfg = BuildConfiguration(resource); | ||
|
||
new SchemaExport(cfg).Execute(true, true, false); | ||
|
||
var validator = new Tool.hbm2ddl.SchemaValidator(cfg); | ||
validator.Validate(); | ||
var export = new SchemaExport(cfg); | ||
export.Create(true, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the Turkish case, I am not sure if creating the schema under the Turkish culture is required or not, so I have left it in place. |
||
try | ||
{ | ||
var validator = new Tool.hbm2ddl.SchemaValidator(cfg); | ||
validator.Validate(); | ||
} | ||
finally | ||
{ | ||
export.Drop(true, true); | ||
} | ||
} | ||
|
||
[Test] | ||
public void ShouldNotVerifyModifiedTable() | ||
{ | ||
const string resource1 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.1_Version.hbm.xml"; | ||
var cfgV1 = BuildConfiguration(resource1); | ||
var cfgV2 = BuildConfiguration(_version2Resource); | ||
var validatorV2 = new Tool.hbm2ddl.SchemaValidator(cfgV2); | ||
|
||
Assert.That( | ||
() => validatorV2.Validate(), | ||
Throws.TypeOf<SchemaValidationException>() | ||
.And.Message.EqualTo("Schema validation failed: see list of validation errors") | ||
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase); | ||
} | ||
|
||
const string resource2 = "NHibernate.Test.Tools.hbm2ddl.SchemaValidator.2_Version.hbm.xml"; | ||
var cfgV2 = BuildConfiguration(resource2); | ||
[Test] | ||
public void ShouldNotVerifyMultiModifiedTable() | ||
{ | ||
var cfg = BuildConfiguration(_version3Resource); | ||
|
||
new SchemaExport(cfgV1).Execute(true, true, false); | ||
var validator = new Tool.hbm2ddl.SchemaValidator(cfg); | ||
|
||
var validatorV2 = new Tool.hbm2ddl.SchemaValidator(cfgV2); | ||
try | ||
{ | ||
validatorV2.Validate(); | ||
} | ||
catch (HibernateException e) | ||
{ | ||
Assert.That(e.Message, Does.StartWith("Missing column: Name")); | ||
} | ||
var error = Assert.Throws<SchemaValidationException>(() => validator.Validate()); | ||
Assert.That(error, | ||
Has.Message.EqualTo("Schema validation failed: see list of validation errors") | ||
.And.Property("ValidationErrors").Some.Contains("Missing column: Name in ").IgnoreCase.And.Contains("Version").IgnoreCase); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know another way for testing multiple values. Assert.That(error,
Has.Property("ValidationErrors").Some.Contains("Missing column: Title in ").IgnoreCase.And.Contains("Version").IgnoreCase);
Assert.That(error,
Has.Property("ValidationErrors").Some.Contains("Missing sequence or table: ").IgnoreCase.And.Contains("id_table").IgnoreCase); |
||
Assert.That(error, | ||
Has.Property("ValidationErrors").Some.Contains("Missing column: Title in ").IgnoreCase.And.Contains("Version").IgnoreCase); | ||
Assert.That(error, | ||
Has.Property("ValidationErrors").Some.Contains("Missing sequence or table: ").IgnoreCase.And.Contains("id_table").IgnoreCase); | ||
} | ||
|
||
private static Configuration BuildConfiguration(string resource) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was converting them to async otherwise, causing them to be invalid. The test for this feature does not inherit a base test class, and was not cleaning up correctly (leaving schema). So I have added setup and teardown logic in it.