diff --git a/extensions/camel-k/mock/pom.xml b/extensions/camel-k/mock/pom.xml deleted file mode 100644 index e96b77db870..00000000000 --- a/extensions/camel-k/mock/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - camel-k-extension-pom - 6.2-SNAPSHOT - - - - camel-k-mock - Fabric8 :: Camel-K :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - camel-k-client - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServer.java b/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServer.java deleted file mode 100644 index 37bb8b2d386..00000000000 --- a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServer.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.camelk.mock; - -import io.fabric8.camelk.client.DefaultCamelKClient; -import io.fabric8.camelk.client.NamespacedCamelKClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class CamelKMockServer extends KubernetesMockServer { - - public CamelKMockServer() { - super(); - } - - public CamelKMockServer(boolean useHttps) { - super(useHttps); - } - - public CamelKMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/camel.apache.org" }; - } - - public NamespacedCamelKClient createCamelKClient() { - return new DefaultCamelKClient(getMockConfiguration()); - } -} diff --git a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServerExtension.java b/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServerExtension.java deleted file mode 100644 index 68926ef805b..00000000000 --- a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKMockServerExtension.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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.camelk.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.camelk.client.NamespacedCamelKClient; -import io.fabric8.camelk.client.CamelKClient; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(CamelKMockServerExtension.class) or through - * @EnableCamelKMockClient annotation - */ -public class CamelKMockServerExtension extends KubernetesMockServerExtension { - private CamelKMockServer camelKMockServer; - private NamespacedCamelKClient camelKClient; - - @Override - protected void destroy() { - camelKMockServer.destroy(); - camelKClient.close(); - } - - @Override - protected Class getClientType() { - return CamelKClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return CamelKMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableCamelKMockClient a = testClass.getAnnotation(EnableCamelKMockClient.class); - final Map> responses = new HashMap<>(); - camelKMockServer = a.crud() - ? new CamelKMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new CamelKMockServer(a.https()); - camelKMockServer.init(); - camelKClient = camelKMockServer.createCamelKClient(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, camelKClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, camelKMockServer)); - } -} diff --git a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKServer.java b/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKServer.java deleted file mode 100644 index 59073d4c3b1..00000000000 --- a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/CamelKServer.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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.camelk.mock; - -import io.fabric8.camelk.client.CamelKClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class CamelKServer extends ExternalResource { - - protected CamelKMockServer mock; - private CamelKClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public CamelKServer() { - this(true, false); - } - - public CamelKServer(boolean https) { - this(https, false); - } - - public CamelKServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new CamelKMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new CamelKMockServer(https); - mock.init(); - client = mock.createCamelKClient(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - - public CamelKClient getCamelKClient() { - return client; - } - - - public MockServerExpectation expect() { - return mock.expect(); - } - - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } -} diff --git a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/EnableCamelKMockClient.java b/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/EnableCamelKMockClient.java deleted file mode 100644 index bb7642fd5d8..00000000000 --- a/extensions/camel-k/mock/src/main/java/io/fabric8/camelk/mock/EnableCamelKMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.camelk.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling CamelKMockServerExtension JUnit5 extension. - * You may set here two parameters of `CamelKServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(CamelKMockServerExtension.class) -public @interface EnableCamelKMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/camel-k/pom.xml b/extensions/camel-k/pom.xml index e83569d6d90..7e4f799a14c 100755 --- a/extensions/camel-k/pom.xml +++ b/extensions/camel-k/pom.xml @@ -36,7 +36,6 @@ model-v1alpha1 model-v1 client - mock tests diff --git a/extensions/certmanager/mock/pom.xml b/extensions/certmanager/mock/pom.xml deleted file mode 100644 index ec1370328f9..00000000000 --- a/extensions/certmanager/mock/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - certmanager-extension-pom - 6.2-SNAPSHOT - - - certmanager-server-mock - Fabric8 :: Cert Manager :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - certmanager-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServer.java b/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServer.java deleted file mode 100644 index a29e8b73f1c..00000000000 --- a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.server.mock; - -import io.fabric8.certmanager.client.DefaultCertManagerClient; -import io.fabric8.certmanager.client.NamespacedCertManagerClient; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class CertManagerMockServer extends KubernetesMockServer { - - public CertManagerMockServer() { - super(); - } - - public CertManagerMockServer(boolean useHttps) { - super(useHttps); - } - - public CertManagerMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/cert-manager.io" }; - } - - public NamespacedCertManagerClient createCertManager() { - Config config = getMockConfiguration(); - return new DefaultCertManagerClient(config); - } -} diff --git a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServerExtension.java b/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServerExtension.java deleted file mode 100644 index f7cab794eec..00000000000 --- a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.server.mock; - - -import io.fabric8.certmanager.client.CertManagerClient; -import io.fabric8.certmanager.client.NamespacedCertManagerClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(CertManagerMockServerExtension.class) or through - * @EnableCertManagerMockClient annotation - */ -public class CertManagerMockServerExtension extends KubernetesMockServerExtension { - private CertManagerMockServer certManagerMockServer; - private NamespacedCertManagerClient certManagerClient; - - @Override - protected void destroy() { - certManagerMockServer.destroy(); - certManagerClient.close(); - } - - @Override - protected Class getClientType() { - return CertManagerClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return CertManagerMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableCertManagerMockClient a = testClass.getAnnotation(EnableCertManagerMockClient.class); - final Map> responses = new HashMap<>(); - certManagerMockServer = a.crud() - ? new CertManagerMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new CertManagerMockServer(a.https()); - certManagerMockServer.init(); - certManagerClient = certManagerMockServer.createCertManager(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, certManagerClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, certManagerMockServer)); - } -} - diff --git a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerServer.java b/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerServer.java deleted file mode 100644 index 0d5d62b0e27..00000000000 --- a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/CertManagerServer.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.server.mock; - -import io.fabric8.certmanager.client.CertManagerClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class CertManagerServer extends ExternalResource { - - protected CertManagerMockServer mock; - private CertManagerClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public CertManagerServer() { - this(true, false); - } - - public CertManagerServer(boolean https) { - this(https, false); - } - - public CertManagerServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new CertManagerMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new CertManagerMockServer(https); - mock.init(); - client = mock.createCertManager(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - - public CertManagerClient getCertManagerClient() { - return client; - } - - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/EnableCertManagerMockClient.java b/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/EnableCertManagerMockClient.java deleted file mode 100644 index ee51a99644b..00000000000 --- a/extensions/certmanager/mock/src/main/java/io/fabric8/certmanager/server/mock/EnableCertManagerMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling CertManagerMockServerExtension JUnit5 extension. - * You may set here two parameters of `CertManagerKServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(CertManagerMockServerExtension.class) -public @interface EnableCertManagerMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/certmanager/pom.xml b/extensions/certmanager/pom.xml index adc7d83d6a2..fb16b6c39a6 100644 --- a/extensions/certmanager/pom.xml +++ b/extensions/certmanager/pom.xml @@ -38,7 +38,6 @@ model-v1beta1 model-v1 client - mock examples tests diff --git a/extensions/chaosmesh/mock/pom.xml b/extensions/chaosmesh/mock/pom.xml deleted file mode 100644 index f1221cf50cb..00000000000 --- a/extensions/chaosmesh/mock/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - chaosmesh - 6.2-SNAPSHOT - - - chaosmesh-server-mock - Fabric8 :: Chaos Mesh :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - chaosmesh-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServer.java b/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServer.java deleted file mode 100644 index 38221453460..00000000000 --- a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServer.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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.chaosmesh.server.mock; - -import io.fabric8.chaosmesh.client.DefaultChaosMeshClient; -import io.fabric8.chaosmesh.client.NamespacedChaosMeshClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class ChaosMeshMockServer extends KubernetesMockServer { - public ChaosMeshMockServer() { - super(); - } - - public ChaosMeshMockServer(boolean useHttps) { - super(useHttps); - } - - public ChaosMeshMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/chaos-mesh.org" }; - } - - public NamespacedChaosMeshClient createChaosMeshClient() { - return new DefaultChaosMeshClient(getMockConfiguration()); - } -} diff --git a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServerExtension.java b/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServerExtension.java deleted file mode 100644 index e787a4fb670..00000000000 --- a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.chaosmesh.server.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.chaosmesh.client.NamespacedChaosMeshClient; -import io.fabric8.chaosmesh.client.ChaosMeshClient; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(OpenShiftMockServerExtension.class) or through - * @EnableOpenShiftMockClient annotation - */ -public class ChaosMeshMockServerExtension extends KubernetesMockServerExtension { - private ChaosMeshMockServer chaosMeshMockServer; - private NamespacedChaosMeshClient chaosMeshClient; - - @Override - protected void destroy() { - chaosMeshMockServer.destroy(); - chaosMeshClient.close(); - } - - @Override - protected Class getClientType() { - return ChaosMeshClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return ChaosMeshMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableChaosMeshMockClient a = testClass.getAnnotation(EnableChaosMeshMockClient.class); - final Map> responses = new HashMap<>(); - chaosMeshMockServer = a.crud() - ? new ChaosMeshMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new ChaosMeshMockServer(a.https()); - chaosMeshMockServer.init(); - chaosMeshClient = chaosMeshMockServer.createChaosMeshClient(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, chaosMeshClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, chaosMeshMockServer)); - } -} - diff --git a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshServer.java b/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshServer.java deleted file mode 100644 index 59acd2ffdfc..00000000000 --- a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/ChaosMeshServer.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.chaosmesh.server.mock; - -import io.fabric8.chaosmesh.client.ChaosMeshClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class ChaosMeshServer extends ExternalResource { - - protected ChaosMeshMockServer mock; - private ChaosMeshClient client; - - private final boolean https; - private final boolean crudMode; - - public ChaosMeshServer() { - this(true, false); - } - - public ChaosMeshServer(boolean https) { - this(https, false); - } - - public ChaosMeshServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new ChaosMeshMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new ChaosMeshMockServer(https); - mock.init(); - client = mock.createChaosMeshClient(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public ChaosMeshClient get() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/EnableChaosMeshMockClient.java b/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/EnableChaosMeshMockClient.java deleted file mode 100644 index 369f68cfff3..00000000000 --- a/extensions/chaosmesh/mock/src/main/java/io/fabric8/chaosmesh/server/mock/EnableChaosMeshMockClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.chaosmesh.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling ChaoMeshMockServerExtension JUnit5 extension. - * You may set here two parameters of `ChaosMeshServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(ChaosMeshMockServerExtension.class) -public @interface EnableChaosMeshMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/chaosmesh/pom.xml b/extensions/chaosmesh/pom.xml index 6f453835380..92a69007ae9 100644 --- a/extensions/chaosmesh/pom.xml +++ b/extensions/chaosmesh/pom.xml @@ -36,7 +36,6 @@ model client - mock examples tests diff --git a/extensions/chaosmesh/tests/src/test/java/io/fabric8/chaosmesh/test/crud/IoChaosTest.java b/extensions/chaosmesh/tests/src/test/java/io/fabric8/chaosmesh/test/crud/IoChaosTest.java index 010429bfdd0..a3ebced3ddb 100644 --- a/extensions/chaosmesh/tests/src/test/java/io/fabric8/chaosmesh/test/crud/IoChaosTest.java +++ b/extensions/chaosmesh/tests/src/test/java/io/fabric8/chaosmesh/test/crud/IoChaosTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class IOChaosTest { @@ -77,7 +76,7 @@ void testCrud() { assertEquals("true", client.ioChaos().withName("latency").get().getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.ioChaos().withName("latency").delete().size() == 1); + assertEquals(1, client.ioChaos().withName("latency").delete().size()); assertNull(client.ioChaos().withName("latency").get()); } } diff --git a/extensions/istio/mock/pom.xml b/extensions/istio/mock/pom.xml deleted file mode 100644 index c64525adfb8..00000000000 --- a/extensions/istio/mock/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - istio-extension-pom - 6.2-SNAPSHOT - - - istio-server-mock - Fabric8 :: Istio :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - istio-client - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/EnableIstioMockClient.java b/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/EnableIstioMockClient.java deleted file mode 100644 index 3b5f70f98b4..00000000000 --- a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/EnableIstioMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.istio.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling IstioMockServerExtension JUnit5 extension. - * You may set here two parameters of `IstioServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(IstioMockServerExtension.class) -public @interface EnableIstioMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServer.java b/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServer.java deleted file mode 100644 index 95b2f4b8a76..00000000000 --- a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServer.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.istio.mock; - -import io.fabric8.istio.client.DefaultIstioClient; -import io.fabric8.istio.client.NamespacedIstioClient; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class IstioMockServer extends KubernetesMockServer { - public IstioMockServer() { - super(); - } - - public IstioMockServer(boolean useHttps) { - super(useHttps); - } - - public IstioMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/networking.istio.io", "/apis/security.istio.io", "/apis/operator.istio.io" }; - } - - public NamespacedIstioClient createIstio() { - Config config = getMockConfiguration(); - return new DefaultIstioClient(config); - } -} diff --git a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServerExtension.java b/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServerExtension.java deleted file mode 100644 index 1e06500106e..00000000000 --- a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioMockServerExtension.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.istio.mock; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -import org.junit.jupiter.api.extension.ExtensionContext; - -import io.fabric8.istio.client.IstioClient; -import io.fabric8.istio.client.NamespacedIstioClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(KnativeMockServerExtension.class) or through - * @EnableKnativeMockClient annotation - */ -public class IstioMockServerExtension extends KubernetesMockServerExtension { - private IstioMockServer mockServer; - private NamespacedIstioClient istioClient; - - @Override - protected void destroy() { - mockServer.destroy(); - istioClient.close(); - } - - @Override - protected Class getClientType() { - return IstioClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return IstioMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableIstioMockClient a = testClass.getAnnotation(EnableIstioMockClient.class); - final Map> responses = new HashMap<>(); - mockServer = a.crud() - ? new IstioMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new IstioMockServer(a.https()); - mockServer.init(); - istioClient = mockServer.createIstio(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, istioClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, mockServer)); - } -} diff --git a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioServer.java b/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioServer.java deleted file mode 100644 index a9521b9fa79..00000000000 --- a/extensions/istio/mock/src/main/java/io/fabric8/istio/mock/IstioServer.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.istio.mock; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -import org.junit.rules.ExternalResource; - -import io.fabric8.istio.client.IstioClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; - -public class IstioServer extends ExternalResource { - - protected IstioMockServer mock; - private IstioClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public IstioServer() { - this(true, false); - } - - public IstioServer(boolean https) { - this(https, false); - } - - public IstioServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new IstioMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new IstioMockServer(https); - mock.init(); - client = mock.createIstio(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public IstioClient getIstioClient() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/istio/pom.xml b/extensions/istio/pom.xml index 4d9b247c0bd..ddbd9ad4086 100755 --- a/extensions/istio/pom.xml +++ b/extensions/istio/pom.xml @@ -36,7 +36,6 @@ model-v1alpha3 model-v1beta1 client - mock examples tests diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/DestinationRuleTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/DestinationRuleTest.java index 52142ac454e..7684e0f767f 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/DestinationRuleTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/DestinationRuleTest.java @@ -31,10 +31,10 @@ /** * @author Christophe Laprun */ -public class DestinationRuleTest { +class DestinationRuleTest { @Test - public void loadingFromYAMLIssue82ShouldWork() throws Exception { + void loadingFromYAMLIssue82ShouldWork() throws Exception { final InputStream inputStream = DestinationRuleTest.class.getResourceAsStream("/v1alpha3/destination-rule-issue82.yaml"); final DestinationRule destinationRule = Serialization.yamlMapper().readValue(inputStream, DestinationRule.class); diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/EnvoyFilterTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/EnvoyFilterTest.java index dd8567da3a8..db4aa1775bc 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/EnvoyFilterTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/EnvoyFilterTest.java @@ -25,15 +25,15 @@ import java.io.InputStream; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Christophe Laprun */ -public class EnvoyFilterTest { +class EnvoyFilterTest { @Test - public void loadingFromYAMLIssue99ShouldWork() throws Exception { + void loadingFromYAMLIssue99ShouldWork() throws Exception { final InputStream inputStream = EnvoyFilterTest.class.getResourceAsStream("/v1alpha3/envoy-filter-issue99.yaml"); final EnvoyFilter filter = Serialization.yamlMapper().readValue(inputStream, EnvoyFilter.class); diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/VirtualServiceTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/VirtualServiceTest.java index 083bfff93ef..114c3df27e6 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/VirtualServiceTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1alpha3/VirtualServiceTest.java @@ -25,12 +25,12 @@ import java.io.InputStream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class VirtualServiceTest { +class VirtualServiceTest { @Test - public void roundtripBasicVirtualServiceShouldWork() throws Exception { + void roundtripBasicVirtualServiceShouldWork() throws Exception { final String apiVersion = "networking.istio.io/v1alpha3"; final VirtualService virtualService = new VirtualServiceBuilder().withApiVersion(apiVersion) .withNewMetadata().withName("vs_name").withNamespace("ns").endMetadata() @@ -55,7 +55,7 @@ public void roundtripBasicVirtualServiceShouldWork() throws Exception { } @Test - public void loadingFromYAMLIssue103ShouldWork() throws Exception { + void loadingFromYAMLIssue103ShouldWork() throws Exception { final InputStream inputStream = VirtualServiceTest.class.getResourceAsStream("/v1alpha3/virtual-service-issue103.yaml"); final VirtualService virtualService = Serialization.yamlMapper().readValue(inputStream, VirtualService.class); @@ -76,7 +76,7 @@ public void loadingFromYAMLIssue103ShouldWork() throws Exception { } @Test - public void loadingVirtualServiceWithValidationMessages() throws Exception { + void loadingVirtualServiceWithValidationMessages() throws Exception { final InputStream inputStream = VirtualServiceTest.class.getResourceAsStream("/v1alpha3/virtual-service-issue4315.yaml"); final VirtualService virtualService = Serialization.yamlMapper().readValue(inputStream, VirtualService.class); assertEquals(3, virtualService.getStatus().getValidationMessages().size()); diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/CorsPolicyTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/CorsPolicyTest.java index 33d83dd72e6..f34d694668b 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/CorsPolicyTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/CorsPolicyTest.java @@ -22,15 +22,15 @@ import io.fabric8.kubernetes.client.utils.Serialization; import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Christophe Laprun */ -public class CorsPolicyTest { +class CorsPolicyTest { @Test - public void roundtripShouldWork() throws Exception { + void roundtripShouldWork() throws Exception { final String prefix = "example.com"; final String allowOrigin = "bar.com"; final CorsPolicy policy = new CorsPolicyBuilder() diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java index 259e68aa737..5b9756a5a85 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/GatewayTest.java @@ -26,7 +26,6 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Assert; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.Yaml; @@ -127,7 +126,7 @@ void testDeleteOrphan() throws InterruptedException { } @Test - public void checkBasicGateway() throws Exception { + void checkBasicGateway() throws Exception { final Gateway gateway = new GatewayBuilder() .withNewMetadata() .withName("httpbin-gateway") @@ -146,45 +145,45 @@ public void checkBasicGateway() throws Exception { Yaml parser = new Yaml(); final Map reloaded = parser.loadAs(output, Map.class); - Assert.assertEquals("Gateway", reloaded.get("kind")); + assertEquals("Gateway", reloaded.get("kind")); final Map metadata = (Map) reloaded.get("metadata"); - Assert.assertNotNull(metadata); - Assert.assertEquals("httpbin-gateway", metadata.get("name")); + assertNotNull(metadata); + assertEquals("httpbin-gateway", metadata.get("name")); final Map spec = (Map) reloaded.get("spec"); - Assert.assertNotNull(spec); + assertNotNull(spec); final Map selector = spec.get("selector"); - Assert.assertNotNull(selector); - Assert.assertEquals("ingressgateway", selector.get("istio")); + assertNotNull(selector); + assertEquals("ingressgateway", selector.get("istio")); final List servers = (List) spec.get("servers"); - Assert.assertNotNull(servers); - Assert.assertEquals(2, servers.size()); + assertNotNull(servers); + assertEquals(2, servers.size()); Map server = servers.get(0); - Assert.assertNotNull(server); + assertNotNull(server); Map port = server.get("port"); - Assert.assertNotNull(port); - Assert.assertEquals(80, port.get("number")); - Assert.assertEquals("http", port.get("name")); - Assert.assertEquals("HTTP", port.get("protocol")); + assertNotNull(port); + assertEquals(80, port.get("number")); + assertEquals("http", port.get("name")); + assertEquals("HTTP", port.get("protocol")); final List hosts = (List) server.get("hosts"); - Assert.assertNotNull(hosts); - Assert.assertEquals("httpbin.example.com", hosts.get(0)); + assertNotNull(hosts); + assertEquals("httpbin.example.com", hosts.get(0)); server = servers.get(1); - Assert.assertNotNull(server); + assertNotNull(server); port = server.get("port"); - Assert.assertNotNull(port); - Assert.assertEquals(443, port.get("number")); - Assert.assertEquals("tls-0", port.get("name")); - Assert.assertEquals("TLS", port.get("protocol")); + assertNotNull(port); + assertEquals(443, port.get("number")); + assertEquals("tls-0", port.get("name")); + assertEquals("TLS", port.get("protocol")); final Map tls = server.get("tls"); - Assert.assertEquals("TLSV1_2", tls.get("minProtocolVersion")); + assertEquals("TLSV1_2", tls.get("minProtocolVersion")); } } diff --git a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java index afb0fbfa5e6..92a2df79a28 100644 --- a/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java +++ b/extensions/istio/tests/src/test/java/io/fabric8/istio/test/v1beta1/VirtualServiceTest.java @@ -35,7 +35,6 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; import io.fabric8.kubernetes.client.utils.Serialization; import okhttp3.mockwebserver.RecordedRequest; -import org.junit.Assert; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.Yaml; @@ -166,7 +165,7 @@ void testDeleteOrphan() throws InterruptedException { */ // @formatter:on @Test - public void checkBasicVirtualService() throws Exception { + void checkBasicVirtualService() throws Exception { final VirtualService virtualService = new VirtualServiceBuilder() .withNewMetadata() .withName("details") @@ -189,32 +188,32 @@ public void checkBasicVirtualService() throws Exception { Yaml parser = new Yaml(); final Map reloaded = parser.loadAs(output, Map.class); - Assert.assertEquals("VirtualService", reloaded.get("kind")); + assertEquals("VirtualService", reloaded.get("kind")); final Map metadata = (Map) reloaded.get("metadata"); - Assert.assertNotNull(metadata); - Assert.assertEquals("details", metadata.get("name")); + assertNotNull(metadata); + assertEquals("details", metadata.get("name")); final Map spec = (Map) reloaded.get("spec"); - Assert.assertNotNull(spec); + assertNotNull(spec); final List https = (List) spec.get("http"); - Assert.assertNotNull(https); + assertNotNull(https); final Map http = https.get(0); - Assert.assertNotNull(http); + assertNotNull(http); final List routes = (List) http.get("route"); - Assert.assertNotNull(routes); + assertNotNull(routes); final Map route = routes.get(0); - Assert.assertNotNull(route); + assertNotNull(route); final Map destination = route.get("destination"); - Assert.assertNotNull(destination); + assertNotNull(destination); - Assert.assertEquals("details", destination.get("host")); - Assert.assertEquals("v1", destination.get("subset")); + assertEquals("details", destination.get("host")); + assertEquals("v1", destination.get("subset")); } // @formatter:off @@ -245,7 +244,7 @@ public void checkBasicVirtualService() throws Exception { */ // @formatter:on @Test - public void checkVirtualServiceWithMatch() throws IOException { + void checkVirtualServiceWithMatch() throws IOException { final String reviewsHost = "reviews.prod.svc.cluster.local"; final VirtualService resource = new VirtualServiceBuilder() .withNewMetadata().withName("reviews-route").endMetadata() @@ -271,39 +270,39 @@ public void checkVirtualServiceWithMatch() throws IOException { Yaml parser = new Yaml(); final Map reloaded = parser.loadAs(output, Map.class); - Assert.assertEquals("VirtualService", reloaded.get("kind")); + assertEquals("VirtualService", reloaded.get("kind")); final Map metadata = (Map) reloaded.get("metadata"); - Assert.assertNotNull(metadata); - Assert.assertEquals("reviews-route", metadata.get("name")); + assertNotNull(metadata); + assertEquals("reviews-route", metadata.get("name")); final Map spec = (Map) reloaded.get("spec"); - Assert.assertNotNull(spec); + assertNotNull(spec); - Assert.assertEquals(reviewsHost, ((List) spec.get("hosts")).get(0).toString()); + assertEquals(reviewsHost, ((List) spec.get("hosts")).get(0).toString()); final List https = (List) spec.get("http"); - Assert.assertNotNull(https); + assertNotNull(https); Map http = https.get(0); - Assert.assertNotNull(http); + assertNotNull(http); final List matches = (List) http.get("match"); - Assert.assertNotNull(matches); - Assert.assertEquals(2, matches.size()); - Assert.assertEquals("/wpcatalog", ((Map) matches.get(0).get("uri")).get("prefix")); - Assert.assertEquals("/consumercatalog", ((Map) matches.get(1).get("uri")).get("prefix")); + assertNotNull(matches); + assertEquals(2, matches.size()); + assertEquals("/wpcatalog", ((Map) matches.get(0).get("uri")).get("prefix")); + assertEquals("/consumercatalog", ((Map) matches.get(1).get("uri")).get("prefix")); - Assert.assertEquals("/newcatalog", http.get("rewrite").get("uri")); + assertEquals("/newcatalog", http.get("rewrite").get("uri")); Map destination = (Map) ((List) http.get("route")).get(0).get("destination"); - Assert.assertEquals(reviewsHost, destination.get("host")); - Assert.assertEquals("v2", destination.get("subset")); + assertEquals(reviewsHost, destination.get("host")); + assertEquals("v2", destination.get("subset")); http = https.get(1); destination = (Map) ((List) http.get("route")).get(0).get("destination"); - Assert.assertEquals(reviewsHost, destination.get("host")); - Assert.assertEquals("v1", destination.get("subset")); + assertEquals(reviewsHost, destination.get("host")); + assertEquals("v1", destination.get("subset")); } // @formatter:off @@ -331,7 +330,7 @@ public void checkVirtualServiceWithMatch() throws IOException { */ // @formatter:on @Test - public void checkVirtualServiceWithPortSelector() throws IOException { + void checkVirtualServiceWithPortSelector() throws IOException { final String reviewsHost = "reviews.prod.svc.cluster.local"; final VirtualService resource = new VirtualServiceBuilder() .withNewMetadata().withName("reviews-route").endMetadata() @@ -356,43 +355,43 @@ public void checkVirtualServiceWithPortSelector() throws IOException { Yaml parser = new Yaml(); final Map reloaded = parser.loadAs(output, Map.class); - Assert.assertEquals("VirtualService", reloaded.get("kind")); + assertEquals("VirtualService", reloaded.get("kind")); final Map metadata = (Map) reloaded.get("metadata"); - Assert.assertNotNull(metadata); - Assert.assertEquals("reviews-route", metadata.get("name")); + assertNotNull(metadata); + assertEquals("reviews-route", metadata.get("name")); final Map spec = (Map) reloaded.get("spec"); - Assert.assertNotNull(spec); + assertNotNull(spec); - Assert.assertEquals(reviewsHost, ((List) spec.get("hosts")).get(0).toString()); + assertEquals(reviewsHost, ((List) spec.get("hosts")).get(0).toString()); final List https = (List) spec.get("http"); - Assert.assertNotNull(https); + assertNotNull(https); Map http = https.get(0); - Assert.assertNotNull(http); + assertNotNull(http); Map destination = (Map) ((List) http.get("route")).get(0).get("destination"); - Assert.assertEquals(reviewsHost, destination.get("host")); - Assert.assertEquals("v2", destination.get("subset")); + assertEquals(reviewsHost, destination.get("host")); + assertEquals("v2", destination.get("subset")); final Map portSelector1 = (Map) (destination.get("port")); - Assert.assertNotNull(portSelector1); - Assert.assertEquals(9090, portSelector1.get("number").intValue()); + assertNotNull(portSelector1); + assertEquals(9090, portSelector1.get("number").intValue()); http = https.get(1); destination = (Map) ((List) http.get("route")).get(0).get("destination"); - Assert.assertEquals(reviewsHost, destination.get("host")); - Assert.assertEquals("v1", destination.get("subset")); + assertEquals(reviewsHost, destination.get("host")); + assertEquals("v1", destination.get("subset")); final Map portSelector2 = (Map) (destination.get("port")); - Assert.assertNotNull(portSelector2); - Assert.assertEquals(9090, portSelector2.get("number").intValue()); + assertNotNull(portSelector2); + assertEquals(9090, portSelector2.get("number").intValue()); } @Test - public void loadingFromYAMLShouldWork() throws Exception { + void loadingFromYAMLShouldWork() throws Exception { final InputStream inputStream = VirtualServiceTest.class.getResourceAsStream("/v1beta1/virtual-service.yaml"); // @formatter:off @@ -417,23 +416,23 @@ public void loadingFromYAMLShouldWork() throws Exception { // @formatter:on final VirtualService virtualService = Serialization.yamlMapper().readValue(inputStream, VirtualService.class); - Assert.assertEquals("ratings.prod.svc.cluster.local", virtualService.getSpec().getHosts().get(0)); + assertEquals("ratings.prod.svc.cluster.local", virtualService.getSpec().getHosts().get(0)); final List http = virtualService.getSpec().getHttp(); - Assert.assertEquals(1, http.size()); + assertEquals(1, http.size()); final HTTPRoute route = http.get(0); final List destinations = route.getRoute(); - Assert.assertEquals(1, destinations.size()); + assertEquals(1, destinations.size()); final Destination destination = destinations.get(0).getDestination(); - Assert.assertEquals("ratings.prod.svc.cluster.local", destination.getHost()); - Assert.assertEquals("v1", destination.getSubset()); + assertEquals("ratings.prod.svc.cluster.local", destination.getHost()); + assertEquals("v1", destination.getSubset()); assertNull(route.getFault().getDelay()); final HTTPFaultInjectionAbort abort = route.getFault().getAbort(); - Assert.assertEquals(10, abort.getPercentage().getValue().intValue()); - Assert.assertEquals(400, ((HTTPFaultInjectionAbortHttpStatus) abort.getErrorType()).getHttpStatus().intValue()); + assertEquals(10, abort.getPercentage().getValue().intValue()); + assertEquals(400, ((HTTPFaultInjectionAbortHttpStatus) abort.getErrorType()).getHttpStatus().intValue()); } @Test - public void loadingFromYAMLIssue48() throws Exception { + void loadingFromYAMLIssue48() throws Exception { final InputStream inputStream = VirtualServiceTest.class.getResourceAsStream("/v1beta1/virtual-service-issue48.yaml"); final VirtualService virtualService = Serialization.yamlMapper().readValue(inputStream, VirtualService.class); @@ -455,13 +454,13 @@ public void loadingFromYAMLIssue48() throws Exception { final Map headers = virtualService.getSpec().getHttp().get(0).getMatch().get(0).getHeaders(); final StringMatch stringMatch = headers.get("baggage-user-agent"); - Assert.assertEquals(StringMatchRegex.class, stringMatch.getMatchType().getClass()); + assertEquals(StringMatchRegex.class, stringMatch.getMatchType().getClass()); StringMatchRegex regex = (StringMatchRegex) stringMatch.getMatchType(); - Assert.assertEquals(".*DarkLaunch.*", regex.getRegex()); + assertEquals(".*DarkLaunch.*", regex.getRegex()); } @Test - public void allowCredentialsShouldWork() throws IOException { + void allowCredentialsShouldWork() throws IOException { final InputStream inputStream = VirtualServiceTest.class.getResourceAsStream("/v1beta1/virtual-service-issue119.yaml"); final VirtualService virtualService = Serialization.yamlMapper().readValue(inputStream, VirtualService.class); diff --git a/extensions/knative/mock/pom.xml b/extensions/knative/mock/pom.xml deleted file mode 100644 index 9d54528afa1..00000000000 --- a/extensions/knative/mock/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - knative-extension-pom - 6.2-SNAPSHOT - - - knative-mock - Fabric8 :: Knative :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - knative-client - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/EnableKnativeMockClient.java b/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/EnableKnativeMockClient.java deleted file mode 100644 index cbed1240f4b..00000000000 --- a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/EnableKnativeMockClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.knative.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling KnativeMockServerExtension JUnit5 extension. - * You may set here two parameters of `KnativeServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(KnativeMockServerExtension.class) -public @interface EnableKnativeMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServer.java b/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServer.java deleted file mode 100644 index 95dd9c7e195..00000000000 --- a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.knative.mock; - -import io.fabric8.knative.client.DefaultKnativeClient; -import io.fabric8.knative.client.NamespacedKnativeClient; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class KnativeMockServer extends KubernetesMockServer { - - public KnativeMockServer() { - super(); - } - - public KnativeMockServer(boolean useHttps) { - super(useHttps); - } - - public KnativeMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/serving.knative.dev", "/apis/eventing/knative.dev" }; - } - - public NamespacedKnativeClient createKnative() { - Config config = getMockConfiguration(); - return new DefaultKnativeClient(config); - } -} diff --git a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServerExtension.java b/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServerExtension.java deleted file mode 100644 index f1399679e9e..00000000000 --- a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeMockServerExtension.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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.knative.mock; - - -import io.fabric8.knative.client.KnativeClient; -import io.fabric8.knative.client.NamespacedKnativeClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(KnativeMockServerExtension.class) or through - * @EnableKnativeMockClient annotation - */ -public class KnativeMockServerExtension extends KubernetesMockServerExtension { - private KnativeMockServer knativeMockServer; - private NamespacedKnativeClient knativeClient; - - @Override - protected void destroy() { - knativeMockServer.destroy(); - knativeClient.close(); - } - - @Override - protected Class getClientType() { - return KnativeClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return KnativeMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableKnativeMockClient a = testClass.getAnnotation(EnableKnativeMockClient.class); - final Map> responses = new HashMap<>(); - knativeMockServer = a.crud() - ? new KnativeMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new KnativeMockServer(a.https()); - knativeMockServer.init(); - knativeClient = knativeMockServer.createKnative(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, knativeClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, knativeMockServer)); - } -} diff --git a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeServer.java b/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeServer.java deleted file mode 100644 index 1aa3f62ba2b..00000000000 --- a/extensions/knative/mock/src/main/java/io/fabric8/knative/mock/KnativeServer.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * 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.knative.mock; - -import io.fabric8.knative.client.KnativeClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class KnativeServer extends ExternalResource { - - protected KnativeMockServer mock; - private KnativeClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public KnativeServer() { - this(true, false); - } - - public KnativeServer(boolean https) { - this(https, false); - } - - public KnativeServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new KnativeMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new KnativeMockServer(https); - mock.init(); - client = mock.createKnative(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public KnativeClient getKnativeClient() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } - - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } -} diff --git a/extensions/knative/pom.xml b/extensions/knative/pom.xml index 1f45c4192c1..ae370e01cc1 100755 --- a/extensions/knative/pom.xml +++ b/extensions/knative/pom.xml @@ -35,7 +35,6 @@ model client - mock examples tests diff --git a/extensions/open-cluster-management/mock/pom.xml b/extensions/open-cluster-management/mock/pom.xml deleted file mode 100644 index 5902449ba61..00000000000 --- a/extensions/open-cluster-management/mock/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - open-cluster-management - 6.2-SNAPSHOT - - - open-cluster-management-server-mock - Fabric8 :: Open Cluster Management :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - open-cluster-management-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/EnableOpenClusterManagementMockClient.java b/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/EnableOpenClusterManagementMockClient.java deleted file mode 100644 index aea942ee123..00000000000 --- a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/EnableOpenClusterManagementMockClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.openclustermanagement.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling OpenClusterManagementMockServerExtension JUnit5 extension. - * You may set here two parameters of `OpenClusterManagementServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(OpenClusterManagementMockServerExtension.class) -public @interface EnableOpenClusterManagementMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServer.java b/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServer.java deleted file mode 100644 index 7b9aeedce62..00000000000 --- a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServer.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.openclustermanagement.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.openclustermanagement.client.DefaultOpenClusterManagementClient; -import io.fabric8.openclustermanagement.client.NamespacedOpenClusterManagementClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class OpenClusterManagementMockServer extends KubernetesMockServer { - public OpenClusterManagementMockServer() { - super(); - } - - public OpenClusterManagementMockServer(boolean useHttps) { - super(useHttps); - } - - public OpenClusterManagementMockServer(Context context, MockWebServer server, - Map> responses, Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/apps.open-cluster-management.io", - "/apis/cluster.open-cluster-management.io", - "/apis/discovery.open-cluster-management.io", - "/apis/observability.open-cluster-management.io", - "/apis/operator.open-cluster-management.io", - "/apis/policy.open-cluster-management.io", - "/apis/search.open-cluster-management.io", - }; - } - - public NamespacedOpenClusterManagementClient createOpenClusterManagement() { - return new DefaultOpenClusterManagementClient(getMockConfiguration()); - } -} diff --git a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServerExtension.java b/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServerExtension.java deleted file mode 100644 index d66cd4f1a7a..00000000000 --- a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.openclustermanagement.server.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.openclustermanagement.client.NamespacedOpenClusterManagementClient; -import io.fabric8.openclustermanagement.client.OpenClusterManagementClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(OpenClusterManagementServerExtension.class) or through - * @EnableOpenClusterManagementMockClient annotation - */ -public class OpenClusterManagementMockServerExtension extends KubernetesMockServerExtension { - private OpenClusterManagementMockServer openClusterManagementMockServer; - private NamespacedOpenClusterManagementClient openClusterManagementClient; - - @Override - protected void destroy() { - openClusterManagementMockServer.destroy(); - openClusterManagementClient.close(); - } - - @Override - protected Class getClientType() { - return OpenClusterManagementClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return OpenClusterManagementMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableOpenClusterManagementMockClient a = testClass.getAnnotation(EnableOpenClusterManagementMockClient.class); - final Map> responses = new HashMap<>(); - openClusterManagementMockServer = a.crud() - ? new OpenClusterManagementMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new OpenClusterManagementMockServer(a.https()); - openClusterManagementMockServer.init(); - openClusterManagementClient = openClusterManagementMockServer.createOpenClusterManagement(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, openClusterManagementClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, openClusterManagementMockServer)); - } -} - - diff --git a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementServer.java b/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementServer.java deleted file mode 100644 index 54ae9aa199b..00000000000 --- a/extensions/open-cluster-management/mock/src/main/java/io/fabric8/openclustermanagement/server/mock/OpenClusterManagementServer.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.openclustermanagement.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.openclustermanagement.client.OpenClusterManagementClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class OpenClusterManagementServer extends ExternalResource { - - protected OpenClusterManagementMockServer mock; - private OpenClusterManagementClient client; - - private final boolean https; - private final boolean crudMode; - - public OpenClusterManagementServer() { - this(true, false); - } - - public OpenClusterManagementServer(boolean https) { - this(https, false); - } - - public OpenClusterManagementServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new OpenClusterManagementMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new OpenClusterManagementMockServer(https); - mock.init(); - client = mock.createOpenClusterManagement(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public OpenClusterManagementClient get() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/open-cluster-management/pom.xml b/extensions/open-cluster-management/pom.xml index fa9be62d345..93e4b171f3a 100644 --- a/extensions/open-cluster-management/pom.xml +++ b/extensions/open-cluster-management/pom.xml @@ -44,7 +44,6 @@ model-policy model-search client - mock tests examples diff --git a/extensions/service-catalog/mock/pom.xml b/extensions/service-catalog/mock/pom.xml deleted file mode 100644 index 304fbdbb2e1..00000000000 --- a/extensions/service-catalog/mock/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - service-catalog - 6.2-SNAPSHOT - - - servicecatalog-server-mock - Fabric8 :: Service Catalog :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - servicecatalog-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/EnableServiceCatalogMockClient.java b/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/EnableServiceCatalogMockClient.java deleted file mode 100644 index 6cd75a5f39c..00000000000 --- a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/EnableServiceCatalogMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.servicecatalog.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling ServiceCatalogMockServerExtension JUnit5 extension. - * You may set here two parameters of `ServiceCatalogServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(ServiceCatalogMockServerExtension.class) -public @interface EnableServiceCatalogMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServer.java b/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServer.java deleted file mode 100644 index 1ab0585c420..00000000000 --- a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.servicecatalog.server.mock; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.servicecatalog.client.DefaultServiceCatalogClient; -import io.fabric8.servicecatalog.client.NamespacedServiceCatalogClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class ServiceCatalogMockServer extends KubernetesMockServer { - - public ServiceCatalogMockServer() { - super(); - } - - public ServiceCatalogMockServer(boolean useHttps) { - super(useHttps); - } - - public ServiceCatalogMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/servicecatalog.k8s.io" }; - } - - public NamespacedServiceCatalogClient createServiceCatalog() { - Config config = getMockConfiguration(); - return new DefaultServiceCatalogClient(config); - } -} diff --git a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServerExtension.java b/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServerExtension.java deleted file mode 100644 index c0b426b6376..00000000000 --- a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogMockServerExtension.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.servicecatalog.server.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.servicecatalog.client.ServiceCatalogClient; -import io.fabric8.servicecatalog.client.NamespacedServiceCatalogClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(ServiceCatalogMockServerExtension.class) or through - * @EnableServiceCatalogMockClient annotation - */ -public class ServiceCatalogMockServerExtension extends KubernetesMockServerExtension { - private ServiceCatalogMockServer serviceCatalogMockServer; - private NamespacedServiceCatalogClient serviceCatalogClient; - - @Override - protected void destroy() { - serviceCatalogMockServer.destroy(); - serviceCatalogClient.close(); - } - - @Override - protected Class getClientType() { - return ServiceCatalogClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return ServiceCatalogMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableServiceCatalogMockClient a = testClass.getAnnotation(EnableServiceCatalogMockClient.class); - final Map> responses = new HashMap<>(); - serviceCatalogMockServer = a.crud() - ? new ServiceCatalogMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new ServiceCatalogMockServer(a.https()); - serviceCatalogMockServer.init(); - serviceCatalogClient = serviceCatalogMockServer.createServiceCatalog(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, serviceCatalogClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, serviceCatalogMockServer)); - } -} diff --git a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogServer.java b/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogServer.java deleted file mode 100644 index 99c89ab1c53..00000000000 --- a/extensions/service-catalog/mock/src/main/java/io/fabric8/servicecatalog/server/mock/ServiceCatalogServer.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 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.servicecatalog.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.servicecatalog.client.ServiceCatalogClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class ServiceCatalogServer extends ExternalResource { - - protected ServiceCatalogMockServer mock; - private ServiceCatalogClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public ServiceCatalogServer() { - this(true, false); - } - - public ServiceCatalogServer(boolean https) { - this(https, false); - } - - public ServiceCatalogServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new ServiceCatalogMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new ServiceCatalogMockServer(https); - mock.init(); - client = mock.createServiceCatalog(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public ServiceCatalogClient getServiceCatalogClient() { - return client; - } - - - public MockServerExpectation expect() { - return mock.expect(); - } - - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } -} diff --git a/extensions/service-catalog/pom.xml b/extensions/service-catalog/pom.xml index f2e0b067210..3920baa5036 100644 --- a/extensions/service-catalog/pom.xml +++ b/extensions/service-catalog/pom.xml @@ -35,7 +35,6 @@ model client - mock examples tests diff --git a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceBrokerTest.java b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceBrokerTest.java index 40b2aa2f0f8..ae07335d38d 100644 --- a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceBrokerTest.java +++ b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceBrokerTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class ClusterServiceBrokerTest { @@ -89,7 +88,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.clusterServiceBrokers().withName("broker1").delete().size() == 1); + assertEquals(1, client.clusterServiceBrokers().withName("broker1").delete().size()); assertNull(client.clusterServiceBrokers().withName("broker1").get()); } } diff --git a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceClassTest.java b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceClassTest.java index 9b80c11ebb5..d6a8aee7444 100644 --- a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceClassTest.java +++ b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServiceClassTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class ClusterServiceClassTest { @@ -89,7 +88,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.clusterServiceClasses().withName("class1").delete().size() == 1); + assertEquals(1, client.clusterServiceClasses().withName("class1").delete().size()); assertNull(client.clusterServiceClasses().withName("class1").get()); } } diff --git a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServicePlanTest.java b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServicePlanTest.java index c115b719897..b0dcbb3f311 100644 --- a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServicePlanTest.java +++ b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ClusterServicePlanTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class ClusterServicePlanTest { @@ -89,7 +88,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.clusterServicePlans().withName("plan1").delete().size() == 1); + assertEquals(1, client.clusterServicePlans().withName("plan1").delete().size()); assertNull(client.clusterServicePlans().withName("plan1").get()); } } diff --git a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceBindingTest.java b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceBindingTest.java index d2baeffa803..6bef3751f1d 100644 --- a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceBindingTest.java +++ b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceBindingTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class ServiceBindingTest { @@ -109,7 +108,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.serviceBindings().inNamespace("testns").withName("binding1").delete().size() == 1); + assertEquals(1, client.serviceBindings().inNamespace("testns").withName("binding1").delete().size()); assertNull(client.serviceBindings().inNamespace("testns").withName("binding1").get()); } } diff --git a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceInstanceTest.java b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceInstanceTest.java index bc8ad0d1fd0..af878f48d0a 100644 --- a/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceInstanceTest.java +++ b/extensions/service-catalog/tests/src/test/java/io/fabric8/servicecatalog/test/crud/ServiceInstanceTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class ServiceInstanceTest { @@ -109,7 +108,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.serviceInstances().inNamespace("testns").withName("instance1").delete().size() == 1); + assertEquals(1, client.serviceInstances().inNamespace("testns").withName("instance1").delete().size()); assertNull(client.serviceInstances().inNamespace("testns").withName("instance1").get()); } } diff --git a/extensions/tekton/mock/pom.xml b/extensions/tekton/mock/pom.xml deleted file mode 100644 index 58209899822..00000000000 --- a/extensions/tekton/mock/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - tekton-extension-pom - 6.2-SNAPSHOT - - - - tekton-mock - Fabric8 :: Tekton :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - tekton-client - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/EnableTektonMockClient.java b/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/EnableTektonMockClient.java deleted file mode 100644 index c49a25f74d7..00000000000 --- a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/EnableTektonMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.tekton.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling TektonMockServerExtension JUnit5 extension. - * You may set here two parameters of `TektonServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(TektonMockServerExtension.class) -public @interface EnableTektonMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServer.java b/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServer.java deleted file mode 100644 index cb6902fddba..00000000000 --- a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.tekton.mock; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.tekton.client.DefaultTektonClient; -import io.fabric8.tekton.client.NamespacedTektonClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class TektonMockServer extends KubernetesMockServer { - - public TektonMockServer() { - super(); - } - - public TektonMockServer(boolean useHttps) { - super(useHttps); - } - - public TektonMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/tekton.k8s.io" }; - } - - public NamespacedTektonClient createTekton() { - Config config = getMockConfiguration(); - return new DefaultTektonClient(config); - } -} diff --git a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServerExtension.java b/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServerExtension.java deleted file mode 100644 index 2ecdc303d9a..00000000000 --- a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.tekton.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.tekton.client.NamespacedTektonClient; -import io.fabric8.tekton.client.TektonClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(TektonMockServerExtension.class) or through - * @EnableTektonMockClient annotation - */ -public class TektonMockServerExtension extends KubernetesMockServerExtension { - private TektonMockServer tektonMockServer; - private NamespacedTektonClient tektonClient; - - @Override - protected void destroy() { - tektonMockServer.destroy(); - tektonClient.close(); - } - - @Override - protected Class getClientType() { - return TektonClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return TektonMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableTektonMockClient a = testClass.getAnnotation(EnableTektonMockClient.class); - final Map> responses = new HashMap<>(); - tektonMockServer = a.crud() - ? new TektonMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new TektonMockServer(a.https()); - tektonMockServer.init(); - tektonClient = tektonMockServer.createTekton(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, tektonClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, tektonMockServer)); - } -} - - diff --git a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonServer.java b/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonServer.java deleted file mode 100644 index 6c3db2ffde8..00000000000 --- a/extensions/tekton/mock/src/main/java/io/fabric8/tekton/mock/TektonServer.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 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.tekton.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.tekton.client.TektonClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class TektonServer extends ExternalResource { - - protected TektonMockServer mock; - private TektonClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public TektonServer() { - this(true, false); - } - - public TektonServer(boolean https) { - this(https, false); - } - - public TektonServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new TektonMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new TektonMockServer(https); - mock.init(); - client = mock.createTekton(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - - public TektonClient getTektonClient() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } - - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } -} diff --git a/extensions/tekton/pom.xml b/extensions/tekton/pom.xml index 17ceffb5b66..9739ef5eeb5 100755 --- a/extensions/tekton/pom.xml +++ b/extensions/tekton/pom.xml @@ -38,7 +38,6 @@ model-triggers-v1alpha1 model-triggers-v1beta1 client - mock examples tests diff --git a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/ArrayOrStringTest.java b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/ArrayOrStringTest.java index 03608236409..f2711db9c9d 100644 --- a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/ArrayOrStringTest.java +++ b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/ArrayOrStringTest.java @@ -26,7 +26,7 @@ class ArrayOrStringTest { @Test - public void testArrayOrStringJson() throws IOException { + void testArrayOrStringJson() throws IOException { ArrayOrString is = new ArrayOrString("string-value"); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(is); diff --git a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/TaskTest.java b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/TaskTest.java index 2b160447fa3..072f70a064b 100644 --- a/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/TaskTest.java +++ b/extensions/tekton/tests/src/test/java/io/fabric8/tekton/pipeline/v1beta1/TaskTest.java @@ -27,7 +27,7 @@ class TaskTest { @Test - public void testTaskFromJSON() throws IOException { + void testTaskFromJSON() throws IOException { InputStream is = TaskTest.class.getResourceAsStream("/task.json"); ObjectMapper mapper = new ObjectMapper(); Task task = mapper.readValue(is, Task.class); diff --git a/extensions/verticalpodautoscaler/mock/pom.xml b/extensions/verticalpodautoscaler/mock/pom.xml deleted file mode 100644 index 7ae4e029829..00000000000 --- a/extensions/verticalpodautoscaler/mock/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - verticalpodautoscaler-extension-pom - 6.2-SNAPSHOT - - - verticalpodautoscaler-server-mock - Fabric8 :: Vertical Pod Autoscaler :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - verticalpodautoscaler-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/EnableVerticalPodAutoscalerMockClient.java b/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/EnableVerticalPodAutoscalerMockClient.java deleted file mode 100644 index fc24224ce3c..00000000000 --- a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/EnableVerticalPodAutoscalerMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.verticalpodautoscaler.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling VerticalPodAutoscalerMockServerExtension JUnit5 extension. - * You may set here two parameters of `VerticalPodAutoscalerKServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(VerticalPodAutoscalerMockServerExtension.class) -public @interface EnableVerticalPodAutoscalerMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServer.java b/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServer.java deleted file mode 100644 index 39b5fc07e07..00000000000 --- a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.verticalpodautoscaler.server.mock; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.verticalpodautoscaler.client.DefaultVerticalPodAutoscalerClient; -import io.fabric8.verticalpodautoscaler.client.NamespacedVerticalPodAutoscalerClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class VerticalPodAutoscalerMockServer extends KubernetesMockServer { - - public VerticalPodAutoscalerMockServer() { - super(); - } - - public VerticalPodAutoscalerMockServer(boolean useHttps) { - super(useHttps); - } - - public VerticalPodAutoscalerMockServer(Context context, MockWebServer server, - Map> responses, Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/cert-manager.io" }; - } - - public NamespacedVerticalPodAutoscalerClient createVerticalPodAutoscaler() { - Config config = getMockConfiguration(); - return new DefaultVerticalPodAutoscalerClient(config); - } -} diff --git a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServerExtension.java b/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServerExtension.java deleted file mode 100644 index cecf3e84d1e..00000000000 --- a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.verticalpodautoscaler.server.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.verticalpodautoscaler.client.VerticalPodAutoscalerClient; -import io.fabric8.verticalpodautoscaler.client.NamespacedVerticalPodAutoscalerClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(VerticalPodAutoscalerMockServerExtension.class) or through - * @EnableVerticalPodAutoscalerMockClient annotation - */ -public class VerticalPodAutoscalerMockServerExtension extends KubernetesMockServerExtension { - private VerticalPodAutoscalerMockServer verticalPodAutoscalerMockServer; - private NamespacedVerticalPodAutoscalerClient verticalPodAutoscalerClient; - - @Override - protected void destroy() { - verticalPodAutoscalerMockServer.destroy(); - verticalPodAutoscalerClient.close(); - } - - @Override - protected Class getClientType() { - return VerticalPodAutoscalerClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return VerticalPodAutoscalerMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableVerticalPodAutoscalerMockClient a = testClass.getAnnotation(EnableVerticalPodAutoscalerMockClient.class); - final Map> responses = new HashMap<>(); - verticalPodAutoscalerMockServer = a.crud() - ? new VerticalPodAutoscalerMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new VerticalPodAutoscalerMockServer(a.https()); - verticalPodAutoscalerMockServer.init(); - verticalPodAutoscalerClient = verticalPodAutoscalerMockServer.createVerticalPodAutoscaler(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, verticalPodAutoscalerClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, verticalPodAutoscalerMockServer)); - } -} - diff --git a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerServer.java b/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerServer.java deleted file mode 100644 index 267be9f2270..00000000000 --- a/extensions/verticalpodautoscaler/mock/src/main/java/io/fabric8/verticalpodautoscaler/server/mock/VerticalPodAutoscalerServer.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.verticalpodautoscaler.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.verticalpodautoscaler.client.VerticalPodAutoscalerClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class VerticalPodAutoscalerServer extends ExternalResource { - - protected VerticalPodAutoscalerMockServer mock; - private VerticalPodAutoscalerClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public VerticalPodAutoscalerServer() { - this(true, false); - } - - public VerticalPodAutoscalerServer(boolean https) { - this(https, false); - } - - public VerticalPodAutoscalerServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new VerticalPodAutoscalerMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new VerticalPodAutoscalerMockServer(https); - mock.init(); - client = mock.createVerticalPodAutoscaler(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - - public VerticalPodAutoscalerClient getVerticalPodAutoscalerClient() { - return client; - } - - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/verticalpodautoscaler/pom.xml b/extensions/verticalpodautoscaler/pom.xml index bdc4cbb53cf..72159808ea6 100644 --- a/extensions/verticalpodautoscaler/pom.xml +++ b/extensions/verticalpodautoscaler/pom.xml @@ -35,7 +35,6 @@ model-v1 client - mock examples tests diff --git a/extensions/volcano/mock/pom.xml b/extensions/volcano/mock/pom.xml deleted file mode 100644 index c00f90f26db..00000000000 --- a/extensions/volcano/mock/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - volcano-extension-pom - 6.2-SNAPSHOT - - - volcano-server-mock - Fabric8 :: Volcano :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - io.fabric8 - volcano-client - ${project.version} - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/EnableVolcanoMockClient.java b/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/EnableVolcanoMockClient.java deleted file mode 100644 index a901048fb08..00000000000 --- a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/EnableVolcanoMockClient.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.volcano.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling VolcanoMockServerExtension JUnit5 extension. - * You may set here two parameters of `VolcanoServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(VolcanoMockServerExtension.class) -public @interface EnableVolcanoMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServer.java b/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServer.java deleted file mode 100644 index bba4645c40b..00000000000 --- a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServer.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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.volcano.server.mock; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.volcano.client.DefaultVolcanoClient; -import io.fabric8.volcano.client.NamespacedVolcanoClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class VolcanoMockServer extends KubernetesMockServer { - - public VolcanoMockServer() { - super(); - } - - public VolcanoMockServer(boolean useHttps) { - super(useHttps); - } - - public VolcanoMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/scheduling.k8s.io" }; - } - - public NamespacedVolcanoClient createVolcano() { - Config config = getMockConfiguration(); - return new DefaultVolcanoClient(config); - } -} diff --git a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServerExtension.java b/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServerExtension.java deleted file mode 100644 index 179e0ba9b06..00000000000 --- a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoMockServerExtension.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.volcano.server.mock; - - -import io.fabric8.volcano.client.VolcanoClient; -import io.fabric8.volcano.client.NamespacedVolcanoClient; -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(VolcanoMockServerExtension.class) or through - * @EnableVolcanoMockClient annotation - */ -public class VolcanoMockServerExtension extends KubernetesMockServerExtension { - private VolcanoMockServer volcanoMockServer; - private NamespacedVolcanoClient volcanoClient; - final Map> responses = new HashMap<>(); - - @Override - protected void destroy() { - volcanoMockServer.destroy(); - volcanoClient.close(); - } - - @Override - protected Class getClientType() { - return VolcanoClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return VolcanoMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableVolcanoMockClient a = testClass.getAnnotation(EnableVolcanoMockClient.class); - volcanoMockServer = a.crud() - ? new VolcanoMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new VolcanoMockServer(a.https()); - volcanoMockServer.init(); - volcanoClient = volcanoMockServer.createVolcano(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, volcanoClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, volcanoMockServer)); - } -} diff --git a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoServer.java b/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoServer.java deleted file mode 100644 index ccc2810a0c2..00000000000 --- a/extensions/volcano/mock/src/main/java/io/fabric8/volcano/server/mock/VolcanoServer.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 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.volcano.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.volcano.client.VolcanoClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class VolcanoServer extends ExternalResource { - - protected VolcanoMockServer mock; - private VolcanoClient client; - - private final boolean https; - // In this mode the mock web server will store, read, update and delete - // kubernetes resources using an in memory map and will appear as a real api - // server. - private final boolean crudMode; - - public VolcanoServer() { - this(true, false); - } - - public VolcanoServer(boolean https) { - this(https, false); - } - - public VolcanoServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new VolcanoMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new VolcanoMockServer(https); - mock.init(); - client = mock.createVolcano(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public VolcanoClient getVolcanoClient() { - return client; - } - - - public MockServerExpectation expect() { - return mock.expect(); - } - - @Deprecated - public void expectAndReturnAsJson(String path, int code, T body) { - expect().withPath(path).andReturn(code, body).always(); - } - - @Deprecated - public void expectAndReturnAsString(String path, int code, String body) { - expect().withPath(path).andReturn(code, body).always(); - } -} diff --git a/extensions/volcano/pom.xml b/extensions/volcano/pom.xml index e03f47722d6..62108e148fb 100644 --- a/extensions/volcano/pom.xml +++ b/extensions/volcano/pom.xml @@ -36,7 +36,6 @@ model-v1beta1 client examples - mock tests diff --git a/extensions/volumesnapshot/mock/pom.xml b/extensions/volumesnapshot/mock/pom.xml deleted file mode 100644 index 700339fde9f..00000000000 --- a/extensions/volumesnapshot/mock/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - 4.0.0 - - io.fabric8 - volumesnapshot - 6.2-SNAPSHOT - - - volumesnapshot-server-mock - Fabric8 :: Volume Snapshot :: Server Mock - - - - io.fabric8 - kubernetes-server-mock - - - - io.fabric8 - volumesnapshot-client - ${project.version} - - - - org.junit.jupiter - junit-jupiter-api - provided - - - - diff --git a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/EnableVolumeSnapshotMockClient.java b/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/EnableVolumeSnapshotMockClient.java deleted file mode 100644 index 4ae617b5da4..00000000000 --- a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/EnableVolumeSnapshotMockClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.volumesnapshot.server.mock; - -import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; -import org.junit.jupiter.api.extension.ExtendWith; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Annotation that is used for enabling VolumeSnapshotMockServerExtension JUnit5 extension. - * You may set here two parameters of `VolumeSnapshotServer`: crudMode and https - * - * @deprecated use {@link EnableKubernetesMockClient} instead - */ -@Deprecated -@Target({ TYPE, METHOD, ANNOTATION_TYPE }) -@Retention(RUNTIME) -@ExtendWith(VolumeSnapshotMockServerExtension.class) -public @interface EnableVolumeSnapshotMockClient { - - boolean https() default true; - - boolean crud() default false; -} diff --git a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServer.java b/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServer.java deleted file mode 100644 index 8ddd385affa..00000000000 --- a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServer.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.volumesnapshot.server.mock; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.volumesnapshot.client.DefaultVolumeSnapshotClient; -import io.fabric8.volumesnapshot.client.NamespacedVolumeSnapshotClient; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockWebServer; - -import java.util.Map; -import java.util.Queue; - -/** - * @deprecated use {@link KubernetesMockServer} instead - */ -@Deprecated -public class VolumeSnapshotMockServer extends KubernetesMockServer { - public VolumeSnapshotMockServer() { - super(); - } - - public VolumeSnapshotMockServer(boolean useHttps) { - super(useHttps); - } - - public VolumeSnapshotMockServer(Context context, MockWebServer server, Map> responses, - Dispatcher dispatcher, boolean useHttps) { - super(context, server, responses, dispatcher, useHttps); - } - - @Override - public String[] getRootPaths() { - return new String[] { "/api", "/apis/snapshot.storage.k8s.io" }; - } - - public NamespacedVolumeSnapshotClient createVolumeSnapshot() { - Config config = getMockConfiguration(); - return new DefaultVolumeSnapshotClient(config); - } -} diff --git a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServerExtension.java b/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServerExtension.java deleted file mode 100644 index 12ea4e8c108..00000000000 --- a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotMockServerExtension.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.volumesnapshot.server.mock; - - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.kubernetes.client.server.mock.KubernetesMockServerExtension; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.volumesnapshot.client.NamespacedVolumeSnapshotClient; -import io.fabric8.volumesnapshot.client.VolumeSnapshotClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.extension.ExtensionContext; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -/** - * The class that implements JUnit5 extension mechanism. You can use it directly in your JUnit test - * by annotating it with @ExtendWith(VolumeSnapshotServerExtension.class) or through - * @EnableVolumeSnapshotMockClient annotation - */ -public class VolumeSnapshotMockServerExtension extends KubernetesMockServerExtension { - private VolumeSnapshotMockServer volumeSnapshotMockServer; - private NamespacedVolumeSnapshotClient volumeSnapshotClient; - - @Override - protected void destroy() { - volumeSnapshotMockServer.destroy(); - volumeSnapshotClient.close(); - } - - @Override - protected Class getClientType() { - return VolumeSnapshotClient.class; - } - - @Override - protected Class getKubernetesMockServerType() { - return VolumeSnapshotMockServer.class; - } - - @Override - protected void initializeKubernetesClientAndMockServer(Class testClass) { - EnableVolumeSnapshotMockClient a = testClass.getAnnotation(EnableVolumeSnapshotMockClient.class); - final Map> responses = new HashMap<>(); - volumeSnapshotMockServer= a.crud() - ? new VolumeSnapshotMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), a.https()) - : new VolumeSnapshotMockServer(a.https()); - volumeSnapshotMockServer.init(); - volumeSnapshotClient = volumeSnapshotMockServer.createVolumeSnapshot(); - } - - @Override - protected void setFieldIfKubernetesClientOrMockServer(ExtensionContext context, boolean isStatic, Field field) throws IllegalAccessException { - setFieldIfEqualsToProvidedType(context, isStatic, field, getClientType(), (i, f) -> f.set(i, volumeSnapshotClient)); - setFieldIfEqualsToProvidedType(context, isStatic, field, getKubernetesMockServerType(), (i, f) -> f.set(i, volumeSnapshotMockServer)); - } -} - - diff --git a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotServer.java b/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotServer.java deleted file mode 100644 index 31c4fa36ab3..00000000000 --- a/extensions/volumesnapshot/mock/src/main/java/io/fabric8/volumesnapshot/server/mock/VolumeSnapshotServer.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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.volumesnapshot.server.mock; - -import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher; -import io.fabric8.mockwebserver.Context; -import io.fabric8.mockwebserver.ServerRequest; -import io.fabric8.mockwebserver.ServerResponse; -import io.fabric8.mockwebserver.dsl.MockServerExpectation; -import io.fabric8.volumesnapshot.client.VolumeSnapshotClient; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.rules.ExternalResource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; - -public class VolumeSnapshotServer extends ExternalResource { - - protected VolumeSnapshotMockServer mock; - private VolumeSnapshotClient client; - - private final boolean https; - private final boolean crudMode; - - public VolumeSnapshotServer() { - this(true, false); - } - - public VolumeSnapshotServer(boolean https) { - this(https, false); - } - - public VolumeSnapshotServer(boolean https, boolean crudMode) { - this.https = https; - this.crudMode = crudMode; - } - - @Override - public void before() { - final Map> responses = new HashMap<>(); - mock = crudMode - ? new VolumeSnapshotMockServer(new Context(), new MockWebServer(), responses, new KubernetesMixedDispatcher(responses), true) - : new VolumeSnapshotMockServer(https); - mock.init(); - client = mock.createVolumeSnapshot(); - } - - @Override - public void after() { - mock.destroy(); - client.close(); - } - - public VolumeSnapshotClient get() { - return client; - } - - public MockServerExpectation expect() { - return mock.expect(); - } -} diff --git a/extensions/volumesnapshot/pom.xml b/extensions/volumesnapshot/pom.xml index 07b94078707..b5e6a599e96 100644 --- a/extensions/volumesnapshot/pom.xml +++ b/extensions/volumesnapshot/pom.xml @@ -36,7 +36,6 @@ model client - mock examples tests diff --git a/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotClassTest.java b/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotClassTest.java index 6dd709edaa0..3ed3320b13a 100644 --- a/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotClassTest.java +++ b/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotClassTest.java @@ -26,7 +26,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.assertTrue; @EnableKubernetesMockClient(crud = true) class VolumeSnapshotClassTest { @@ -86,7 +85,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(scr1.delete().size() == 1); + assertEquals(1, scr1.delete().size()); assertNull(scr1.get()); } } diff --git a/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotTest.java b/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotTest.java index 548c98cd4e6..bf41c589ff7 100644 --- a/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotTest.java +++ b/extensions/volumesnapshot/tests/src/test/java/io/fabric8/volumesnapshot/test/crud/VolumeSnapshotTest.java @@ -25,7 +25,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.assertTrue; @EnableKubernetesMockClient(crud = true) class VolumeSnapshotTest { @@ -96,7 +95,7 @@ void testCrud() { assertEquals("true", u1.getMetadata().getLabels().get("updated")); //Delete - assertTrue(client.volumeSnapshots().withName("my-snapshot1").delete().size() == 1); + assertEquals(1, client.volumeSnapshots().withName("my-snapshot1").delete().size()); assertNull(client.volumeSnapshots().withName("my-snapshot1").get()); } }