eclipse / kapua

Eclipse Public License 2.0
225 stars 160 forks source link

Unable to Successfully Run SSO Unit Tests #3296

Open nezau-ct opened 3 years ago

nezau-ct commented 3 years ago

When trying to write unit tests for SSO class(es), I discovered a tricky behaviour. I have multiple test folders (one test folder/source folder) and every folder has testing classes that test one "source" class and when running the tests sepparatelly (one class at a time), everything is working fine.

When running them as a whole, they fail, because it seems that the system values are somehow retained from previous tests ("sso.openid.client.id", "sso.openid.keycloak.uri" and "sso.openid.keycloak.realm"). I have tried to use System.clearProperty and System.setProperty in almost every way imaginable (they work fine by the way, the varables have the desired vlaue), but the "actual" value from the first test is somehow somwhere retained in the code and because of this all other tests fail. If I regroup (rename) the tests, the behaviour is the same (variables have the desired values, but the tests fail, because older values are retained). Can anyone check what this is about? Is there some sort of connection between the classes?

Testflow:

  1. Create unit test for "KeycloakOpenIdLocator" (setting the "sso.openid.client.id", "sso.openid.keycloak.uri" and "sso.openid.keycloak.realm")
  2. Create another testing class, which tests the KeycloakOpenIdService class
  3. Run all the tests

Expected behavior When clearing the system properties with "System.clearProperty", the property should be set to NULL. This is not the case here (the value is retained from previous class), so all other tests fail.

Screenshots 123

Version of Kapua latest develop

Type of deployment /

Main component affected [ ] Console (in case of console please report info on which browser you encountered the problem) [ ] REST API [ ] Message Broker [X] - Others

Additional context /

riccardomodanese commented 3 years ago

Hi @nezau-ct I found this issue while developing the external consumers feature. I deeply refactored the test initialization stuff and in my fork the behavior is predictable. I'm trying to recall what I did since it was time ago, but more or less I removed the @CucumberProperty and our runner implementation (this was a bad approach confirmed by the fact that the newer Cucumber version dosn't allow to extend the test runner). And I prefer to avoid any refactoring in develop now, if possible, since it will deeply impact my future rebases, hoping to be able to prepare a pull request and merge my code soon. There are other few things I changed since, imho, extending a class that is a library (just static methods) just to avoid to reference its methods with the class name prefix is wrong ( KapuaDatabaseCheckUpdateTest )

If you want to take a look to my fork: https://github.com/riccardomodanese/kapua/tree/feature-externalCamel

nezau-ct commented 3 years ago

Hi @riccardomodanese , I understand, thank you.