MODE-2043 Added some tests for the upgrade mechanism and a small code refactoring.

Due to the fact that the upgrading mechanism is triggered only on the change of some internal repository state, it's not really possible to cleanly test this behavior out-of-context (at least not without exposing internal data).

Therefore, the functional tests will have to be indirect via the testing of other tasks like: https://issues.jboss.org/browse/MODE-2044