-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34259 from metacosm/fix-openshift-client
Properly configure KubernetesSerialization for OpenShiftClient
- Loading branch information
Showing
4 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../test/java/io/quarkus/openshift/client/deployment/OpenShiftClientObjectMapperCDITest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.quarkus.openshift.client.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import io.quarkus.kubernetes.client.KubernetesClientObjectMapper; | ||
import io.quarkus.kubernetes.client.KubernetesClientObjectMapperCustomizer; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenShiftClientObjectMapperCDITest { | ||
|
||
@Inject | ||
OpenShiftClient client; | ||
|
||
@Inject | ||
@KubernetesClientObjectMapper | ||
ObjectMapper objectMapper; | ||
|
||
@Test | ||
public void kubernetesClientObjectMapperCustomizer() throws JsonProcessingException { | ||
final var result = objectMapper.readValue("{\"quarkusName\":\"the-name\"}", ObjectMeta.class); | ||
assertEquals("the-name", result.getName()); | ||
} | ||
|
||
@Test | ||
public void kubernetesClientUsesCustomizedObjectMapper() { | ||
final var result = client.getKubernetesSerialization() | ||
.unmarshal("{\"quarkusName\":\"the-name\"}", ObjectMeta.class); | ||
assertEquals("the-name", result.getName()); | ||
} | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.kubernetes-client.devservices.enabled", "false"); | ||
|
||
@Singleton | ||
public static class Customizer implements KubernetesClientObjectMapperCustomizer { | ||
@Override | ||
public void customize(ObjectMapper objectMapper) { | ||
objectMapper.addMixIn(ObjectMeta.class, ObjectMetaMixin.class); | ||
} | ||
|
||
private static final class ObjectMetaMixin { | ||
@JsonProperty("quarkusName") | ||
String name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters