hprange / wounit

The WOUnit framework contains a set of utilities for testing WebObjects applications using JUnit 4.7 or later capabilities.
http://hprange.github.io/wounit/
Apache License 2.0
19 stars 18 forks source link

WOUnit doesn't propagate delete when validating objects for deletion #43

Closed hprange closed 9 years ago

hprange commented 9 years ago

The implementation of the CanBeDeletedMatcher can lead to code that will pass the tests but will fail in production.

WOUnit offers a matcher to verify if an object can or cannot be deleted. The implementation of this matcher is simple. It calls only the validateForDelete method on the object being verified. Considering how EOF works, this implementation is not enough. It doesn't guarantee, for instance, that the state of the object will be correct when firing the validation code while running tests.

In production, two actions execute before the validation and may change the state of an object. The ERXEC calls the ERXEnterpriseObject.mightDelete method when the object is deleted, and the original EOEditingContext propagates the deletion over related objects (applying the delete rules defined in the EOModel) when the editing context is saved. If a relationship has a delete rule of type Nullify or Cascade, it will no longer be in place when the validation is executed.

The following uses of the CanBeDeletedMatcher are affected by this issue:

confirm(eo, canBeDeleted());
confirm(eo, cannotBeDeleted());
confirm(eo, cannotBeDeletedBecause("reason"));

To fix this problem, the CanBeDeletedMatcher should call the ERXEnterpriseObject.mightDelete and the EOEnterpriseObject.propagateDeleteWithEditingContext methods before calling the validateForDelete method.