diff --git a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/CertManagerExtensionAdapter.java b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/CertManagerExtensionAdapter.java index b8fe7c7c486..8d838c3cccc 100644 --- a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/CertManagerExtensionAdapter.java +++ b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/CertManagerExtensionAdapter.java @@ -44,5 +44,4 @@ public Boolean isAdaptable(Client client) { public CertManagerClient adapt(Client client) { return new DefaultCertManagerClient(client.adapt(OkHttpClient.class), client.getConfiguration()); } - } diff --git a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1APIGroupExtensionAdapter.java b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1APIGroupExtensionAdapter.java new file mode 100644 index 00000000000..2b67e42c51e --- /dev/null +++ b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1APIGroupExtensionAdapter.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.client; + +import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; +import io.fabric8.kubernetes.client.Client; +import okhttp3.OkHttpClient; + +public class V1APIGroupExtensionAdapter extends APIGroupExtensionAdapter { + @Override + protected String getAPIGroupName() { + return "v1"; + } + + @Override + public Class getExtensionType() { + return V1APIGroupClient.class; + } + + @Override + protected V1APIGroupClient newInstance(Client client) { + return new V1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); + } +} diff --git a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha2APIGroupExtensionAdapter.java b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha2APIGroupExtensionAdapter.java new file mode 100644 index 00000000000..ac807876ca5 --- /dev/null +++ b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha2APIGroupExtensionAdapter.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.client; + +import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; +import io.fabric8.kubernetes.client.Client; +import okhttp3.OkHttpClient; + +public class V1alpha2APIGroupExtensionAdapter extends APIGroupExtensionAdapter { + @Override + protected String getAPIGroupName() { + return "v1alpha2"; + } + + @Override + public Class getExtensionType() { + return V1alpha2APIGroupClient.class; + } + + @Override + protected V1alpha2APIGroupClient newInstance(Client client) { + return new V1alpha2APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); + } +} diff --git a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha3APIGroupExtensionAdapter.java b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha3APIGroupExtensionAdapter.java new file mode 100644 index 00000000000..f0f5b2868b9 --- /dev/null +++ b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1alpha3APIGroupExtensionAdapter.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.client; + +import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; +import io.fabric8.kubernetes.client.Client; +import okhttp3.OkHttpClient; + +public class V1alpha3APIGroupExtensionAdapter extends APIGroupExtensionAdapter { + @Override + protected String getAPIGroupName() { + return "v1alpha3"; + } + + @Override + public Class getExtensionType() { + return V1alpha3APIGroupClient.class; + } + + @Override + protected V1alpha3APIGroupClient newInstance(Client client) { + return new V1alpha3APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); + } +} diff --git a/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1beta1APIGroupExtensionAdapter.java b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1beta1APIGroupExtensionAdapter.java new file mode 100644 index 00000000000..69daee548ee --- /dev/null +++ b/extensions/certmanager/client/src/main/java/io/fabric8/certmanager/client/V1beta1APIGroupExtensionAdapter.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.client; + +import io.fabric8.kubernetes.client.APIGroupExtensionAdapter; +import io.fabric8.kubernetes.client.Client; +import okhttp3.OkHttpClient; + +public class V1beta1APIGroupExtensionAdapter extends APIGroupExtensionAdapter { + @Override + protected String getAPIGroupName() { + return "v1beta1"; + } + + @Override + public Class getExtensionType() { + return V1beta1APIGroupClient.class; + } + + @Override + protected V1beta1APIGroupClient newInstance(Client client) { + return new V1beta1APIGroupClient(client.adapt(OkHttpClient.class), client.getConfiguration()); + } +} diff --git a/extensions/certmanager/client/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter b/extensions/certmanager/client/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter index 1ccae96b9f7..5849ce315f6 100644 --- a/extensions/certmanager/client/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter +++ b/extensions/certmanager/client/src/main/resources/META-INF/services/io.fabric8.kubernetes.client.ExtensionAdapter @@ -15,3 +15,7 @@ # io.fabric8.certmanager.client.CertManagerExtensionAdapter +io.fabric8.certmanager.client.V1alpha2APIGroupExtensionAdapter +io.fabric8.certmanager.client.V1alpha3APIGroupExtensionAdapter +io.fabric8.certmanager.client.V1beta1APIGroupExtensionAdapter +io.fabric8.certmanager.client.V1APIGroupExtensionAdapter diff --git a/extensions/certmanager/examples/src/main/java/io/fabric8/certmanager/examples/ClientFactory.java b/extensions/certmanager/examples/src/main/java/io/fabric8/certmanager/examples/ClientFactory.java new file mode 100644 index 00000000000..e208162c42f --- /dev/null +++ b/extensions/certmanager/examples/src/main/java/io/fabric8/certmanager/examples/ClientFactory.java @@ -0,0 +1,64 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.examples; + +import io.fabric8.certmanager.client.CertManagerClient; +import io.fabric8.certmanager.client.DefaultCertManagerClient; +import io.fabric8.kubernetes.client.ConfigBuilder; + +public class ClientFactory { + + public static CertManagerClient newClient(String[] args) { + ConfigBuilder config = new ConfigBuilder(); + for (int i = 0; i < args.length - 1; i++) { + + String key = args[i]; + String value = args[i + 1]; + + if (key.equals("--api-server")) { + config = config.withMasterUrl(value); + } + + if (key.equals("--token")) { + config = config.withOauthToken(value); + } + + if (key.equals("--username")) { + config = config.withUsername(value); + } + + if (key.equals("--password")) { + config = config.withPassword(value); + } + if (key.equals("--namespace")) { + config = config.withNamespace(value); + } + } + return new DefaultCertManagerClient(config.build()); + } + + public static String getOptions(String args[], String name, String defaultValue) { + for (int i = 0; i < args.length - 1; i++) { + String key = args[i]; + String value = args[i + 1]; + if (key.equals(name)) { + return value; + } + } + return defaultValue; + } +} + diff --git a/extensions/certmanager/tests/pom.xml b/extensions/certmanager/tests/pom.xml index 3bc89269169..d7945d0c0a0 100644 --- a/extensions/certmanager/tests/pom.xml +++ b/extensions/certmanager/tests/pom.xml @@ -66,6 +66,12 @@ ${slf4j.version} test + + io.fabric8 + tekton-mock + 5.4-SNAPSHOT + test + diff --git a/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1CertificateCrudTest.java b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1CertificateCrudTest.java new file mode 100644 index 00000000000..e6fa2213dc8 --- /dev/null +++ b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1CertificateCrudTest.java @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.test.crud; + +import io.fabric8.certmanager.api.model.v1.Certificate; +import io.fabric8.certmanager.api.model.v1.CertificateBuilder; +import io.fabric8.certmanager.api.model.v1.CertificateList; +import io.fabric8.certmanager.client.CertManagerClient; +import io.fabric8.certmanager.server.mock.CertManagerServer; +import org.junit.Rule; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +@EnableRuleMigrationSupport +class V1CertificateCrudTest { + + @Rule + public CertManagerServer server = new CertManagerServer(true, true); + + @Test + void shouldReturnEmptyList() { + CertManagerClient client = server.get(); + CertificateList certificateList = client.v1().certificates().inNamespace("ns1").list(); + assertNotNull(certificateList); + assertTrue(certificateList.getItems().isEmpty()); + } + + @Test + void shouldListAndGetCertificate() { + CertManagerClient client = server.get(); + Certificate certificate2 = new CertificateBuilder().withNewMetadata().withName("cert2").endMetadata().build(); + client.v1().certificates().inNamespace("ns2").create(certificate2); + CertificateList certificateList = client.v1().certificates().inNamespace("ns2").list(); + assertNotNull(certificateList); + assertEquals(1, certificateList.getItems().size()); + } + + @Test + void shouldDeleteACertificate() { + CertManagerClient client = server.get(); + Certificate certificate3 = new CertificateBuilder().withNewMetadata().withName("cert3").endMetadata().build(); + client.v1().certificates().inNamespace("ns3").create(certificate3); + Boolean deleted = client.v1().certificates().inNamespace("ns3").withName("cert3").delete(); + assertTrue(deleted); + } + + @Test + void shouldLoadCertificate() { + CertManagerClient client = server.get(); + String certificateDefinition = String.join("\n", Arrays.asList( + "apiVersion: cert-manager.io/v1beta1", + "kind: Certificate", + "metadata:", + " name: ca-issuer", + "spec:", + " isCA: true", + " secretName: ca-key-pair", + " commonName: my-csi-app", + " issuerRef:", + " name: selfsigned-issuer", + " kind: Issuer", + " group: cert-manager.io" + )); + io.fabric8.certmanager.api.model.v1beta1.Certificate certificate = client.v1beta1().certificates().inNamespace("ns4").load(new ByteArrayInputStream(certificateDefinition.getBytes())).createOrReplace(); + assertEquals("ca-issuer", certificate.getMetadata().getName()); + assertEquals("ca-key-pair", certificate.getSpec().getSecretName()); + assertEquals("my-csi-app", certificate.getSpec().getCommonName()); + } + +} diff --git a/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha2CertificateCrudTest.java b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha2CertificateCrudTest.java new file mode 100644 index 00000000000..ab03e57a858 --- /dev/null +++ b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha2CertificateCrudTest.java @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.test.crud; + +import io.fabric8.certmanager.api.model.v1alpha2.Certificate; +import io.fabric8.certmanager.api.model.v1alpha2.CertificateBuilder; +import io.fabric8.certmanager.api.model.v1alpha2.CertificateList; +import io.fabric8.certmanager.client.CertManagerClient; +import io.fabric8.certmanager.server.mock.CertManagerServer; +import org.junit.Rule; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +@EnableRuleMigrationSupport +class V1alpha2CertificateCrudTest { + + @Rule + public CertManagerServer server = new CertManagerServer(true, true); + + @Test + void shouldReturnEmptyList() { + CertManagerClient client = server.get(); + CertificateList certificateList = client.v1alpha2().certificates().inNamespace("ns1").list(); + assertNotNull(certificateList); + assertTrue(certificateList.getItems().isEmpty()); + } + + @Test + void shouldListAndGetCertificate() { + CertManagerClient client = server.get(); + Certificate certificate2 = new CertificateBuilder().withNewMetadata().withName("cert2").endMetadata().build(); + client.v1alpha2().certificates().inNamespace("ns2").create(certificate2); + CertificateList certificateList = client.v1alpha2().certificates().inNamespace("ns2").list(); + assertNotNull(certificateList); + assertEquals(1, certificateList.getItems().size()); + } + + @Test + void shouldDeleteACertificate() { + CertManagerClient client = server.get(); + Certificate certificate3 = new CertificateBuilder().withNewMetadata().withName("cert3").endMetadata().build(); + client.v1alpha2().certificates().inNamespace("ns3").create(certificate3); + Boolean deleted = client.v1alpha2().certificates().inNamespace("ns3").withName("cert3").delete(); + assertTrue(deleted); + } + + @Test + void shouldLoadCertificate() { + CertManagerClient client = server.get(); + String certificateDefinition = String.join("\n", Arrays.asList( + "apiVersion: cert-manager.io/v1beta1", + "kind: Certificate", + "metadata:", + " name: ca-issuer", + "spec:", + " isCA: true", + " secretName: ca-key-pair", + " commonName: my-csi-app", + " issuerRef:", + " name: selfsigned-issuer", + " kind: Issuer", + " group: cert-manager.io" + )); + io.fabric8.certmanager.api.model.v1beta1.Certificate certificate = client.v1beta1().certificates().inNamespace("ns4").load(new ByteArrayInputStream(certificateDefinition.getBytes())).createOrReplace(); + assertEquals("ca-issuer", certificate.getMetadata().getName()); + assertEquals("ca-key-pair", certificate.getSpec().getSecretName()); + assertEquals("my-csi-app", certificate.getSpec().getCommonName()); + } + +} diff --git a/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha3CertificateCrudTest.java b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha3CertificateCrudTest.java new file mode 100644 index 00000000000..9447768eff8 --- /dev/null +++ b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1alpha3CertificateCrudTest.java @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.test.crud; + +import io.fabric8.certmanager.api.model.v1alpha3.Certificate; +import io.fabric8.certmanager.api.model.v1alpha3.CertificateBuilder; +import io.fabric8.certmanager.api.model.v1alpha3.CertificateList; +import io.fabric8.certmanager.client.CertManagerClient; +import io.fabric8.certmanager.server.mock.CertManagerServer; +import org.junit.Rule; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +@EnableRuleMigrationSupport +class V1alpha3CertificateCrudTest { + + @Rule + public CertManagerServer server = new CertManagerServer(true, true); + + @Test + void shouldReturnEmptyList() { + CertManagerClient client = server.get(); + CertificateList certificateList = client.v1alpha3().certificates().inNamespace("ns1").list(); + assertNotNull(certificateList); + assertTrue(certificateList.getItems().isEmpty()); + } + + @Test + void shouldListAndGetCertificate() { + CertManagerClient client = server.get(); + Certificate certificate2 = new CertificateBuilder().withNewMetadata().withName("cert2").endMetadata().build(); + client.v1alpha3().certificates().inNamespace("ns2").create(certificate2); + CertificateList certificateList = client.v1alpha3().certificates().inNamespace("ns2").list(); + assertNotNull(certificateList); + assertEquals(1, certificateList.getItems().size()); + } + + @Test + void shouldDeleteACertificate() { + CertManagerClient client = server.get(); + Certificate certificate3 = new CertificateBuilder().withNewMetadata().withName("cert3").endMetadata().build(); + client.v1alpha3().certificates().inNamespace("ns3").create(certificate3); + Boolean deleted = client.v1alpha3().certificates().inNamespace("ns3").withName("cert3").delete(); + assertTrue(deleted); + } + + @Test + void shouldLoadCertificate() { + CertManagerClient client = server.get(); + String certificateDefinition = String.join("\n", Arrays.asList( + "apiVersion: cert-manager.io/v1beta1", + "kind: Certificate", + "metadata:", + " name: ca-issuer", + "spec:", + " isCA: true", + " secretName: ca-key-pair", + " commonName: my-csi-app", + " issuerRef:", + " name: selfsigned-issuer", + " kind: Issuer", + " group: cert-manager.io" + )); + io.fabric8.certmanager.api.model.v1beta1.Certificate certificate = client.v1beta1().certificates().inNamespace("ns4").load(new ByteArrayInputStream(certificateDefinition.getBytes())).createOrReplace(); + assertEquals("ca-issuer", certificate.getMetadata().getName()); + assertEquals("ca-key-pair", certificate.getSpec().getSecretName()); + assertEquals("my-csi-app", certificate.getSpec().getCommonName()); + } + +} diff --git a/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1beta1CertificateCrudTest.java b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1beta1CertificateCrudTest.java new file mode 100644 index 00000000000..020a2abc273 --- /dev/null +++ b/extensions/certmanager/tests/src/test/java/io/fabric8/certmanager/test/crud/V1beta1CertificateCrudTest.java @@ -0,0 +1,88 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.certmanager.test.crud; + +import io.fabric8.certmanager.api.model.v1beta1.Certificate; +import io.fabric8.certmanager.api.model.v1beta1.CertificateBuilder; +import io.fabric8.certmanager.api.model.v1beta1.CertificateList; +import io.fabric8.certmanager.client.CertManagerClient; +import io.fabric8.certmanager.server.mock.CertManagerServer; +import org.junit.Rule; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; + +import java.io.ByteArrayInputStream; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +@EnableRuleMigrationSupport +class V1beta1CertificateCrudTest { + + @Rule + public CertManagerServer server = new CertManagerServer(true, true); + + @Test + void shouldReturnEmptyList() { + CertManagerClient client = server.get(); + CertificateList certificateList = client.v1beta1().certificates().inNamespace("ns1").list(); + assertNotNull(certificateList); + assertTrue(certificateList.getItems().isEmpty()); + } + + @Test + void shouldListAndGetCertificate() { + CertManagerClient client = server.get(); + Certificate certificate2 = new CertificateBuilder().withNewMetadata().withName("cert2").endMetadata().build(); + client.v1beta1().certificates().inNamespace("ns2").create(certificate2); + CertificateList certificateList = client.v1beta1().certificates().inNamespace("ns2").list(); + assertNotNull(certificateList); + assertEquals(1, certificateList.getItems().size()); + } + + @Test + void shouldDeleteACertificate() { + CertManagerClient client = server.get(); + Certificate certificate3 = new CertificateBuilder().withNewMetadata().withName("cert3").endMetadata().build(); + client.v1beta1().certificates().inNamespace("ns3").create(certificate3); + Boolean deleted = client.v1beta1().certificates().inNamespace("ns3").withName("cert3").delete(); + assertTrue(deleted); + } + + @Test + void shouldLoadCertificate() { + CertManagerClient client = server.get(); + String certificateDefinition = String.join("\n", Arrays.asList( + "apiVersion: cert-manager.io/v1beta1", + "kind: Certificate", + "metadata:", + " name: ca-issuer", + "spec:", + " isCA: true", + " secretName: ca-key-pair", + " commonName: my-csi-app", + " issuerRef:", + " name: selfsigned-issuer", + " kind: Issuer", + " group: cert-manager.io" + )); + Certificate certificate = client.v1beta1().certificates().inNamespace("ns4").load(new ByteArrayInputStream(certificateDefinition.getBytes())).createOrReplace(); + assertEquals("ca-issuer", certificate.getMetadata().getName()); + assertEquals("ca-key-pair", certificate.getSpec().getSecretName()); + assertEquals("my-csi-app", certificate.getSpec().getCommonName()); + } + +}