Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stianst
Copy link
Contributor

@stianst stianst commented Jul 18, 2024

Signed-off-by: stianst [email protected]

@stianst stianst requested a review from a team as a code owner July 18, 2024 12:30
@stianst stianst force-pushed the testpoc-github-action branch 2 times, most recently from f43629e to 80e5949 Compare July 18, 2024 13:30
Copy link
Contributor

@lhanusov lhanusov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here are few suggestions, otherwise it looks good to me 👍


@Override
public WebDriver getWebDriver() {
return new ChromeDriver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will help to find Selenium Web elements properly:
ChromeOptions options = new ChromeOptions();
options.setImplicitWaitTimeout(Duration.ofMillis(1000));
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
return new ChromeDriver(options);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to AbstractWebDriverSupplier

public String getAlias() {
return "firefox";
public WebDriver getWebDriver() {
return new FirefoxDriver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for chrome:
FirefoxOptions options = new FirefoxOptions();
options.setImplicitWaitTimeout(Duration.ofMillis(1000));
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
return new `FirefoxDriver(options);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to AbstractWebDriverSupplier

public class ChromeWebDriverSupplier extends AbstractWebDriverSupplier {

@Override
public String getAlias() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be also defined as abstract in AbstractWebDriverSupplier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, alias is optional, the default name for a supplier will be class.getSimpleName

@Override
public void close(WebDriver instance) {
instance.quit();
public String getAlias() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be also defined as abstract in AbstractWebDriverSupplier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, alias is optional, the default name for a supplier will be class.getSimpleName

} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Thread.sleep(1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once Chrome and Firefox options are in place this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

return getValue(registry, annotation);
void initValue(InstanceContext<T, S> instanceContext);

default LifeCycle lifeCycle(S annotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between lifecycle and getDefaultLifecycle? In AbstractWebDriverSupplier is lifecycle and in AbstractKeycloakServerSupplier only getDefaultLifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registry calls getLifeCycle(annotation) to get the life cycle a given instance should have, by default that will look for a method lifecycle on the annotation and use that value if present, otherwise it will call getDefaultLifeCycle. That basically means we can have a consistent approach to the lifecycle in annotations.

An alternative approach would just be to let the suppliers handle it all; and return the lifecycle from the annotation if present, or the default lifecycle. Then we'd only have getLifeCycle (without a default implementation) and remove getDefaultLifecycle.

@stianst stianst force-pushed the testpoc-github-action branch from 6d6de67 to abdc736 Compare July 19, 2024 08:24
steps:
- uses: actions/checkout@v4

- id: integration-test-setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit the id if you are not referencing it anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, just copy/paste from elsewhere though. Having id/name makes the run a bit more readable though as the output with reusable actions is not very elegant without it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd just add a human readable name to it and call it a day

public class NoAdminUserKeycloakTestServerConfig implements KeycloakTestServerConfig {

@Override
public Optional<String> adminUserName() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of my optionals? 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have their place, but found it easier to not have it in this case, as it's both simpler to just return null, and found the checks when setting the values simpler without optional stuff ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a matter of personal preference I guess. However using optionals forces you to handle nullability, whereas nulls do not. Also:

serverConfig.adminUserName().ifPresentOrElse(
  username -> System.setProperty("keycloakAdmin", username),
  () -> System.getProperties().remove("keycloakAdmin")
);

return getValue(registry, annotation);
T getValue(InstanceContext<T, S> instanceContext);

default LifeCycle getLifeCycle(S annotation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do:

if (annotation == null) {
  return getDefaultLifecycle();
}

// The rest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think it matters too much - down to personal preference I guess ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh for sure, you know how much I hate nesting, this is just a prime example of an early return pattern.

@stianst stianst merged commit 7216967 into keycloak:main Jul 19, 2024
@stianst stianst deleted the testpoc-github-action branch July 19, 2024 10:23
stianst added a commit to stianst/keycloak that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants