Skip to content

Commit

Permalink
Replace usage of KubernetesServerTestResource with WithKubernetesTest…
Browse files Browse the repository at this point in the history
…Server annotation
  • Loading branch information
kornys committed Aug 10, 2021
1 parent 8c476ab commit 1c64089
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.bf2.operator.controllers;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.common.ManagedKafkaAgentResourceClient;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent;
import org.junit.jupiter.api.Test;
Expand All @@ -12,7 +11,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class ManagedKafkaAgentControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import io.fabric8.kubernetes.api.model.OwnerReferenceBuilder;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.Watcher.Action;
import io.javaoperatorsdk.operator.api.Context;
import io.javaoperatorsdk.operator.processing.event.EventList;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.operator.events.ResourceEvent;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition;
Expand All @@ -18,12 +16,12 @@

import javax.inject.Inject;

import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;

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

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class ManagedKafkaControllerTest {

Expand All @@ -34,13 +32,13 @@ public class ManagedKafkaControllerTest {
void shouldCreateStatus() throws InterruptedException {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getMetadata().setUid(UUID.randomUUID().toString());
mk.getMetadata().setGeneration(1l);
mk.getMetadata().setGeneration(1L);
mk.getMetadata().setResourceVersion("1");

// create
Context<ManagedKafka> context = Mockito.mock(Context.class);
Mockito.when(context.getEvents())
.thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
.thenReturn(new EventList(Collections.singletonList(new CustomResourceEvent(Action.ADDED, mk, null))));

mkController.createOrUpdateResource(mk, context);
ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
Expand All @@ -51,11 +49,11 @@ void shouldCreateStatus() throws InterruptedException {
// essentially there "last event" of the delete is something other than a deployment or a kafka
// it should still trigger the update of the status
Mockito.when(context.getEvents())
.thenReturn(new EventList(Arrays.asList(new ResourceEvent<>(new ServiceBuilder()
.thenReturn(new EventList(Collections.singletonList(new ResourceEvent<>(new ServiceBuilder()
.withNewMetadata()
.withOwnerReferences(new OwnerReferenceBuilder().withUid(mk.getMetadata().getUid()).build())
.endMetadata()
.build(), null, Watcher.Action.DELETED))));
.build(), null, Action.DELETED))));
mkController.createOrUpdateResource(mk, context);

// should now be deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionBuilder;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionConditionBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import io.strimzi.api.kafka.model.Kafka;
import io.strimzi.api.kafka.model.KafkaBuilder;
import org.bf2.operator.clients.KafkaResourceClient;
Expand All @@ -38,7 +37,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class StrimziBundleManagerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import io.strimzi.api.kafka.model.Kafka;
import io.strimzi.api.kafka.model.status.ConditionBuilder;
import io.strimzi.api.kafka.model.status.KafkaStatusBuilder;
Expand All @@ -35,7 +34,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class StrimziManagerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder;
Expand All @@ -16,7 +15,7 @@

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

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class AdminServerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder;
Expand All @@ -16,7 +15,7 @@

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

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class CanaryTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package org.bf2.operator.operands;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.zjsonpatch.JsonDiff;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import io.strimzi.api.kafka.model.Kafka;
import io.strimzi.api.kafka.model.KafkaBuilder;
import io.strimzi.api.kafka.model.storage.JbodStorage;
Expand Down Expand Up @@ -39,7 +36,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
class KafkaClusterTest {

Expand Down Expand Up @@ -147,15 +144,16 @@ void testKafkaInstanceConfigurationSerialization() throws IOException {
assertEquals("zkfoo zkbar, zkfoo2 zkbar2", propertyMap.get("managedkafka.zookeeper.jvm-xx"));

}
private JsonNode diffToExpected(Kafka kafka, String expected) throws IOException, JsonProcessingException, JsonMappingException {

private JsonNode diffToExpected(Kafka kafka, String expected) throws IOException {
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
JsonNode file1 = objectMapper.readTree(KafkaClusterTest.class.getResourceAsStream(expected));
JsonNode file2 = objectMapper.readTree(Serialization.asYaml(kafka));
return JsonDiff.asJson(file1, file2);
}

@Test
void testDrainCleanerWebhookFound() throws IOException {
void testDrainCleanerWebhookFound() {
DrainCleanerManager mock = Mockito.mock(DrainCleanerManager.class);
Mockito.when(mock.isDrainCleanerWebhookFound()).thenReturn(true);
QuarkusMock.installMockForType(mock, DrainCleanerManager.class);
Expand All @@ -168,7 +166,7 @@ void testDrainCleanerWebhookFound() throws IOException {
}

@Test
void testDrainCleanerWebhookNotFound() throws IOException {
void testDrainCleanerWebhookNotFound() {
DrainCleanerManager mock = Mockito.mock(DrainCleanerManager.class);
Mockito.when(mock.isDrainCleanerWebhookFound()).thenReturn(false);
QuarkusMock.installMockForType(mock, DrainCleanerManager.class);
Expand Down Expand Up @@ -220,9 +218,9 @@ void testExistingStorageClassOverridesDontGetUpdated() {
assertNull(((PersistentClaimStorage) reconciledKafka.getSpec().getZookeeper().getStorage()).getStorageClass());
assertEquals(buildStorageOverrides(), ((PersistentClaimStorage) reconciledKafka.getSpec().getZookeeper().getStorage()).getOverrides());

((JbodStorage)reconciledKafka.getSpec().getKafka().getStorage()).getVolumes().stream().forEach(v -> {
assertNull(((PersistentClaimStorage)v).getStorageClass());
assertEquals(buildStorageOverrides(), ((PersistentClaimStorage)v).getOverrides());
((JbodStorage) reconciledKafka.getSpec().getKafka().getStorage()).getVolumes().forEach(v -> {
assertNull(((PersistentClaimStorage) v).getStorageClass());
assertEquals(buildStorageOverrides(), ((PersistentClaimStorage) v).getOverrides());
});
}

Expand All @@ -234,9 +232,9 @@ private List<PersistentClaimStorageOverride> buildStorageOverrides() {
for (int i = 0; i < num; i++) {
overrides.add(
new PersistentClaimStorageOverrideBuilder()
.withBroker(i)
.withStorageClass(storageClasses.get(i % storageClasses.size()))
.build());
.withBroker(i)
.withStorageClass(storageClasses.get(i % storageClasses.size()))
.build());
}
return overrides;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.Arrays;

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

public class KafkaInstanceTest {

@Test
void testStatus() throws IOException {
void testStatus() {
// sample operand readiness
Operand<ManagedKafka> error = mockOperand(new OperandReadiness(Status.False, Reason.Error, "I'm not well"));
Operand<ManagedKafka> installing = mockOperand(new OperandReadiness(Status.False, Reason.Installing, "I'm installing"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.common.OperandUtils;
import org.bf2.operator.MockProfile;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
Expand All @@ -24,7 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@TestProfile(MockProfile.class)
@QuarkusTest
public class ImagePullSecretManagerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.operator.resources.v1alpha1.ObservabilityConfiguration;
import org.bf2.operator.resources.v1alpha1.ObservabilityConfigurationBuilder;
import org.junit.jupiter.api.Test;
Expand All @@ -19,7 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class ObservabilityManagerTest {

Expand Down
5 changes: 2 additions & 3 deletions sync/src/test/java/org/bf2/sync/AgentPollerTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.bf2.sync;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.junit.mockito.InjectMock;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.common.ManagedKafkaAgentResourceClient;
import org.bf2.operator.resources.v1alpha1.ClusterCapacityBuilder;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaAgent;
Expand All @@ -19,7 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
@TestProfile(MockSyncProfile.class)
public class AgentPollerTest {
Expand Down
5 changes: 2 additions & 3 deletions sync/src/test/java/org/bf2/sync/PollerTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.bf2.sync;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.junit.mockito.InjectMock;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.common.ManagedKafkaResourceClient;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaList;
Expand All @@ -31,7 +30,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
@TestProfile(MockSyncProfile.class)
public class PollerTest {
Expand Down
5 changes: 2 additions & 3 deletions sync/src/test/java/org/bf2/sync/UpdateTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.bf2.sync;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.junit.mockito.InjectMock;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.bf2.common.ManagedKafkaResourceClient;
import org.bf2.operator.resources.v1alpha1.ManagedKafka;
import org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus;
Expand All @@ -23,7 +22,7 @@

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

@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
@TestProfile(MockSyncProfile.class)
public class UpdateTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bf2.systemtest.framework.KeycloakInstance;
Expand Down Expand Up @@ -41,7 +40,7 @@
* Tests for verifying that test suite is not broken and basic functionality is working properly
*/
@QuarkusTest
@QuarkusTestResource(KubernetesServerTestResource.class)
@WithKubernetesTestServer
public class SuiteUnitTest extends AbstractST {
private static final Logger LOGGER = LogManager.getLogger(SuiteUnitTest.class);
private static final String TEST_NS = "default";
Expand Down

0 comments on commit 1c64089

Please sign in to comment.