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

SmallRyeHealthCheckEnricherTest seems to be using mock refactored wit… #3529

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,35 @@
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import org.eclipse.jkube.kit.common.Dependency;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.config.resource.PlatformMode;
import org.eclipse.jkube.kit.config.resource.ProcessorConfig;
import org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import java.io.File;
import java.util.Collections;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Supplier;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class SmallRyeHealthCheckEnricherTest {
private JKubeEnricherContext context;
private JavaProject javaProject;
private Properties properties;
private KubernetesListBuilder klb;


@BeforeEach
void setup() {
properties = new Properties();
ProcessorConfig processorConfig = new ProcessorConfig();
klb = new KubernetesListBuilder();

klb.addToItems(new DeploymentBuilder()
.editOrNewSpec()
.editOrNewTemplate()
Expand All @@ -62,14 +64,16 @@ void setup() {
.endSpec()
.build());

context = mock(JKubeEnricherContext.class, RETURNS_DEEP_STUBS);
javaProject = mock(JavaProject.class, RETURNS_DEEP_STUBS);
when(context.getProject()).thenReturn(javaProject);
when(context.getProperties()).thenReturn(properties);
when(context.getConfiguration().getProcessorConfig()).thenReturn(processorConfig);
when(javaProject.getProperties()).thenReturn(properties);
when(javaProject.getBaseDirectory()).thenReturn(new File("/tmp/ignore"));
when(javaProject.getOutputDirectory()).thenReturn(new File("/tmp/ignore"));
javaProject = JavaProject.builder()
.properties(properties)
.outputDirectory(new File("/tmp/ignore"))
.dependenciesWithTransitive(new ArrayList<>())
.build();
context = JKubeEnricherContext.builder()
.log(new KitLogger.SilentLogger())
.project(javaProject)
.processorConfig(new ProcessorConfig())
.build();
}

@Test
Expand Down Expand Up @@ -157,21 +161,24 @@ void create_withMicroprofileHealthAndSmallRyeWithEnricherConfiguration_shouldPro
}

private void withMicroprofileHealthTransitiveDependency(String microProfileVersion) {
when(javaProject.getDependenciesWithTransitive()).thenReturn(Collections.singletonList(Dependency.builder()
final List<Dependency> deps = new ArrayList<>(javaProject.getDependencies());
deps.add(Dependency.builder()
.groupId("org.eclipse.microprofile.health")
.artifactId("microprofile-health-api")
.version(microProfileVersion)
.build()));
.build());
javaProject.setDependenciesWithTransitive(deps);
}

private void withSmallRyeDependency() {
when(javaProject.getDependencies()).thenReturn(Collections.singletonList(Dependency.builder()
.groupId("io.smallrye")
.artifactId("smallrye-health")
.build()));
final List<Dependency> deps = new ArrayList<>(javaProject.getDependencies());
deps.add(Dependency.builder()
.groupId("io.smallrye")
.artifactId("smallrye-health")
.build());
javaProject.setDependencies(deps);
}


private void assertProbesAdded(String livenessScheme, String livenessPath, String readyScheme, String readyPath, String startedScheme, String startedPath) {
Container container = getFirstContainerFromDeployment();
assertProbe(container::getLivenessProbe, livenessScheme, livenessPath);
Expand Down
Loading