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

@WithAccessId collides with @ParameterizedTest #555

Open
bruderj15 opened this issue Feb 12, 2025 · 8 comments
Open

@WithAccessId collides with @ParameterizedTest #555

bruderj15 opened this issue Feb 12, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@bruderj15
Copy link
Member

Whenever writing parametrized tests that require additional @WithAccessId, the tests get created as expected but there is an additional test for every @WithUserId provided, which in turn fails because it does not provide a value for the actual parameter.

E.g. consider:

  @ParameterizedTest
  @EnumSource(Bar.class)
  @WithAccessId(user = "user-1-2")
  void should_Foo_For_Bar(Bar bar) {
    // ...
  }

This will run the following tests:

for user 'user-1-2'
[2] BarSummand1
[3] BarSummand2
...

The first one fails with:

org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [foo.Bar arg0] in method [void foo.test.BarTest.should_Foo_For_Bar(foo.Bar)].
        at ...
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
@bruderj15 bruderj15 added the bug Something isn't working label Feb 12, 2025
@jamesrdi
Copy link
Contributor

jamesrdi commented Feb 14, 2025

I cannot replicate the problem, I tried running this test I made and it worked fine

private enum Bar {
      VALUE2(-1),
      VALUE3(0);

      private final int value; // Field for integer value

      Bar(int value) {
        this.value = value;
      }

      public int getValue() {
        return value;
      }
    }

    @ParameterizedTest
    @EnumSource(Bar.class)
    @WithAccessId(user = "user-1-2")
    void testParameterizedTest(Bar jobBatchSize) {

    }

@bruderj15
Copy link
Member Author

You probably need to extend the class with @ExtendWith(JaasExtension.class).

@bruderj15
Copy link
Member Author

Here is a minimal working example:

import io.kadai.common.test.security.JaasExtension;
import io.kadai.common.test.security.WithAccessId;
import java.time.DayOfWeek;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@ExtendWith(JaasExtension.class)
public class Test {

  @ParameterizedTest
  @EnumSource(DayOfWeek.class)
  @WithAccessId(user = "user-1-1")
  public void test(DayOfWeek day) {}
}

@jamesrdi
Copy link
Contributor

Ok, I am now able to replicate the problem, will look into it

@bruderj15
Copy link
Member Author

bruderj15 commented Feb 14, 2025

Related work: junit-team/junit5#871 & junit-team/junit5#3843

First one seems to be released soon and presents itself as the ideal solution (I guess).
Latter is a more traditional yet clean work-around.

@bruderj15
Copy link
Member Author

bruderj15 commented Feb 14, 2025

Here is the cause of the problem.
We provide additional TestTemplateInvocationContexts to the ones from @ParameterizedTest (addition).

What we would want is: Multiplication.
This will be possible with above mentioned junit-team/junit5#871, called Container-Template.
See their preliminary docs here.

bruderj15 added a commit to bruderj15/kadai-fork that referenced this issue Feb 17, 2025
@bruderj15
Copy link
Member Author

Partial workaround for a single @WithAccessId in #578.

@bruderj15
Copy link
Member Author

Update: junit-team/junit5#4315 for Container-Templates has been merged and is probably released with Junit5@v5.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants