Skip to content

Commit

Permalink
fix: Integration test bootstrap fixed
Browse files Browse the repository at this point in the history
These tests need a bootstraping which is not in the test itself but externally.
This means, these tests cannot be executed standalone, which is bad. If another test runs before, then these tests can run as well, therefore it has not been found before. Normally we run all tests in a suite.
  • Loading branch information
strehle committed Jul 16, 2024
1 parent 8ba95b2 commit e834903
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public UaaUser getUser() {
return user;
}

public UaaTestAccounts getTestAccounts() { return testAccounts; }

private void initializeIfNecessary(FrameworkMethod method, Object target) {
OAuth2ProtectedResourceDetails resource = testAccounts.getAdminClientCredentialsResource();
OAuth2RestTemplate client = createRestTemplate(resource, new DefaultAccessTokenRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class CfScimUserEndpointIntegrationTests {
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class CfUserIdTranslationEndpointIntegrationTests {
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

@BeforeOAuth2Context
@OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class LoginServerSecurityIntegrationTests {
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

private MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public class OpenIdTokenAuthorizationWithApprovalIntegrationTests {
private UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

private RestTemplate client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PasswordChangeEndpointIntegrationTests {
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

private RestOperations client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ public class ScimGroupEndpointsIntegrationTests {
private UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);


private RestTemplate client;
private List<ScimGroup> scimGroups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ public class ScimUserEndpointsIntegrationTests {

private UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

private RestTemplate client;
private List<ScimUser> scimUsers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class UserInfoEndpointIntegrationTests {
private UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

/**
* tests a happy-day flow of the <code>/userinfo</code> endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class AppApprovalIT {
UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

public RestOperations restTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public class SessionLossDuringOauthFlowIT {
UaaTestAccounts testAccounts = UaaTestAccounts.standard(serverRunning);

@Rule
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccounts);
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);

@Rule
public TestAccountSetup testAccountSetup = TestAccountSetup.standard(serverRunning, testAccounts);
public OAuth2ContextSetup context = OAuth2ContextSetup.withTestAccounts(serverRunning, testAccountSetup);

public RestOperations restTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.cloudfoundry.identity.uaa.oauth.token.AccessTokenProvider;
import org.cloudfoundry.identity.uaa.oauth.token.AccessTokenRequest;
import org.cloudfoundry.identity.uaa.oauth.token.DefaultAccessTokenRequest;
import org.cloudfoundry.identity.uaa.test.TestAccountSetup;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.internal.AssumptionViolatedException;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class OAuth2ContextSetup extends TestWatchman {
private final RestTemplateHolder clientHolder;

private final TestAccounts testAccounts;
private final TestAccountSetup testAccountSetup;

private OAuth2AccessToken accessToken;

Expand Down Expand Up @@ -102,8 +104,8 @@ public static OAuth2ContextSetup withEnvironment(RestTemplateHolder clientHolder
* @return a rule that wraps test methods in an OAuth2 context
*/
public static OAuth2ContextSetup withTestAccounts(RestTemplateHolder clientHolder,
TestAccounts testAccounts) {
return new OAuth2ContextSetup(clientHolder, testAccounts, null);
TestAccountSetup testAccountSetup) {
return new OAuth2ContextSetup(clientHolder, testAccountSetup, null);
}

/**
Expand All @@ -130,9 +132,10 @@ public static OAuth2ContextSetup standard(RestTemplateHolder clientHolder) {
}

private OAuth2ContextSetup(RestTemplateHolder clientHolder,
TestAccounts testAccounts, Environment environment) {
TestAccountSetup testAccountSetup, Environment environment) {
this.clientHolder = clientHolder;
this.testAccounts = testAccounts;
this.testAccountSetup = testAccountSetup;
this.testAccounts = testAccountSetup.getTestAccounts();
this.environment = environment;
}

Expand Down Expand Up @@ -238,6 +241,8 @@ public OAuth2ClientContext getOAuth2ClientContext() {

private void initializeIfNecessary(FrameworkMethod method, final Object target) {

testAccountSetup.apply(null, method, target);

final TestClass testClass = new TestClass(target.getClass());
OAuth2ContextConfiguration contextConfiguration = findOAuthContextConfiguration(
method, testClass);
Expand Down

0 comments on commit e834903

Please sign in to comment.