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

Introduce soft assertions with AssertJ #124

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<aspectj.version>1.9.21.2</aspectj.version>
<allure.version>2.25.0</allure.version>
<allure.maven.version>2.12.0</allure.maven.version>
<assertj.version>3.24.2</assertj.version>
</properties>

<repositories>
Expand Down Expand Up @@ -174,6 +175,12 @@
<scope>compile</scope>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down Expand Up @@ -473,6 +480,11 @@
<artifactId>allure-hamcrest</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-assertj</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-okhttp3</artifactId>
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/io/odh/test/e2e/standard/ModelServingST.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import io.skodjob.annotations.SuiteDoc;
import io.skodjob.annotations.TestDoc;
import lombok.SneakyThrows;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -70,7 +70,7 @@
import static io.odh.test.TestConstants.GLOBAL_TIMEOUT;
import static io.odh.test.TestUtils.DEFAULT_TIMEOUT_DURATION;
import static io.odh.test.TestUtils.DEFAULT_TIMEOUT_UNIT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

@SuppressWarnings({"checkstyle:ClassFanOutComplexity"})
@SuiteDoc(
Expand All @@ -91,6 +91,9 @@ public class ModelServingST extends StandardAbstract {

private static final Logger LOGGER = LoggerFactory.getLogger(ModelServingST.class);

@InjectSoftAssertions
private SoftAssertions softly;

private static final String DS_PROJECT_NAME = "test-model-serving";

private final OpenShiftClient kubeClient = (OpenShiftClient) ResourceManager.getKubeClient().getClient();
Expand Down Expand Up @@ -227,11 +230,11 @@ void testMultiModelServerInference() {
ServingRuntime processModelServerTemplate(String templateName) {
TemplateResource templateResource = kubeClient.templates().inNamespace(OdhConstants.CONTROLLERS_NAMESPACE).withName(templateName);
Template template = templateResource.get();
Assertions.assertNotNull(template);
Assertions.assertEquals(0, template.getParameters().size());
assertThat(template).isNotNull();
assertThat(template.getParameters()).isEmpty();

List<HasMetadata> instances = templateResource.process().getItems();
Assertions.assertEquals(1, instances.size());
softly.assertThat(instances).hasSize(1);
return instances.stream().map(it -> {
GenericKubernetesResource genericKubernetesResource = (GenericKubernetesResource) it;
// WORKAROUND(RHOAIENG-4547) ServingRuntime should not have top level `labels` key
Expand Down Expand Up @@ -274,8 +277,8 @@ void queryModelAndCheckMnistInference(String baseUrl, String modelInputPath, Str
.build();
HttpResponse<String> inferResponse = httpClient.send(inferRequest, HttpResponse.BodyHandlers.ofString());

assertThat(inferResponse.body(), inferResponse.statusCode(), Matchers.is(200));
assertThat(inferResponse.body(), Matchers.containsString(expectedModelOutput));
softly.assertThat(inferResponse.statusCode()).as(inferResponse.body()).isEqualTo(200);
softly.assertThat(inferResponse.body()).contains(expectedModelOutput);
}

private <T> T castResource(KubernetesResource value, Class<T> type) {
Expand Down
34 changes: 18 additions & 16 deletions src/test/java/io/odh/test/e2e/standard/PipelineServerST.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,18 @@
import io.skodjob.annotations.Step;
import io.skodjob.annotations.SuiteDoc;
import io.skodjob.annotations.TestDoc;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

@SuiteDoc(
description = @Desc("Verifies simple setup of ODH by spin-up operator, setup DSCI, and setup DSC."),
Expand All @@ -71,6 +70,9 @@
public class PipelineServerST extends StandardAbstract {
private static final Logger LOGGER = LoggerFactory.getLogger(PipelineServerST.class);

@InjectSoftAssertions
private SoftAssertions softly;

private static final String DS_PROJECT_NAME = "test-pipelines";

private final ResourceManager resourceManager = ResourceManager.getInstance();
Expand Down Expand Up @@ -231,18 +233,18 @@ void testUserCanCreateRunAndDeleteADSPipelineFromDSProject() throws IOException
KFPv1Client.Pipeline importedPipeline = kfpv1Client.importPipeline(pipelineTestName, pipelineTestDesc, pipelineTestFilepath);

List<KFPv1Client.Pipeline> pipelines = kfpv1Client.listPipelines();
assertThat(pipelines.stream().map(p -> p.name).collect(Collectors.toList()), Matchers.contains(pipelineTestName));
assertThat(pipelines).extracting(p -> p.name).contains(pipelineTestName);

KFPv1Client.PipelineRun pipelineRun = kfpv1Client.runPipeline(pipelineTestRunBasename, importedPipeline.id, "Immediate");
Assertions.assertTrue(pipelineRun.pipelineSpec.workflowManifest.contains(pipelineWorkflowName));
assertThat(pipelineRun.pipelineSpec.workflowManifest).contains(pipelineWorkflowName);

kfpv1Client.waitForPipelineRun(pipelineRun.id);

List<KFPv1Client.PipelineRun> statuses = kfpv1Client.getPipelineRunStatus();
assertThat(statuses.stream()
.filter(run -> run.id.equals(pipelineRun.id))
.map(run -> run.status)
.findFirst().get(), Matchers.is("Succeeded"));
assertThat(statuses)
.filteredOn(run -> run.id.equals(pipelineRun.id))
.extracting(run -> run.status)
.singleElement().isEqualTo("Succeeded");

checkPipelineRunK8sDeployments(prjTitle, pipelineWorkflowName + "-" + pipelineRun.id.substring(0, 5));

Expand All @@ -261,16 +263,16 @@ private void checkPipelineRunK8sDeployments(String prjTitle, String workflowName
).map(pod -> pod.list().getItems()).toList();

for (List<Pod> pods : tektonTaskPods) {
Assertions.assertEquals(1, pods.size());
Assertions.assertEquals("Succeeded", pods.get(0).getStatus().getPhase());
softly.assertThat(pods).hasSize(1);
softly.assertThat(pods.get(0).getStatus().getPhase()).isEqualTo("Succeeded");

List<ContainerStatus> containerStatuses = pods.get(0).getStatus().getContainerStatuses();
Assertions.assertNotEquals(0, containerStatuses.size());
softly.assertThat(containerStatuses).isNotEmpty();
for (ContainerStatus containerStatus : containerStatuses) {
ContainerStateTerminated terminated = containerStatus.getState().getTerminated();
Assertions.assertNotNull(terminated);
Assertions.assertEquals(0, terminated.getExitCode());
Assertions.assertEquals("Completed", terminated.getReason());
softly.assertThat(terminated).isNotNull();
softly.assertThat(terminated.getExitCode()).isEqualTo(0);
softly.assertThat(terminated.getReason()).isEqualTo("Completed");
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions src/test/java/io/odh/test/e2e/standard/PipelineV2ServerST.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
import io.skodjob.annotations.Step;
import io.skodjob.annotations.SuiteDoc;
import io.skodjob.annotations.TestDoc;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -69,9 +69,8 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

@SuppressWarnings({"checkstyle:ClassFanOutComplexity"})
@SuiteDoc(
Expand All @@ -91,6 +90,9 @@
public class PipelineV2ServerST extends StandardAbstract {
private static final Logger LOGGER = LoggerFactory.getLogger(PipelineV2ServerST.class);

@InjectSoftAssertions
private SoftAssertions softly;

private static final String DS_PROJECT_NAME = "test-pipelines";

private final KubernetesClient client = ResourceManager.getKubeClient().getClient();
Expand Down Expand Up @@ -302,7 +304,7 @@ void testUserCanOperateDSv2PipelineFromDSProject() throws IOException {
KFPv2Client.Pipeline importedPipeline = kfpClient.importPipeline(pipelineTestName, pipelineTestDesc, pipelineTestFilepath);

List<KFPv2Client.Pipeline> pipelines = kfpClient.listPipelines();
assertThat(pipelines.stream().map(p -> p.displayName).collect(Collectors.toList()), Matchers.contains(pipelineTestName));
assertThat(pipelines).extracting(p -> p.displayName).contains(pipelineTestName);

Map<String, Object> parameters = Map.of(
"min_max_scaler", false,
Expand All @@ -314,10 +316,10 @@ void testUserCanOperateDSv2PipelineFromDSProject() throws IOException {
kfpClient.waitForPipelineRun(pipelineRun.runId);

List<KFPv2Client.PipelineRun> statuses = kfpClient.getPipelineRunStatus();
assertThat(statuses.stream()
.filter(run -> run.runId.equals(pipelineRun.runId))
.map(run -> run.state)
.findFirst().orElseThrow(), Matchers.is("SUCCEEDED"));
assertThat(statuses)
.filteredOn(run -> run.runId.equals(pipelineRun.runId))
.extracting(run -> run.state)
.singleElement().isEqualTo("SUCCEEDED");

checkPipelineRunK8sDeployments(prjTitle, pipelineRun.runId);

Expand All @@ -342,18 +344,18 @@ private static void deletePreexistingPipelinesAndVersions(KFPv2Client kfpClient)
@io.qameta.allure.Step
private void checkPipelineRunK8sDeployments(String prjTitle, String runId) {
List<Pod> argoTaskPods = client.pods().inNamespace(prjTitle).withLabel("pipeline/runid=" + runId).list().getItems();
Assertions.assertEquals(7, argoTaskPods.size());
softly.assertThat(argoTaskPods).hasSize(7);

for (Pod pod : argoTaskPods) {
Assertions.assertEquals("Succeeded", pod.getStatus().getPhase());
softly.assertThat(pod.getStatus().getPhase()).isEqualTo("Succeeded");

List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
Assertions.assertNotEquals(0, containerStatuses.size());
softly.assertThat(containerStatuses).isNotEmpty();
for (ContainerStatus containerStatus : containerStatuses) {
ContainerStateTerminated terminated = containerStatus.getState().getTerminated();
Assertions.assertNotNull(terminated);
Assertions.assertEquals(0, terminated.getExitCode());
Assertions.assertEquals("Completed", terminated.getReason());
softly.assertThat(terminated).isNotNull();
softly.assertThat(terminated.getExitCode()).isEqualTo(0);
softly.assertThat(terminated.getReason()).isEqualTo("Completed");
}
}

Expand All @@ -369,7 +371,7 @@ private void checkPipelineRunK8sDeployments(String prjTitle, String runId) {
List<String> argoNodeNames = argoTaskPods.stream()
.map(pod -> pod.getMetadata().getAnnotations().get("workflows.argoproj.io/node-name"))
.toList();
Assertions.assertIterableEquals(expectedNodeNames.stream().sorted().toList(), argoNodeNames.stream().sorted().toList(), argoNodeNames.toString());
softly.assertThat(argoNodeNames).containsExactlyInAnyOrderElementsOf(expectedNodeNames);
}

@io.qameta.allure.Step
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/io/odh/test/e2e/standard/StandardAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.odh.test.install.BundleInstall;
import io.odh.test.install.InstallTypes;
import io.odh.test.install.OlmInstall;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -26,6 +27,7 @@
@Tag(TestSuite.STANDARD)
@ExtendWith(OdhResourceCleaner.class)
@ExtendWith(ResourceManagerDeleteHandler.class)
@ExtendWith(SoftAssertionsExtension.class)
public abstract class StandardAbstract extends Abstract {

private static final Logger LOGGER = LoggerFactory.getLogger(StandardAbstract.class);
Expand Down
Loading