diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/SerializationAdditionalPropertiesTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/SerializationAdditionalPropertiesTest.java index f616a8c9381..b417d756c90 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/SerializationAdditionalPropertiesTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/SerializationAdditionalPropertiesTest.java @@ -25,6 +25,8 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.Collections; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -40,8 +42,7 @@ void tearDown() { @DisplayName("unmarshal, with unknown fields, values are set in additionalProperties map") void unmarshalWithUnknownFields() { // Given - final String marshalled = - "{\"kind\": \"ConfigMap\"," + + final String marshalled = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + @@ -50,30 +51,29 @@ void unmarshalWithUnknownFields() { final KubernetesResource result = Serialization.unmarshal(marshalled); // Then assertThat(result) - .isInstanceOf(ConfigMap.class) - .hasFieldOrPropertyWithValue("metadata.name", "the-name") - .hasFieldOrPropertyWithValue("data.key", "value") - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); + .isInstanceOf(ConfigMap.class) + .hasFieldOrPropertyWithValue("metadata.name", "the-name") + .hasFieldOrPropertyWithValue("data.key", "value") + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); } @Test @DisplayName("unmarshal, with unmatched type fields, should throw Exception") void unmarshalWithUnmatchedTypeFieldsAndDefaults() { // Given - final String marshalled = - "{\"kind\": \"ConfigMap\"," + + final String marshalled = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + "\"immutable\":\"${immutable}\"}"; // When - final KubernetesClientException result = assertThrows(KubernetesClientException.class, () -> - Serialization.unmarshal(marshalled)); + final KubernetesClientException result = assertThrows(KubernetesClientException.class, + () -> Serialization.unmarshal(marshalled)); // Then assertThat(result) - .getCause() - .isInstanceOf(InvalidFormatException.class) - .hasMessageStartingWith("Cannot deserialize value of type `java.lang.Boolean` from String \"${immutable}\""); + .getCause() + .isInstanceOf(InvalidFormatException.class) + .hasMessageStartingWith("Cannot deserialize value of type `java.lang.Boolean` from String \"${immutable}\""); } @Test @@ -81,8 +81,7 @@ void unmarshalWithUnmatchedTypeFieldsAndDefaults() { void unmarshalWithUnmatchedTypeFields() { // Given Serialization.UNMATCHED_FIELD_TYPE_MODULE.setRestrictToTemplates(false); - final String marshalled = - "{\"kind\": \"ConfigMap\"," + + final String marshalled = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + @@ -92,11 +91,11 @@ void unmarshalWithUnmatchedTypeFields() { final KubernetesResource result = Serialization.unmarshal(marshalled); // Then assertThat(result) - .isInstanceOf(ConfigMap.class) - .hasFieldOrPropertyWithValue("metadata.name", "the-name") - .hasFieldOrPropertyWithValue("immutable", null) - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue") - .hasFieldOrPropertyWithValue("additionalProperties.immutable", "${immutable}"); + .isInstanceOf(ConfigMap.class) + .hasFieldOrPropertyWithValue("metadata.name", "the-name") + .hasFieldOrPropertyWithValue("immutable", null) + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue") + .hasFieldOrPropertyWithValue("additionalProperties.immutable", "${immutable}"); } @Test @@ -104,8 +103,7 @@ void unmarshalWithUnmatchedTypeFields() { void unmarshalWithUnmatchedTypeNestedFields() { // Given Serialization.UNMATCHED_FIELD_TYPE_MODULE.setRestrictToTemplates(false); - final String marshalled = - "{\"kind\": \"Deployment\"," + + final String marshalled = "{\"kind\": \"Deployment\"," + "\"apiVersion\": \"apps/v1\"," + "\"metadata\":{\"name\":\"deployment\", \"annotations\": \"${annotations}\"}," + "\"spec\":{\"replicas\":\"${replicas}\",\"paused\":true}," + @@ -114,14 +112,14 @@ void unmarshalWithUnmatchedTypeNestedFields() { final KubernetesResource result = Serialization.unmarshal(marshalled); // Then assertThat(result) - .isInstanceOf(Deployment.class) - .hasFieldOrPropertyWithValue("metadata.name", "deployment") - .hasFieldOrPropertyWithValue("metadata.annotations", null) - .hasFieldOrPropertyWithValue("metadata.additionalProperties.annotations", "${annotations}") - .hasFieldOrPropertyWithValue("spec.paused", true) - .hasFieldOrPropertyWithValue("spec.replicas", null) - .hasFieldOrPropertyWithValue("spec.additionalProperties.replicas", "${replicas}") - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); + .isInstanceOf(Deployment.class) + .hasFieldOrPropertyWithValue("metadata.name", "deployment") + .hasFieldOrPropertyWithValue("metadata.annotations", Collections.emptyMap()) + .hasFieldOrPropertyWithValue("metadata.additionalProperties.annotations", "${annotations}") + .hasFieldOrPropertyWithValue("spec.paused", true) + .hasFieldOrPropertyWithValue("spec.replicas", null) + .hasFieldOrPropertyWithValue("spec.additionalProperties.replicas", "${replicas}") + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); } @Test @@ -129,9 +127,9 @@ void unmarshalWithUnmatchedTypeNestedFields() { void marshalWithAdditionalPropertiesOverridingFields() { // Given final ConfigMap configMap = new ConfigMapBuilder() - .withNewMetadata().withName("name").addToAnnotations("key", "value").endMetadata() - .withImmutable(true) - .build(); + .withNewMetadata().withName("name").addToAnnotations("key", "value").endMetadata() + .withImmutable(true) + .build(); configMap.getAdditionalProperties().put("immutable", "${immutable}"); configMap.getAdditionalProperties().put("unknownField", "unknownValue"); configMap.getMetadata().getAdditionalProperties().put("annotations", "${annotations}"); @@ -139,12 +137,12 @@ void marshalWithAdditionalPropertiesOverridingFields() { final String result = Serialization.asJson(configMap); // Then assertThat(result).isEqualTo("{" + - "\"apiVersion\":\"v1\"," + - "\"kind\":\"ConfigMap\"," + - "\"metadata\":{\"name\":\"name\",\"annotations\":\"${annotations}\"}," + - "\"immutable\":\"${immutable}\"," + - "\"unknownField\":\"unknownValue\"" + - "}"); + "\"apiVersion\":\"v1\"," + + "\"kind\":\"ConfigMap\"," + + "\"metadata\":{\"name\":\"name\",\"annotations\":\"${annotations}\"}," + + "\"immutable\":\"${immutable}\"," + + "\"unknownField\":\"unknownValue\"" + + "}"); } } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/serialization/UnmatchedFieldTypeModuleTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/serialization/UnmatchedFieldTypeModuleTest.java index 9bebc4be535..6b4deb70ec4 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/serialization/UnmatchedFieldTypeModuleTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/serialization/UnmatchedFieldTypeModuleTest.java @@ -29,6 +29,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Collections; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -55,8 +57,7 @@ void setUp() { @DisplayName("readValue, with unknown fields, values are set in additionalProperties map") void readValueWithUnknownFields() throws JsonProcessingException { // Given - final String json = - "{\"kind\": \"ConfigMap\"," + + final String json = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + @@ -65,18 +66,17 @@ void readValueWithUnknownFields() throws JsonProcessingException { final KubernetesResource result = objectMapper.readValue(json, KubernetesResource.class); // Then assertThat(result) - .isInstanceOf(ConfigMap.class) - .hasFieldOrPropertyWithValue("metadata.name", "the-name") - .hasFieldOrPropertyWithValue("data.key", "value") - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); + .isInstanceOf(ConfigMap.class) + .hasFieldOrPropertyWithValue("metadata.name", "the-name") + .hasFieldOrPropertyWithValue("data.key", "value") + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); } @Test @DisplayName("readValue, with unmatched type fields, values are set in additionalProperties map") void readValueWithUnmatchedTypeFields() throws JsonProcessingException { // Given - final String json = - "{\"kind\": \"ConfigMap\"," + + final String json = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + @@ -86,19 +86,18 @@ void readValueWithUnmatchedTypeFields() throws JsonProcessingException { final KubernetesResource result = objectMapper.readValue(json, KubernetesResource.class); // Then assertThat(result) - .isInstanceOf(ConfigMap.class) - .hasFieldOrPropertyWithValue("metadata.name", "the-name") - .hasFieldOrPropertyWithValue("immutable", null) - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue") - .hasFieldOrPropertyWithValue("additionalProperties.immutable", "${immutable}"); + .isInstanceOf(ConfigMap.class) + .hasFieldOrPropertyWithValue("metadata.name", "the-name") + .hasFieldOrPropertyWithValue("immutable", null) + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue") + .hasFieldOrPropertyWithValue("additionalProperties.immutable", "${immutable}"); } @Test @DisplayName("readValue, with unmatched type nested fields, values are set in additionalProperties map") void readValueWithUnmatchedTypeNestedFields() throws JsonProcessingException { // Given - final String json = - "{\"kind\": \"Deployment\"," + + final String json = "{\"kind\": \"Deployment\"," + "\"apiVersion\": \"apps/v1\"," + "\"metadata\":{\"name\":\"deployment\", \"annotations\": \"${annotations}\"}," + "\"spec\":{\"replicas\":\"${replicas}\",\"paused\":true}," + @@ -107,24 +106,24 @@ void readValueWithUnmatchedTypeNestedFields() throws JsonProcessingException { final KubernetesResource result = objectMapper.readValue(json, KubernetesResource.class); // Then assertThat(result) - .isInstanceOf(Deployment.class) - .hasFieldOrPropertyWithValue("metadata.name", "deployment") - .hasFieldOrPropertyWithValue("metadata.annotations", null) - .hasFieldOrPropertyWithValue("metadata.additionalProperties.annotations", "${annotations}") - .hasFieldOrPropertyWithValue("spec.paused", true) - .hasFieldOrPropertyWithValue("spec.replicas", null) - .hasFieldOrPropertyWithValue("spec.additionalProperties.replicas", "${replicas}") - .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); + .isInstanceOf(Deployment.class) + .hasFieldOrPropertyWithValue("metadata.name", "deployment") + .hasFieldOrPropertyWithValue("metadata.annotations", Collections.emptyMap()) + .hasFieldOrPropertyWithValue("metadata.additionalProperties.annotations", "${annotations}") + .hasFieldOrPropertyWithValue("spec.paused", true) + .hasFieldOrPropertyWithValue("spec.replicas", null) + .hasFieldOrPropertyWithValue("spec.additionalProperties.replicas", "${replicas}") + .hasFieldOrPropertyWithValue("additionalProperties.unknownField", "unknownValue"); } @Test @DisplayName("readValue, with no anySetter, should throw Exception") - void readValueWithNoAnySetterShouldThrowException() { + void readValueWithNoAnySetterShouldThrowException() { // Given final String json = "{\"value\": false}"; // When - final MismatchedInputException result = assertThrows(MismatchedInputException.class, () -> - objectMapper.readValue(json, Example.class)); + final MismatchedInputException result = assertThrows(MismatchedInputException.class, + () -> objectMapper.readValue(json, Example.class)); // Then assertThat(result).hasMessageStartingWith("Cannot deserialize value of type `int` from Boolean value"); } @@ -134,15 +133,14 @@ void readValueWithNoAnySetterShouldThrowException() { void readValueWithRestrictToTemplatesAndUnmatchedTypeFields() { // Given unmatchedFieldTypeModule.setRestrictToTemplates(true); - final String json = - "{\"kind\": \"ConfigMap\"," + + final String json = "{\"kind\": \"ConfigMap\"," + "\"apiVersion\": \"v1\"," + "\"metadata\":{\"name\":\"the-name\"}," + "\"data\":{\"key\":\"value\"}," + "\"immutable\":\"${immutable}\"}"; // When - final MismatchedInputException result = assertThrows(MismatchedInputException.class, () -> - objectMapper.readValue(json, KubernetesResource.class)); + final MismatchedInputException result = assertThrows(MismatchedInputException.class, + () -> objectMapper.readValue(json, KubernetesResource.class)); // Then assertThat(result).hasMessageStartingWith("Cannot deserialize value of type `java.lang.Boolean` from String"); } @@ -152,9 +150,9 @@ void readValueWithRestrictToTemplatesAndUnmatchedTypeFields() { void writeValueAsStringWithAdditionalPropertiesOverridingFields() throws JsonProcessingException { // Given final ConfigMap configMap = new ConfigMapBuilder() - .withNewMetadata().withName("name").addToAnnotations("key", "ignored").addToLabels("lKey", "value").endMetadata() - .withImmutable(true) - .build(); + .withNewMetadata().withName("name").addToAnnotations("key", "ignored").addToLabels("lKey", "value").endMetadata() + .withImmutable(true) + .build(); configMap.getAdditionalProperties().put("immutable", "${immutable}"); configMap.getAdditionalProperties().put("unknownField", "unknownValue"); configMap.getMetadata().getAdditionalProperties().put("annotations", "${annotations}"); @@ -162,12 +160,12 @@ void writeValueAsStringWithAdditionalPropertiesOverridingFields() throws JsonPro final String result = objectMapper.writeValueAsString(configMap); // Then assertThat(result).isEqualTo("{" + - "\"apiVersion\":\"v1\"," + - "\"kind\":\"ConfigMap\"," + - "\"metadata\":{\"labels\":{\"lKey\":\"value\"},\"name\":\"name\",\"annotations\":\"${annotations}\"}," + - "\"immutable\":\"${immutable}\"," + - "\"unknownField\":\"unknownValue\"" + - "}"); + "\"apiVersion\":\"v1\"," + + "\"kind\":\"ConfigMap\"," + + "\"metadata\":{\"labels\":{\"lKey\":\"value\"},\"name\":\"name\",\"annotations\":\"${annotations}\"}," + + "\"immutable\":\"${immutable}\"," + + "\"unknownField\":\"unknownValue\"" + + "}"); } @Test @@ -177,9 +175,9 @@ void writeValueAsStringWithAdditionalPropertiesOverridingFieldsShouldLogWarning( // Given unmatchedFieldTypeModule.setLogWarnings(true); final ConfigMap configMap = new ConfigMapBuilder() - .withNewMetadata().withName("name").endMetadata() - .withImmutable(true) - .build(); + .withNewMetadata().withName("name").endMetadata() + .withImmutable(true) + .build(); configMap.getAdditionalProperties().put("immutable", "I'll trigger a warning"); final Logger mockLogger = mock(Logger.class, RETURNS_DEEP_STUBS); lfMock.when(() -> LoggerFactory.getLogger(any(Class.class))).thenReturn(mockLogger); @@ -187,8 +185,8 @@ void writeValueAsStringWithAdditionalPropertiesOverridingFieldsShouldLogWarning( objectMapper.writeValueAsString(configMap); // Then verify(mockLogger, times(1)) - .warn("Value in field '{}' ignored in favor of value in additionalProperties ({}) for {}", - "immutable", "I'll trigger a warning", "io.fabric8.kubernetes.api.model.ConfigMap"); + .warn("Value in field '{}' ignored in favor of value in additionalProperties ({}) for {}", + "immutable", "I'll trigger a warning", "io.fabric8.kubernetes.api.model.ConfigMap"); } } @@ -202,9 +200,9 @@ void writeValueAsStringWithAdditionalPropertiesOverridingFieldsShouldNotLogWarni om.registerModule(module); module.setLogWarnings(false); final ConfigMap configMap = new ConfigMapBuilder() - .withNewMetadata().withName("name").endMetadata() - .withImmutable(true) - .build(); + .withNewMetadata().withName("name").endMetadata() + .withImmutable(true) + .build(); configMap.getAdditionalProperties().put("immutable", "I'll trigger a warning"); final Logger mockLogger = mock(Logger.class, RETURNS_DEEP_STUBS); lfMock.when(() -> LoggerFactory.getLogger(any(Class.class))).thenReturn(mockLogger); @@ -212,8 +210,8 @@ void writeValueAsStringWithAdditionalPropertiesOverridingFieldsShouldNotLogWarni om.writeValueAsString(configMap); // Then verify(mockLogger, never()) - .warn("Value in field '{}' ignored in favor of value in additionalProperties ({}) for {}", - "immutable", "I'll trigger a warning", "io.fabric8.kubernetes.api.model.ConfigMap"); + .warn("Value in field '{}' ignored in favor of value in additionalProperties ({}) for {}", + "immutable", "I'll trigger a warning", "io.fabric8.kubernetes.api.model.ConfigMap"); } } diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/DryRunIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/DryRunIT.java index e0c46ed3ade..6f52bd2fe67 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/DryRunIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/DryRunIT.java @@ -69,7 +69,7 @@ void createOrReplace() { assertNotNull(replacedConfigMap.getMetadata().getCreationTimestamp()); assertNotNull(replacedConfigMap.getMetadata().getUid()); ConfigMap configMapQueriedFromServer = client.configMaps().withName(name).get(); - assertNull(configMapQueriedFromServer.getMetadata().getLabels()); + assertTrue(configMapQueriedFromServer.getMetadata().getLabels().isEmpty()); } @Test diff --git a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PatchIT.java b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PatchIT.java index 99c7b4a57f5..90f55eca025 100644 --- a/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PatchIT.java +++ b/kubernetes-itests/src/test/java/io/fabric8/kubernetes/PatchIT.java @@ -61,7 +61,7 @@ void testJsonMergePatch() { // Then assertThat(patchedConfigMap).isNotNull(); - assertThat(patchedConfigMap.getMetadata().getAnnotations()).isNull(); + assertThat(patchedConfigMap.getMetadata().getAnnotations()).isNullOrEmpty(); } @Test diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceDefinitionTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceDefinitionTest.java index f6f230d4c08..6b36e0d1c51 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceDefinitionTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/CustomResourceDefinitionTest.java @@ -25,6 +25,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import io.fabric8.kubernetes.client.utils.Serialization; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,8 +33,8 @@ import java.net.URL; import java.util.List; -import static junit.framework.TestCase.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -103,7 +104,7 @@ void testCreate() { assertNotNull(crd); assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName()); // Assertion to test behavior in https://github.com/fabric8io/kubernetes-client/issues/1486 - assertNull(crd.getSpec().getValidation().getOpenAPIV3Schema().getDependencies()); + assertFalse(Serialization.asYaml(crd.getSpec().getValidation()).contains("dependencies")); } @Test diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/SecretCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/SecretCrudTest.java index 7ad89f0b224..c150df1f343 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/SecretCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/SecretCrudTest.java @@ -30,7 +30,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -82,7 +81,7 @@ public void testCrud() { secret2 = client.secrets().inNamespace("ns2").withName("secret2") .edit(s -> new SecretBuilder(s).removeFromData("one").build()); assertNotNull(secret2); - assertNull(secret2.getData()); + assertTrue(secret2.getData().isEmpty()); } @Test @@ -100,7 +99,7 @@ void testSecretWithNoMetadataCreateFails() { assertEquals("Secret is invalid", kubernetesClientException.getStatus().getMessage()); assertEquals(1, kubernetesClientException.getStatus().getDetails().getCauses().size()); assertEquals("ValueRequired", kubernetesClientException.getStatus().getDetails().getCauses().get(0).getReason()); - assertEquals("Required value: metadata is required", + assertEquals("Required value: name or generateName is required", kubernetesClientException.getStatus().getDetails().getCauses().get(0).getMessage()); } } diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java index 51d6307a9b6..b04d6abc8e9 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/StorageSpaceCrudTest.java @@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @EnableKubernetesMockClient(crud = true) public class StorageSpaceCrudTest { @@ -68,7 +68,7 @@ public void testCrud() { assertEquals(1, storageClassList.getItems().size()); assertEquals("kubernetes.io/aws-ebs", storageClassList.getItems().get(0).getProvisioner()); assertEquals("value", storageClassList.getItems().get(0).getParameters().get("key")); - assertNull(storageClassList.getItems().get(0).getMetadata().getLabels()); + assertTrue(storageClassList.getItems().get(0).getMetadata().getLabels().isEmpty()); //test update storageClass = client.storage().storageClasses().withName(name).edit(s -> new StorageClassBuilder(s).editOrNewMetadata() diff --git a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/V1CustomResourceDefinitionTest.java b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/V1CustomResourceDefinitionTest.java index 6890fb4de02..ec32c904909 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/V1CustomResourceDefinitionTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/V1CustomResourceDefinitionTest.java @@ -25,6 +25,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import io.fabric8.kubernetes.client.utils.Serialization; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,8 +34,8 @@ import java.net.URL; import java.util.List; -import static junit.framework.TestCase.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -102,7 +103,7 @@ void testCreate() { assertNotNull(crd); assertEquals("sparkclusters.radanalytics.io", crd.getMetadata().getName()); // Assertion to test behavior in https://github.com/fabric8io/kubernetes-client/issues/1486 - assertNull(crd.getSpec().getVersions().get(0).getSchema().getOpenAPIV3Schema().getDependencies()); + assertFalse(Serialization.asYaml(crd.getSpec().getVersions().get(0).getSchema()).contains("dependencies")); } @Test diff --git a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java index c75205c7916..a409ca1774c 100644 --- a/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java +++ b/kubernetes-tests/src/test/java/io/fabric8/openshift/client/server/mock/OpenshiftRoleBindingTest.java @@ -16,6 +16,8 @@ package io.fabric8.openshift.client.server.mock; import com.fasterxml.jackson.databind.ObjectMapper; +import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; +import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.openshift.api.model.RoleBinding; import io.fabric8.openshift.api.model.RoleBindingBuilder; import io.fabric8.openshift.client.OpenShiftClient; @@ -23,213 +25,358 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -@EnableOpenShiftMockClient +@EnableKubernetesMockClient class OpenshiftRoleBindingTest { - OpenShiftMockServer server; + KubernetesMockServer server; OpenShiftClient client; private RoleBinding expectedRoleBinding = new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .addNewSubject().withKind("User").withName("testuser1").endSubject() - .addNewSubject().withKind("User").withName("testuser2").endSubject() - .addNewSubject().withKind("ServiceAccount").withNamespace("test").withName("svcacct").endSubject() - .addNewSubject().withKind("Group").withName("testgroup").endSubject() - .build(); + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .addNewSubject() + .withKind("User") + .withName("testuser1") + .endSubject() + .addNewSubject() + .withKind("User") + .withName("testuser2") + .endSubject() + .addNewSubject() + .withKind("ServiceAccount") + .withNamespace("test") + .withName("svcacct") + .endSubject() + .addNewSubject() + .withKind("Group") + .withName("testgroup") + .endSubject() + .build(); @Test void testCreateWithOnlySubjects() throws Exception { - server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().create( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addNewSubject().withKind("User").withName("testuser1").endSubject() - .addNewSubject().withKind("User").withName("testuser2").endSubject() - .addNewSubject().withKind("ServiceAccount").withName("svcacct").endSubject() - .addNewSubject().withKind("Group").withName("testgroup").endSubject() - .build() - ); + server.expect() + .post() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings") + .andReturn(201, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .create( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addNewSubject() + .withKind("User") + .withName("testuser1") + .endSubject() + .addNewSubject() + .withKind("User") + .withName("testuser2") + .endSubject() + .addNewSubject() + .withKind("ServiceAccount") + .withName("svcacct") + .endSubject() + .addNewSubject() + .withKind("Group") + .withName("testgroup") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().readByteArray())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().readByteArray())); } @Test void testCreateWithUserNamesAndGroupsAndNoSubjects() throws Exception { - server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().create( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .build() - ); + server.expect() + .post() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings") + .andReturn(201, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .create( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } @Test void testCreateWithUserNamesAndGroupsAndOverwriteSubjects() throws Exception { - server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().create( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .addNewSubject().withKind("User").withName("unexpected").endSubject() - .build() - ); + server.expect() + .post() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings") + .andReturn(201, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .create( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .addNewSubject() + .withKind("User") + .withName("unexpected") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } @Test void testReplaceWithOnlySubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - server.expect().put().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").replace( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addNewSubject().withKind("User").withName("testuser1").endSubject() - .addNewSubject().withKind("User").withName("testuser2").endSubject() - .addNewSubject().withKind("ServiceAccount").withName("svcacct").endSubject() - .addNewSubject().withKind("Group").withName("testgroup").endSubject() - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + server.expect() + .put() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .replace( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addNewSubject() + .withKind("User") + .withName("testuser1") + .endSubject() + .addNewSubject() + .withKind("User") + .withName("testuser2") + .endSubject() + .addNewSubject() + .withKind("ServiceAccount") + .withName("svcacct") + .endSubject() + .addNewSubject() + .withKind("Group") + .withName("testgroup") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } @Test void testReplaceWithUserNamesAndGroupsAndNoSubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - server.expect().put().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").replace( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + server.expect() + .put() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .replace( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .build()); assertEquals(expectedRoleBinding, response); - - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } @Test void testReplaceWithUserNamesAndGroupsAndOverwriteSubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - server.expect().put().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").replace( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .addNewSubject().withKind("User").withName("unexpected").endSubject() - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + server.expect() + .put() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .replace( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .addNewSubject() + .withKind("User") + .withName("unexpected") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } @Test void testPatchWithOnlySubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()).once(); - server.expect().patch().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").patch( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addNewSubject().withKind("User").withName("testuser1").endSubject() - .addNewSubject().withKind("User").withName("testuser2").endSubject() - .addNewSubject().withKind("ServiceAccount").withName("svcacct").endSubject() - .addNewSubject().withKind("Group").withName("testgroup").endSubject() - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()) + .once(); + server.expect() + .patch() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .patch( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addNewSubject() + .withKind("User") + .withName("testuser1") + .endSubject() + .addNewSubject() + .withKind("User") + .withName("testuser2") + .endSubject() + .addNewSubject() + .withKind("ServiceAccount") + .withName("svcacct") + .endSubject() + .addNewSubject() + .withKind("Group") + .withName("testgroup") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals( - "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", - server.getLastRequest().getBody().readUtf8() - ); + assertEquals( + "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", + server.getLastRequest().getBody().readUtf8()); } @Test void testPatchWithUserNamesAndGroupsAndNoSubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()).once(); - server.expect().patch().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").patch( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()) + .once(); + server.expect() + .patch() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .patch( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .build()); assertEquals(expectedRoleBinding, response); - assertEquals( - "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", - server.getLastRequest().getBody().readUtf8() - ); + assertEquals( + "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", + server.getLastRequest().getBody().readUtf8()); } @Test void testPatchWithUserNamesAndGroupsAndOverwriteSubjects() throws Exception { - server.expect().get().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()).once(); - server.expect().patch().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb").andReturn(200, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().withName("testrb").patch( - new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") - .addToGroupNames("testgroup") - .addNewSubject().withKind("User").withName("unexpected").endSubject() - .build() - ); + server.expect() + .get() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, new RoleBindingBuilder().addToUserNames("unexpected").build()) + .once(); + server.expect() + .patch() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings/testrb") + .andReturn(200, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .withName("testrb") + .patch( + new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addToUserNames("testuser1", "testuser2", "system:serviceaccount:test:svcacct") + .addToGroupNames("testgroup") + .addNewSubject() + .withKind("User") + .withName("unexpected") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals( - "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/metadata\",\"value\":{}},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", - server.getLastRequest().getBody().readUtf8() - ); + assertEquals( + "[{\"op\":\"replace\",\"path\":\"/userNames/0\",\"value\":\"testuser1\"},{\"op\":\"add\",\"path\":\"/userNames/1\",\"value\":\"testuser2\"},{\"op\":\"add\",\"path\":\"/userNames/2\",\"value\":\"system:serviceaccount:test:svcacct\"},{\"op\":\"add\",\"path\":\"/groupNames\",\"value\":[\"testgroup\"]},{\"op\":\"add\",\"path\":\"/subjects\",\"value\":[{\"kind\":\"User\",\"name\":\"testuser1\"},{\"kind\":\"User\",\"name\":\"testuser2\"},{\"kind\":\"ServiceAccount\",\"name\":\"svcacct\",\"namespace\":\"test\"},{\"kind\":\"Group\",\"name\":\"testgroup\"}]}]", + server.getLastRequest().getBody().readUtf8()); } @Test void testCreateInline() throws Exception { - server.expect().post().withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings").andReturn(201, expectedRoleBinding).once(); - - - RoleBinding response = client.roleBindings().create(new RoleBindingBuilder() - .withNewMetadata().endMetadata() - .addNewSubject().withKind("User").withName("testuser1").endSubject() - .addNewSubject().withKind("User").withName("testuser2").endSubject() - .addNewSubject().withKind("ServiceAccount").withName("svcacct").endSubject() - .addNewSubject().withKind("Group").withName("testgroup").endSubject() - .build()); + server.expect() + .post() + .withPath("/apis/authorization.openshift.io/v1/namespaces/test/rolebindings") + .andReturn(201, expectedRoleBinding) + .once(); + + RoleBinding response = client.roleBindings() + .create(new RoleBindingBuilder() + .withNewMetadata() + .endMetadata() + .addNewSubject() + .withKind("User") + .withName("testuser1") + .endSubject() + .addNewSubject() + .withKind("User") + .withName("testuser2") + .endSubject() + .addNewSubject() + .withKind("ServiceAccount") + .withName("svcacct") + .endSubject() + .addNewSubject() + .withKind("Group") + .withName("testgroup") + .endSubject() + .build()); assertEquals(expectedRoleBinding, response); - assertEquals(expectedRoleBinding, new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); + assertEquals(expectedRoleBinding, + new ObjectMapper().readerFor(RoleBinding.class).readValue(server.getLastRequest().getBody().inputStream())); } }