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

Continue refactoring of the test module #10553

Merged
Merged
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
4 changes: 2 additions & 2 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<!-- The api module is currently not ready or Javadoc checks-->
<suppress checks="(JavadocMethod|JavadocType|JavadocVariable|MissingJavadocType|MissingJavadocMethod)" files="api[/\\]src[/\\]main[/\\]java[/\\]io[/\\]strimzi[/\\].*"/>

<!-- The test module is currently not ready or Javadoc checks-->
<suppress checks="(JavadocMethod|JavadocType|JavadocVariable|MissingJavadocType|MissingJavadocMethod)" files="test[/\\]src[/\\]main[/\\]java[/\\]io[/\\]strimzi[/\\].*"/>
<!-- The systemtest module is currently not ready or Javadoc checks-->
<suppress checks="(JavadocMethod|JavadocType|JavadocVariable|MissingJavadocType|MissingJavadocMethod)" files="systemtest[/\\]src[/\\]main[/\\]java[/\\]io[/\\]strimzi[/\\].*"/>

</suppressions>
5 changes: 0 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.strimzi.test.TestUtils;
import io.strimzi.test.ReadWriteUtils;
import io.strimzi.test.interfaces.TestSeparator;
import org.junit.jupiter.api.TestInstance;

Expand Down Expand Up @@ -62,11 +62,11 @@ private void createDelete(File resourceFile) {
}

protected <T extends CustomResource> void createScaleDelete(Class<T> resourceClass, String resource) {
T model = TestUtils.fromYaml(resource, resourceClass);
T model = ReadWriteUtils.readObjectFromYamlFileInResources(resource, resourceClass);
String apiVersion = model.getApiVersion();
String kind = model.getKind();
String resourceName = model.getMetadata().getName();
String resourceYamlAsString = TestUtils.toYamlString(model);
String resourceYamlAsString = ReadWriteUtils.writeObjectToYamlString(model);
createScaleDelete(apiVersion, kind, resourceName, resourceYamlAsString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.CustomResource;
import io.strimzi.test.TestUtils;
import io.strimzi.test.ReadWriteUtils;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -24,23 +24,23 @@ protected AbstractCrdTest(Class<R> crdClass) {
}

protected void assertDesiredResource(R actual, String expectedResource) {
String content = TestUtils.readResource(getClass(), expectedResource);
String content = ReadWriteUtils.readFileFromResources(getClass(), expectedResource);
assertThat("The resource " + expectedResource + " does not exist", content, is(notNullValue()));

String ssStr = TestUtils.toYamlString(actual);
String ssStr = ReadWriteUtils.writeObjectToYamlString(actual);
assertThat(ssStr.trim(), is(content.trim()));
}

@Test
public void roundTrip() {
String resourceName = crdClass.getSimpleName() + ".yaml";
R model = TestUtils.fromYaml(resourceName, crdClass);
R model = ReadWriteUtils.readObjectFromYamlFileInResources(resourceName, crdClass);
assertThat("The classpath resource " + resourceName + " does not exist", model, is(notNullValue()));

ObjectMeta metadata = model.getMetadata();
assertThat(metadata, is(notNullValue()));
assertDesiredResource(model, crdClass.getSimpleName() + ".out.yaml");
assertDesiredResource(TestUtils.fromYamlString(TestUtils.toYamlString(model), crdClass), crdClass.getSimpleName() + ".out.yaml");
assertDesiredResource(ReadWriteUtils.readObjectFromYamlString(ReadWriteUtils.writeObjectToYamlString(model), crdClass), crdClass.getSimpleName() + ".out.yaml");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package io.strimzi.api.kafka.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import io.fabric8.kubernetes.api.model.KubernetesResource;
import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.strimzi.test.ReadWriteUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.Test;

Expand All @@ -25,7 +24,6 @@

import static org.junit.jupiter.api.Assertions.fail;


/**
* The purpose of this test is to check that all the resources in the
* {@code ../packaging/examples} directory are valid.
Expand Down Expand Up @@ -57,8 +55,7 @@ private void validateRecursively(File directory) {

private void validate(File f) {
try {
ObjectMapper mapper = new YAMLMapper();
final String content = TestUtils.readFile(f);
final String content = ReadWriteUtils.readFile(f);
validate(content);
} catch (Exception | AssertionError e) {
throw new AssertionError("Invalid example yaml in " + f.getPath() + ": " + e.getMessage(), e);
Expand Down
15 changes: 9 additions & 6 deletions api/src/test/java/io/strimzi/api/kafka/model/JvmOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
package io.strimzi.api.kafka.model;

import io.strimzi.api.kafka.model.common.JvmOptions;
import io.strimzi.test.TestUtils;
import io.strimzi.test.ReadWriteUtils;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;

public class JvmOptionsTest {
@Test
public void testSetXmxXms() {
JvmOptions opts = TestUtils.fromYamlString("-Xmx: 2g\n" +
JvmOptions opts = ReadWriteUtils.readObjectFromYamlString("-Xmx: 2g\n" +
"-Xms: 1g",
JvmOptions.class);

Expand All @@ -24,25 +27,25 @@ public void testSetXmxXms() {

@Test
public void testEmptyXmxXms() {
JvmOptions opts = TestUtils.fromYamlString("{}", JvmOptions.class);
JvmOptions opts = ReadWriteUtils.readObjectFromYamlString("{}", JvmOptions.class);

assertThat(opts.getXms(), is(nullValue()));
assertThat(opts.getXmx(), is(nullValue()));
}

@Test
public void testXx() {
JvmOptions opts = TestUtils.fromYamlString("-XX:\n" +
JvmOptions opts = ReadWriteUtils.readObjectFromYamlString("-XX:\n" +
" key1: value1\n" +
" key2: value2\n" +
" key3: true\n" +
" key4: true\n" +
" key5: 10\n",
JvmOptions.class);

assertThat(opts.getXx(), is(TestUtils.map("key1", "value1", "key2", "value2", "key3", "true", "key4", "true", "key5", "10")));
assertThat(opts.getXx(), is(Map.of("key1", "value1", "key2", "value2", "key3", "true", "key4", "true", "key5", "10")));

opts = TestUtils.fromYamlString("{}", JvmOptions.class);
opts = ReadWriteUtils.readObjectFromYamlString("{}", JvmOptions.class);

assertThat(opts.getXx(), is(nullValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io.strimzi.api.kafka.model.common.jmx.KafkaJmxAuthenticationPassword;
import io.strimzi.api.kafka.model.common.jmx.KafkaJmxOptions;
import io.strimzi.test.TestUtils;
import io.strimzi.test.ReadWriteUtils;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand All @@ -20,7 +20,7 @@
public class KafkaJmxOptionsTest {
@Test
public void testAuthentication() {
KafkaJmxOptions opts = TestUtils.fromYamlString(
KafkaJmxOptions opts = ReadWriteUtils.readObjectFromYamlString(
"authentication:\n" +
" type: password",
KafkaJmxOptions.class);
Expand All @@ -31,7 +31,7 @@ public void testAuthentication() {

@Test
public void testNoJmxOpts() {
KafkaJmxOptions opts = TestUtils.fromYamlString("{}", KafkaJmxOptions.class);
KafkaJmxOptions opts = ReadWriteUtils.readObjectFromYamlString("{}", KafkaJmxOptions.class);

assertThat(opts.getAuthentication(), is(nullValue()));
assertThat(opts.getAdditionalProperties(), is(Collections.emptyMap()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.strimzi.api.annotations.ApiVersion;
import io.strimzi.api.annotations.VersionRange;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -59,10 +60,10 @@ public void v1Beta2IsStructuralWithCrdV1() {

private void assertApiVersionsAreStructural(String crdName, String crdPath, VersionRange<ApiVersion> shouldBeStructural) {
try {
TestUtils.createCrd(client, crdName, crdPath);
CrdUtils.createCrd(client, crdName, crdPath);
assertApiVersionsAreStructuralInApiextensionsV1(crdName, shouldBeStructural);
} finally {
TestUtils.deleteCrd(client, crdName);
CrdUtils.deleteCrd(client, crdName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.strimzi.api.kafka.model.AbstractCrdIT;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.ReadWriteUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -85,7 +87,7 @@ void testKafkaBridgeWithOpenTelemetryTracing() {
void testLoadKafkaBridgeWithWrongTracingType() {
Throwable exception = assertThrows(
RuntimeException.class,
() -> TestUtils.fromYaml("KafkaBridge-with-wrong-tracing-type.yaml", KafkaBridge.class));
() -> ReadWriteUtils.readObjectFromYamlFileInResources("KafkaBridge-with-wrong-tracing-type.yaml", KafkaBridge.class));

assertThat(exception.getMessage(), allOf(
containsStringIgnoringCase("Could not resolve type id 'wrongtype'"),
Expand Down Expand Up @@ -119,13 +121,13 @@ void testKafkaBridgeWithMetrics() {
@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
TestUtils.createCrd(client, KafkaBridge.CRD_NAME, TestUtils.CRD_KAFKA_BRIDGE);
CrdUtils.createCrd(client, KafkaBridge.CRD_NAME, CrdUtils.CRD_KAFKA_BRIDGE);
TestUtils.createNamespace(client, NAMESPACE);
}

@AfterAll
void teardownEnvironment() {
TestUtils.deleteCrd(client, KafkaBridge.CRD_NAME);
CrdUtils.deleteCrd(client, KafkaBridge.CRD_NAME);
TestUtils.deleteNamespace(client, NAMESPACE);
client.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.strimzi.api.kafka.model.AbstractCrdIT;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -100,13 +101,13 @@ void testKafkaConnectWithInvalidExternalConfiguration() {
@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
TestUtils.createCrd(client, KafkaConnect.CRD_NAME, TestUtils.CRD_KAFKA_CONNECT);
CrdUtils.createCrd(client, KafkaConnect.CRD_NAME, CrdUtils.CRD_KAFKA_CONNECT);
TestUtils.createNamespace(client, NAMESPACE);
}

@AfterAll
void teardownEnvironment() {
TestUtils.deleteCrd(client, KafkaConnect.CRD_NAME);
CrdUtils.deleteCrd(client, KafkaConnect.CRD_NAME);
TestUtils.deleteNamespace(client, NAMESPACE);
client.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.strimzi.api.kafka.model.AbstractCrdIT;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -34,13 +35,13 @@ void testKafkaConnectorScaling() {
@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
TestUtils.createCrd(client, KafkaConnector.CRD_NAME, TestUtils.CRD_KAFKA_CONNECTOR);
CrdUtils.createCrd(client, KafkaConnector.CRD_NAME, CrdUtils.CRD_KAFKA_CONNECTOR);
TestUtils.createNamespace(client, NAMESPACE);
}

@AfterAll
void teardownEnvironment() {
TestUtils.deleteCrd(client, KafkaConnector.CRD_NAME);
CrdUtils.deleteCrd(client, KafkaConnector.CRD_NAME);
TestUtils.deleteNamespace(client, NAMESPACE);
client.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.strimzi.api.kafka.model.AbstractCrdIT;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -113,13 +114,13 @@ public void testKafkaWithInvalidZookeeperJmxAuthentication() {
@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
TestUtils.createCrd(client, Kafka.CRD_NAME, TestUtils.CRD_KAFKA);
CrdUtils.createCrd(client, Kafka.CRD_NAME, CrdUtils.CRD_KAFKA);
TestUtils.createNamespace(client, NAMESPACE);
}

@AfterAll
void teardownEnvironment() {
TestUtils.deleteCrd(client, Kafka.CRD_NAME);
CrdUtils.deleteCrd(client, Kafka.CRD_NAME);
TestUtils.deleteNamespace(client, NAMESPACE);
client.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.strimzi.api.kafka.model.kafka.listener.ListenerAddressBuilder;
import io.strimzi.api.kafka.model.kafka.listener.ListenerStatus;
import io.strimzi.api.kafka.model.kafka.listener.ListenerStatusBuilder;
import io.strimzi.test.TestUtils;
import io.strimzi.test.ReadWriteUtils;
import org.junit.jupiter.api.Test;

import java.net.URISyntaxException;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void testCertificationAuthorityBuilderAndInts() throws URISyntaxException
.build();

String path = Objects.requireNonNull(this.getClass().getResource("Kafka-ca-ints.yaml")).toURI().getPath();
assertThat(TestUtils.toYamlString(kafka), is(TestUtils.getFileAsString(path)));
assertThat(ReadWriteUtils.writeObjectToYamlString(kafka), is(ReadWriteUtils.readFile(path)));
}

@Test
Expand Down Expand Up @@ -121,12 +121,12 @@ public void testNewListenerSerialization() throws URISyntaxException {
.build();

String path = Objects.requireNonNull(this.getClass().getResource("Kafka-new-listener-serialization.yaml")).toURI().getPath();
assertThat(TestUtils.toYamlString(kafka), is(TestUtils.getFileAsString(path)));
assertThat(ReadWriteUtils.writeObjectToYamlString(kafka), is(ReadWriteUtils.readFile(path)));
}

@Test
public void testListeners() {
Kafka model = TestUtils.fromYaml("Kafka" + ".yaml", Kafka.class);
Kafka model = ReadWriteUtils.readObjectFromYamlFileInResources("Kafka" + ".yaml", Kafka.class);

assertThat(model.getSpec().getKafka().getListeners(), is(notNullValue()));
assertThat(model.getSpec().getKafka().getListeners().size(), is(2));
Expand Down Expand Up @@ -188,12 +188,12 @@ public void testListenerTypeAndNameInStatus() throws ParseException, URISyntaxEx
.build();

String path = Objects.requireNonNull(this.getClass().getResource("Kafka-listener-name-and-status.yaml")).toURI().getPath();
assertThat(TestUtils.toYamlString(kafka), is(TestUtils.getFileAsString(path)));
assertThat(ReadWriteUtils.writeObjectToYamlString(kafka), is(ReadWriteUtils.readFile(path)));
}

@Test
public void testListenersTypeAndName() {
Kafka model = TestUtils.fromYaml("Kafka-listener-name-and-status" + ".yaml", Kafka.class);
Kafka model = ReadWriteUtils.readObjectFromYamlFileInResources("Kafka-listener-name-and-status" + ".yaml", Kafka.class);

assertThat(model.getStatus().getListeners(), is(notNullValue()));
assertThat(model.getStatus().getListeners().size(), is(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.strimzi.api.kafka.model.AbstractCrdIT;
import io.strimzi.test.CrdUtils;
import io.strimzi.test.TestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -84,14 +85,14 @@ void testKafkaMirrorMakerWithCommitAndAbort() {
@BeforeAll
void setupEnvironment() {
client = new KubernetesClientBuilder().withConfig(new ConfigBuilder().withNamespace(NAMESPACE).build()).build();
TestUtils.createCrd(client, KafkaMirrorMaker.CRD_NAME, TestUtils.CRD_KAFKA_MIRROR_MAKER);
CrdUtils.createCrd(client, KafkaMirrorMaker.CRD_NAME, CrdUtils.CRD_KAFKA_MIRROR_MAKER);
TestUtils.createNamespace(client, NAMESPACE);
}

@SuppressWarnings("deprecation") // Kafka Mirror Maker is deprecated
@AfterAll
void teardownEnvironment() {
TestUtils.deleteCrd(client, KafkaMirrorMaker.CRD_NAME);
CrdUtils.deleteCrd(client, KafkaMirrorMaker.CRD_NAME);
TestUtils.deleteNamespace(client, NAMESPACE);
client.close();
}
Expand Down
Loading
Loading