Skip to content
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

Enable reuse of DefaultActiveProfilesResolver [SPR-12611] #17212

Closed
spring-issuemaster opened this issue Jan 9, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 9, 2015

Tadaya Tsuyukubo opened SPR-12611 and commented

Background

I want to write a custom profile resolver for @ActiveProfiles.

The profile resolution logic is to dynamically append profiles on top of profiles resolved by default logic. Since it is appending profiles, I wanted to either extend or delegate to the DefaultActiveProfilesResolver class to reuse the default logic.

public class MyProfileResolver extends DefaultActiveProfilesResolver {
  @Override
  public String[] resolve(Class<?> testClass) {
    String[] profiles = super.resolve(testClass);
    // my logic to append profiles
  }
}
public class MyProfileResolver implements ActiveProfilesResolver {
  private final ActiveProfilesResolver defaultResolver = new DefaultActiveProfilesResolver();
  @Override
  public String[] resolve(Class<?> testClass) {
    String[] profiles = defaultResolver.resolve(testClass);
    // my logic to append profiles
  }
}

However, in DefaultActiveProfilesResolver, there is this check logic:

Class<? extends ActiveProfilesResolver> resolverClass = annAttrs.getClass("resolver");
if (!ActiveProfilesResolver.class.equals(resolverClass)) {
  String msg = String.format("Configuration error for test class [%s]: %s cannot be used "
    + "in conjunction with custom resolver [%s].", rootDeclaringClass.getName(),
    getClass().getSimpleName(), resolverClass.getName());
  logger.error(msg);
  throw new IllegalStateException(msg);
}

Basically, this check logic prevents the reuse of the DefaultActiveProfilesResolver class.


Proposal

Can this check can be removed, or should this check be isAssignableFrom() instead of equals()?


Affects: 4.1 GA

Issue Links:

  • #14588 Introduce bootstrap strategy in the TestContext framework ("depends on")
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 10, 2015

Sam Brannen commented

Tadaya Tsuyukubo, this was a use case that I did not foresee when I wrote that check. So thanks for bringing it to my attention.

After a cursory review of the changes introduced in conjunction with #14588, I believe that it should be possible to simply get rid of that check altogether.

Regards,

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 10, 2015

Sam Brannen commented

Completed as described in GitHub commit 276712d:

Enable reuse of DefaultActiveProfilesResolver

In order to allow DefaultActiveProfilesResolver to be reused (e.g., via
extension or delegation), the check which asserts that the 'resolver'
attribute of @ActiveProfiles is not set to a customer resolver class
has been removed.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 10, 2015

Sam Brannen commented

Backported to Spring Framework 4.1.5: a76a650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.