-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#1275): Add environment setting to enable/disable test actors
- Loading branch information
1 parent
95e7225
commit 07f821c
Showing
7 changed files
with
585 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...s/citrus-kubernetes/src/test/java/org/citrusframework/kubernetes/KubernetesActorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* 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 org.citrusframework.kubernetes; | ||
|
||
import java.util.HashMap; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesCrudDispatcher; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; | ||
import io.fabric8.mockwebserver.Context; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import org.mockito.Mockito; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
public class KubernetesActorTest { | ||
|
||
private final KubernetesMockServer k8sServer = new KubernetesMockServer(new Context(), new MockWebServer(), | ||
new HashMap<>(), new KubernetesCrudDispatcher(), false); | ||
|
||
KubernetesClient k8sClient; | ||
|
||
@BeforeClass | ||
public void setupMocks() { | ||
k8sServer.init(); | ||
k8sClient = k8sServer.createClient(); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void stop() { | ||
k8sServer.destroy(); | ||
} | ||
|
||
@Test | ||
public void shouldVerifyConnectedState() { | ||
try { | ||
Assert.assertFalse(new KubernetesActor(k8sClient).isDisabled()); | ||
} finally { | ||
KubernetesActor.resetConnectionState(); | ||
} | ||
|
||
try { | ||
KubernetesClient k8sClientMock = Mockito.mock(KubernetesClient.class); | ||
Assert.assertTrue(new KubernetesActor(k8sClientMock).isDisabled()); | ||
} finally { | ||
KubernetesActor.resetConnectionState(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldOverruleConnectedState() { | ||
boolean initial = KubernetesSettings.isEnabled(); | ||
try { | ||
System.setProperty("citrus.kubernetes.enabled", "false"); | ||
Assert.assertTrue(new KubernetesActor(k8sClient).isDisabled()); | ||
} finally { | ||
System.setProperty("citrus.kubernetes.enabled", Boolean.toString(initial)); | ||
} | ||
|
||
initial = Boolean.parseBoolean(System.getProperty("citrus.test.actor.k8s.enabled", "true")); | ||
try { | ||
System.setProperty("citrus.test.actor.k8s.enabled", "false"); | ||
Assert.assertTrue(new KubernetesActor(k8sClient).isDisabled()); | ||
} finally { | ||
System.setProperty("citrus.test.actor.k8s.enabled", Boolean.toString(initial)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...tcontainers/src/test/java/org/citrusframework/testcontainers/TestcontainersActorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* 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 org.citrusframework.testcontainers; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.command.PingCmd; | ||
import org.citrusframework.kubernetes.KubernetesSettings; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class TestcontainersActorTest { | ||
|
||
@Mock | ||
DockerClient dockerClient; | ||
|
||
@Mock | ||
PingCmd connected; | ||
|
||
@Mock | ||
PingCmd disconnected; | ||
|
||
@BeforeClass | ||
public void setupMocks() { | ||
MockitoAnnotations.openMocks(this); | ||
|
||
doNothing().when(connected).exec(); | ||
doThrow(IllegalStateException.class).when(disconnected).exec(); | ||
} | ||
|
||
@Test | ||
public void shouldVerifyConnectedState() { | ||
try { | ||
when(dockerClient.pingCmd()).thenReturn(connected); | ||
Assert.assertFalse(new TestcontainersActor(dockerClient).isDisabled()); | ||
} finally { | ||
TestcontainersActor.resetConnectionState(); | ||
reset(dockerClient); | ||
} | ||
|
||
try { | ||
when(dockerClient.pingCmd()).thenReturn(disconnected); | ||
Assert.assertTrue(new TestcontainersActor(dockerClient).isDisabled()); | ||
} finally { | ||
TestcontainersActor.resetConnectionState(); | ||
reset(dockerClient); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldOverruleConnectedState() { | ||
boolean initial = KubernetesSettings.isEnabled(); | ||
try { | ||
System.setProperty("citrus.testcontainers.enabled", "false"); | ||
when(dockerClient.pingCmd()).thenReturn(connected); | ||
Assert.assertTrue(new TestcontainersActor(dockerClient).isDisabled()); | ||
} finally { | ||
System.setProperty("citrus.testcontainers.enabled", Boolean.toString(initial)); | ||
reset(dockerClient); | ||
} | ||
|
||
initial = Boolean.parseBoolean(System.getProperty("citrus.test.actor.testcontainers.enabled", "true")); | ||
try { | ||
System.setProperty("citrus.test.actor.testcontainers.enabled", "false"); | ||
when(dockerClient.pingCmd()).thenReturn(connected); | ||
Assert.assertTrue(new TestcontainersActor(dockerClient).isDisabled()); | ||
} finally { | ||
System.setProperty("citrus.test.actor.testcontainers.enabled", Boolean.toString(initial)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.