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

Issue 3404 replace mockito with actual object in wildflyjarhealthcheckenrichertest #3416

Conversation

ShivamChavan01
Copy link
Contributor

Description

Replaced Mockito.mock with actual object creation in WildflyJARHealthCheckEnricherTest

Fixes #3404

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • I have read the contributing guidelines
  • I signed-off my commit with a user that has signed the Eclipse Contributor Agreement
  • My code follows the style guidelines of this project
  • I Keep It Small and Simple: The smaller the PR is, the easier it is to review and have it merged
  • I use conventional commits in my commit messages
  • I have performed a self-review of my code
  • I Added CHANGELOG entry
  • I have updated the documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@manusa
Copy link
Member

manusa commented Oct 1, 2024

Eclipse JKube CI Report

Started new GH workflow run for #3416 (2024-10-10T05:11:46Z)

⚙️ JKube E2E Tests (11261508645)

Test results

✔️ Test reports (Windows)
[✓] WindowsITCase - k8sBuild - k8s:build, should create image
[✓] WindowsITCase - k8sPush - k8s:push, should push image to remote registry
[✓] WindowsITCase - k8sResource - k8s:resource, should create manifests
[✓] WindowsITCase - ocResource - oc:resource, should create manifests
[✓] WindowsITCase - k8sHelm - k8s:helm, should create Helm charts
[✓] WindowsITCase - ocHelm - oc:helm, should create Helm charts
[✓] All tests (6) passed successfully!!!

✔️ Test reports (OpenShift v3.10.0-quarkus)
[✓] QuarkusOcTraceEnabledITCase - ocBuild - oc:build, with org.slf4j.simpleLogger.defaultLogLevel=trace, should create image and print trace logs
[✓] QuarkusOcTraceEnabledITCase - ocResource - oc:resource, should create manifests
[✓] QuarkusOcITCase - ocBuild - oc:build, should create image
[✓] QuarkusOcITCase - ocResource - oc:resource, should create manifests
[✓] QuarkusOcTraceEnabledITCase - ocApply - oc:apply, with org.slf4j.simpleLogger.defaultLogLevel=trace, should deploy pod and service and print trace logs
[✓] QuarkusOcITCase - ocHelm - oc:helm, should create Helm charts
[✓] QuarkusOcTraceEnabledITCase - ocLog - oc:log, with org.slf4j.simpleLogger.defaultLogLevel=trace, should retrieve log and print trace logs
[✓] QuarkusOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] QuarkusOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] QuarkusOcTraceEnabledITCase - ocUndeploy - oc:undeploy, with org.slf4j.simpleLogger.defaultLogLevel=trace, should delete all applied resources and print trace logs
[✓] All tests (5) passed successfully!!!

✔️ Test reports (OpenShift v3.10.0-webapp)
[✓] JettyOcITCase - ocBuild - oc:build, should create image
[✓] JettyOcITCase - ocResource - oc:resource, should create manifests
[✓] ZeroConfigOcITCase - ocBuild - oc:build, should create image
[✓] ZeroConfigOcITCase - ocResource - oc:resource, should create manifests
[✓] WildFlyOcITCase - ocBuild - oc:build, should create image
[✓] WildFlyOcITCase - ocResource - oc:resource, should create manifests
[✓] WildFlyOcDockerModeITCase - ocBuild - oc:build, should create image using docker
[✓] WildFlyOcDockerModeITCase - ocResource - k8s:resource, should create manifests
[✓] JettyOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] JettyOcITCase - ocLog - oc:log, should retrieve log
[✓] ZeroConfigOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] ZeroConfigOcITCase - testNodePortResponse - Service as NodePort response should return String
[✓] JettyOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] ZeroConfigOcITCase - ocLog - oc:log, should retrieve log
[✓] ZeroConfigOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] WildFlyOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] WildFlyOcITCase - ocLog - oc:log, should retrieve logs
[✓] WildFlyOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] WildFlyOcDockerModeITCase - ocApply - oc:apply, should deploy pod and service
[✓] WildFlyOcDockerModeITCase - ocLog - oc:log, should retrieve logs
[✓] WildFlyOcDockerModeITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] All tests (5) passed successfully!!!

✔️ Test reports (OpenShift v3.10.0-springboot)
[✓] HelmConfigOcITCase - ocResource - oc:resource, no specified profile, should create default resource manifests
[✓] HelmConfigOcITCase - ocHelm - oc:helm, should create Helm charts
[✓] HelmConfigOcITCase - ocHelmPush - oc:helm-push, should push the charts
[✓] HelmConfigOcITCase - ocHelmInstall - oc:helm-install, should install the charts
[✓] HelmConfigOcITCase - ocHelmUninstall - oc:helm-uninstall, should uninstall the charts
[✓] ZeroConfigOcITCase - ocBuild - oc:build, should create image
[✓] HelmConfigOcITCase - ocHelmUninstall_whenNoReleasePresent_thenErrorMessageDisplayed - oc:helm-uninstall, no release present, display error message
[✓] ZeroConfigOcITCase - ocResource - oc:resource, should create manifests
[✓] ZeroConfigOcGradleITCase - ocBuild - ocBuild, should create image
[✓] ZeroConfigOcGradleITCase - ocResource - ocResource, should create manifests
[✓] CompleteOcDockerITCase - ocBuild - oc:build, with jkube.build.strategy=docker, should create image
[✓] CompleteOcDockerITCase - ocResource - oc:resource, should create manifests
[✓] WatchOcITCase - watch_whenSourceModified_shouldLiveReloadChanges - watch, SHOULD hot reload application on changes
[✓] LayeredJarDisabledOcDockerITCase - ocBuild - oc:build, with jkube.build.strategy=docker, should create image
[✓] LayeredJarDisabledOcDockerITCase - ocResource - oc:resource, should create manifests
[✓] ZeroConfigOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] ZeroConfigOcITCase - ocHelm - oc:helm, should create Helm charts
[✓] ZeroConfigOcITCase - ocLog - oc:log, should retrieve log
[✓] ZeroConfigOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] ZeroConfigOcGradleITCase - ocApply - ocApply, should deploy pod and service
[✓] ZeroConfigOcGradleITCase - ocHelm - ocHelm, should create Helm charts
[✓] ZeroConfigOcGradleITCase - ocLog - ocLog, should retrieve log
[✓] ZeroConfigOcGradleITCase - ocUndeploy - ocUndeploy, should delete all applied resources
[✓] CompleteOcDockerITCase - ocApply - oc:apply, should deploy pod and service
[✓] CompleteOcDockerITCase - ocLog - oc:log, should retrieve log
[✓] LayeredJarDisabledOcDockerITCase - ocApply - oc:apply, should deploy pod and service
[✓] CompleteOcDockerITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] LayeredJarDisabledOcDockerITCase - ocLog - oc:log, should retrieve log
[✓] LayeredJarDisabledOcDockerITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] All tests (5) passed successfully!!!

✔️ Test reports (OpenShift v3.10.0-other)
[✓] WildflyJarOcITCase - ocBuild - oc:build, should create image
[✓] WildflyJarOcITCase - ocResource - oc:resource, should create manifests
[✓] ThorntailOcITCase - ocBuild - oc:build, should create image
[✓] ThorntailOcITCase - ocResource - oc:resource, should create manifests
[✓] OpenLibertyOcITCase - ocBuild - oc:build, should create image
[✓] OpenLibertyOcITCase - ocResource - oc:resource, should create manifests
[✓] DslOcGradleITCase - ocBuild - ocBuild, should create image
[✓] DslOcGradleITCase - ocResource - ocResource, should create manifests
[✓] VertxOcITCase - ocBuild - oc:build, should create image
[✓] VertxOcITCase - ocResource - oc:resource, should create manifests
[✓] KarafOcITCase - ocBuild - oc:build, should create image
[✓] KarafOcITCase - ocResource - oc:resource, should create resource manifests
[✓] WildflyJarOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] WildflyJarOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] ThorntailOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] ThorntailOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] OpenLibertyOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] OpenLibertyOcITCase - ocLog - oc:log, should retrieve log
[✓] DslOcGradleITCase - ocApply - ocApply, should deploy pod and service
[✓] OpenLibertyOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] DslOcGradleITCase - ocHelm - ocHelm, should create Helm charts
[✓] DslOcGradleITCase - ocLog - ocLog, should retrieve log
[✓] DslOcGradleITCase - ocUndeploy - ocUndeploy, should delete all applied resources
[✓] VertxOcITCase - ocApply - oc:apply, should deploy pod and service
[✓] VertxOcITCase - k8sLog - oc:log, should retrieve log
[✓] VertxOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] KarafOcITCase - ocApply - oc:apply, should create pod, service and route
[✓] KarafOcITCase - ocLog - oc:log, should retrieve log
[✓] KarafOcITCase - ocUndeploy - oc:undeploy, should delete all applied resources
[✓] All tests (5) passed successfully!!!

@ShivamChavan01
Copy link
Contributor Author

Hi @rohanKanojia,

I’ve replaced the parts you suggested, but I'm facing challenges with replacing some Mockito.when statements with actual objects. Could you please guide me on how to proceed with these changes?

LIKE

when(project.getPlugins()).thenReturn(lst);
when(context.getProject()).thenReturn(project);
when(context.getConfiguration()).thenReturn(configBuilder.build());

@rohanKanojia
Copy link
Member

@ShivamChavan01 : You can convert an object to builder using toBuilder method and then invoke builder methods for stuff you were mocking earlier:
So the first line can be converted to:

        context = context.toBuilder()
          .processorConfig(c)
          .build();

and similarly second pair of mocks can be converted like this:

        context = context.toBuilder()
          .project(project.toBuilder()
            .plugins(lst)
            .build())
          .processorConfig(c)
          .build();

Could you please test these if they're working?

@manusa manusa added this to the 1.18.0 milestone Oct 2, 2024 — with automated-tasks
.returns(initialDelay, Probe::getInitialDelaySeconds)
.returns(failureThreshold, Probe::getFailureThreshold)
.returns(successThreshold, Probe::getSuccessThreshold)
.returns(periodSeconds, Probe::getPeriodSeconds);
Copy link
Member

Choose a reason for hiding this comment

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

Could you please revert these formatting changes?

Copy link
Contributor Author

@ShivamChavan01 ShivamChavan01 Oct 3, 2024

Choose a reason for hiding this comment

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

  • Yeah I was formatting the code for some lines but it got effected I'll revert these changes

@rohanKanojia
Copy link
Member

@ShivamChavan01 : Build seems to be failing:

[ERROR] Failures: 
[ERROR]   WildflyJARHealthCheckEnricherTest.cloudConfiguration_withWildflyJarAfter25_0shouldAdd_startupProbe:128->assertHttpGet:319 
Expecting actual not to be null
[ERROR]   WildflyJARHealthCheckEnricherTest.withCustomConfigurationComingFromConf_withWildflyJarAfter25_0shouldAdd_startupProbe:193->assertProbeAdded:329->assertHttpGet:319 
Expecting actual not to be null

Could you please check these failures?

ShivamChavan01 and others added 2 commits October 4, 2024 17:12
…ith-actual-object-in-wildflyjarhealthcheckenrichertest
…actual-object-in-wildflyjarhealthcheckenrichertest' into issue-3404-replace-mockito-with-actual-object-in-wildflyjarhealthcheckenrichertest

# Conflicts:
#	jkube-kit/jkube-kit-openliberty/src/test/java/org/eclipse/jkube/openliberty/OpenLibertyUtilsTest.java
@ShivamChavan01
Copy link
Contributor Author

Hey @rohanKanojia im getting these errors
constructor Config in enum org.eclipse.jkube.wildfly.jar.enricher.WildflyJARHealthCheckEnricher.Config cannot be applied to given types;
image

because of these lines in

SCHEME("scheme", "HTTP"),
PORT("port", "9990"),
FAILURE_THRESHOLD("failureThreshold","3"),
SUCCESS_THRESHOLD("successThreshold","1"),
LIVENESS_INITIAL_DELAY("livenessInitialDelay", "60"),
READINESS_INITIAL_DELAY("readinessInitialDelay", "10"),
STARTUP_INITIAL_DELAY("startupInitialDelay", "10"),
READINESS_PATH("readinessPath", DEFAULT_READINESS_PATH),
LIVENESS_PATH("livenessPath", DEFAULT_LIVENESS_PATH),
STARTUP_PATH("startupPath", DEFAULT_STARTUP_PATH),
PERIOD_SECONDS("periodSeconds", "10"),
ENFORCE_PROBES("enforceProbes","false");

@rohanKanojia
Copy link
Member

@ShivamChavan01 : Do you have installed Lombok plugin in your IntelliJ?

@ShivamChavan01
Copy link
Contributor Author

@ShivamChavan01 : Do you have installed Lombok plugin in your IntelliJ?

I had previously installed the Lombok plugin, but since then, I've uninstalled it and reinstalled it. Unfortunately, I'm still encountering issues, and it hasn't resolved the problem.

when(context.getProject()).thenReturn(project);
when(context.getConfiguration()).thenReturn(configBuilder.build());
context = context.toBuilder()
.project(project.toBuilder()
Copy link
Member

Choose a reason for hiding this comment

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

Rather than creating a builder instance from member field project you should create it from context itself so that you don't lose changes done in context.getProject() after test setup

Suggested change
.project(project.toBuilder()
.project(context.getProject().toBuilder()

when(context.getProject()).thenReturn(project);
project = JavaProject.builder().build();
context = JKubeEnricherContext.builder()
.project(context.getProject())
Copy link
Member

Choose a reason for hiding this comment

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

context is not initialized at this point.

Suggested change
.project(context.getProject())
.project(project)

Copy link

sonarcloud bot commented Oct 9, 2024

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@manusa manusa merged commit 1e04e60 into eclipse-jkube:master Oct 10, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WildflyJARHealthCheckEnricherTest : Replace Mockito.mock by creating actual object
3 participants