Watcher revert wiremock tests (#1064)
* very dirty still * revert tests * revert two properties
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -149,13 +149,13 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-dependencies</artifactId>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>-->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
<artifactId>spring-cloud-kubernetes-configuration-watcher</artifactId>
|
||||
|
||||
<properties>
|
||||
<jib.version>1.8.0</jib.version>
|
||||
<base.image>openjdk:8u222-slim</base.image>
|
||||
<docker.registry.organization>springcloud</docker.registry.organization>
|
||||
<plexus-archiver.version>4.1.0</plexus-archiver.version>
|
||||
</properties>
|
||||
@@ -44,12 +42,19 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<!-- In favor of mockito-inline -->
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
@@ -65,6 +70,11 @@
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -131,39 +141,6 @@
|
||||
<env.IMAGE>springcloud/${project.artifactId}:${project.version}</env.IMAGE>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jib</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.google.cloud.tools</groupId>
|
||||
<artifactId>jib-maven-plugin</artifactId>
|
||||
<version>${jib.version}</version>
|
||||
<configuration>
|
||||
<from>
|
||||
<image>${base.image}</image>
|
||||
</from>
|
||||
<to>
|
||||
<image>spring-cloud/${project.artifactId}</image>
|
||||
</to>
|
||||
<container>
|
||||
<user>nobody:nogroup</user>
|
||||
<environment>
|
||||
</environment>
|
||||
</container>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>dockerBuild</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
||||
|
||||
@@ -21,20 +21,28 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import io.kubernetes.client.openapi.models.V1ConfigMap;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointAddress;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointPort;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.client.discovery.reactive.KubernetesInformerReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
@@ -46,6 +54,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider.NAMESPACE_PROPERTY;
|
||||
|
||||
@@ -53,20 +62,17 @@ import static org.springframework.cloud.kubernetes.commons.KubernetesNamespacePr
|
||||
* @author Ryan Baxter
|
||||
* @author Kris Iyer
|
||||
*/
|
||||
// FIXME: 4.0.0 contract wiremock
|
||||
@Ignore("waiting for compatible contract wiremock")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
|
||||
// @Rule
|
||||
// public WireMockRule wireMockRule = new WireMockRule(0);
|
||||
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
|
||||
|
||||
private static final WireMockServer WIRE_MOCK_SERVER = new WireMockServer(
|
||||
WireMockConfiguration.options().dynamicPort());
|
||||
|
||||
@Mock
|
||||
private CoreV1Api coreV1Api;
|
||||
|
||||
@Mock
|
||||
private ConfigurationUpdateStrategy updateStrategy;
|
||||
|
||||
@Mock
|
||||
private KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator;
|
||||
|
||||
@@ -80,64 +86,78 @@ public class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
|
||||
private ConfigurationWatcherConfigurationProperties configurationWatcherConfigurationProperties;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
// fooEndpointPort.setPort(wireMockRule.port());
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
|
||||
instances.add(fooServiceInstance);
|
||||
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
WIRE_MOCK_SERVER.start();
|
||||
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
|
||||
clientUtilsMock.when(KubernetesClientUtils::createApiClientForInformerClient)
|
||||
.thenReturn(new ClientBuilder().setBasePath(WIRE_MOCK_SERVER.baseUrl()).build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void teardown() {
|
||||
clientUtilsMock.close();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
configurationWatcherConfigurationProperties = new ConfigurationWatcherConfigurationProperties();
|
||||
WebClient webClient = WebClient.builder().build();
|
||||
|
||||
ConfigurationUpdateStrategy strategy = new ConfigurationUpdateStrategy("refresh", () -> {
|
||||
|
||||
});
|
||||
|
||||
changeDetector = new HttpBasedConfigMapWatchChangeDetector(coreV1Api, mockEnvironment, configReloadProperties,
|
||||
updateStrategy, configMapPropertySourceLocator, new KubernetesNamespaceProvider(mockEnvironment),
|
||||
strategy, configMapPropertySourceLocator, new KubernetesNamespaceProvider(mockEnvironment),
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor, webClient,
|
||||
reactiveDiscoveryClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerConfigMapRefresh() {
|
||||
void triggerConfigMapRefresh() {
|
||||
stubReactiveCall();
|
||||
V1ConfigMap configMap = new V1ConfigMap();
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
configMap.setMetadata(objectMeta);
|
||||
// WireMock.configureFor("localhost", wireMockRule.port());
|
||||
// stubFor(post(WireMock.urlEqualTo("/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/actuator/refresh")));
|
||||
WireMock.configureFor("localhost", WIRE_MOCK_SERVER.port());
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerConfigMapRefreshWithPropertiesBasedActuatorPath() throws InterruptedException {
|
||||
void triggerConfigMapRefreshWithPropertiesBasedActuatorPath() {
|
||||
stubReactiveCall();
|
||||
configurationWatcherConfigurationProperties.setActuatorPath("/my/custom/actuator");
|
||||
V1ConfigMap configMap = new V1ConfigMap();
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
configMap.setMetadata(objectMeta);
|
||||
// WireMock.configureFor("localhost", wireMockRule.port());
|
||||
// stubFor(post(WireMock.urlEqualTo("/my/custom/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/my/custom/actuator/refresh")));
|
||||
WireMock.configureFor("localhost", WIRE_MOCK_SERVER.port());
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/my/custom/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/my/custom/actuator/refresh")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerConfigMapRefreshWithAnnotationActuatorPath() {
|
||||
void triggerConfigMapRefreshWithAnnotationActuatorPath() {
|
||||
int port = WIRE_MOCK_SERVER.port();
|
||||
WireMock.configureFor("localhost", port);
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
// metadata.put(ANNOTATION_KEY, "http://:" + wireMockRule.port() +
|
||||
// "/my/custom/actuator");
|
||||
metadata.put(HttpBasedConfigMapWatchChangeDetector.ANNOTATION_KEY, "http://:" + port + "/my/custom/actuator");
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
// fooEndpointPort.setPort(wireMockRule.port());
|
||||
fooEndpointPort.setPort(port);
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false);
|
||||
@@ -147,9 +167,26 @@ public class HttpBasedConfigMapWatchChangeDetectorTests {
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
configMap.setMetadata(objectMeta);
|
||||
// stubFor(post(WireMock.urlEqualTo("/my/custom/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/my/custom/actuator/refresh")));
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/my/custom/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(configMap)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/my/custom/actuator/refresh")));
|
||||
}
|
||||
|
||||
private void stubReactiveCall() {
|
||||
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
fooEndpointPort.setPort(WIRE_MOCK_SERVER.port());
|
||||
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
|
||||
instances.add(fooServiceInstance);
|
||||
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,20 +21,28 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointAddress;
|
||||
import io.kubernetes.client.openapi.models.V1EndpointPort;
|
||||
import io.kubernetes.client.openapi.models.V1ObjectMeta;
|
||||
import io.kubernetes.client.openapi.models.V1Secret;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import io.kubernetes.client.util.ClientBuilder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientUtils;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySourceLocator;
|
||||
import org.springframework.cloud.kubernetes.client.discovery.reactive.KubernetesInformerReactiveDiscoveryClient;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
@@ -46,6 +54,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider.NAMESPACE_PROPERTY;
|
||||
|
||||
@@ -53,13 +62,13 @@ import static org.springframework.cloud.kubernetes.commons.KubernetesNamespacePr
|
||||
* @author Ryan Baxter
|
||||
* @author Kris Iyer
|
||||
*/
|
||||
// FIXME: 4.0.0 contract wiremock
|
||||
@Ignore("waiting for compatible contract wiremock")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
|
||||
// @Rule
|
||||
// public WireMockRule wireMockRule = new WireMockRule(0);
|
||||
private static MockedStatic<KubernetesClientUtils> clientUtilsMock;
|
||||
|
||||
private static final WireMockServer WIRE_MOCK_SERVER = new WireMockServer(
|
||||
WireMockConfiguration.options().dynamicPort());
|
||||
|
||||
@Mock
|
||||
private CoreV1Api coreV1Api;
|
||||
@@ -80,18 +89,8 @@ public class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
|
||||
private ConfigurationWatcherConfigurationProperties configurationWatcherConfigurationProperties;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
// fooEndpointPort.setPort(wireMockRule.port());
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
|
||||
instances.add(fooServiceInstance);
|
||||
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty(NAMESPACE_PROPERTY, "default");
|
||||
ConfigReloadProperties configReloadProperties = new ConfigReloadProperties();
|
||||
@@ -103,41 +102,59 @@ public class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
reactiveDiscoveryClient);
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
WIRE_MOCK_SERVER.start();
|
||||
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
|
||||
clientUtilsMock.when(KubernetesClientUtils::createApiClientForInformerClient)
|
||||
.thenReturn(new ClientBuilder().setBasePath(WIRE_MOCK_SERVER.baseUrl()).build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void teardown() {
|
||||
clientUtilsMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerSecretRefresh() throws InterruptedException {
|
||||
void triggerSecretRefresh() {
|
||||
stubReactiveCall();
|
||||
V1Secret secret = new V1Secret();
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
secret.setMetadata(objectMeta);
|
||||
// WireMock.configureFor("localhost", wireMockRule.port());
|
||||
// stubFor(post(WireMock.urlEqualTo("/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/actuator/refresh")));
|
||||
WireMock.configureFor("localhost", WIRE_MOCK_SERVER.port());
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerSecretRefreshWithPropertiesBasedActuatorPath() throws InterruptedException {
|
||||
void triggerSecretRefreshWithPropertiesBasedActuatorPath() {
|
||||
stubReactiveCall();
|
||||
configurationWatcherConfigurationProperties.setActuatorPath("/my/custom/actuator");
|
||||
V1Secret secret = new V1Secret();
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
secret.setMetadata(objectMeta);
|
||||
// WireMock.configureFor("localhost", wireMockRule.port());
|
||||
// stubFor(post(WireMock.urlEqualTo("/my/custom/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/my/custom/actuator/refresh")));
|
||||
WireMock.configureFor("localhost", WIRE_MOCK_SERVER.port());
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/my/custom/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/my/custom/actuator/refresh")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerSecretRefreshWithAnnotationActuatorPath() {
|
||||
void triggerSecretRefreshWithAnnotationActuatorPath() {
|
||||
WireMock.configureFor("localhost", WIRE_MOCK_SERVER.port());
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
// metadata.put(ANNOTATION_KEY, "http://:" + wireMockRule.port() +
|
||||
// "/my/custom/actuator");
|
||||
metadata.put(HttpBasedConfigMapWatchChangeDetector.ANNOTATION_KEY,
|
||||
"http://:" + WIRE_MOCK_SERVER.port() + "/my/custom/actuator");
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
// fooEndpointPort.setPort(wireMockRule.port());
|
||||
fooEndpointPort.setPort(WIRE_MOCK_SERVER.port());
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), metadata, false);
|
||||
@@ -147,9 +164,23 @@ public class HttpBasedSecretsWatchChangeDetectorTests {
|
||||
V1ObjectMeta objectMeta = new V1ObjectMeta();
|
||||
objectMeta.setName("foo");
|
||||
secret.setMetadata(objectMeta);
|
||||
// stubFor(post(WireMock.urlEqualTo("/my/custom/actuator/refresh")).willReturn(aResponse().withStatus(200)));
|
||||
// StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
// verify(postRequestedFor(urlEqualTo("/my/custom/actuator/refresh")));
|
||||
WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/my/custom/actuator/refresh"))
|
||||
.willReturn(WireMock.aResponse().withStatus(200)));
|
||||
StepVerifier.create(changeDetector.triggerRefresh(secret)).verifyComplete();
|
||||
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/my/custom/actuator/refresh")));
|
||||
}
|
||||
|
||||
private void stubReactiveCall() {
|
||||
V1EndpointAddress fooEndpointAddress = new V1EndpointAddress();
|
||||
fooEndpointAddress.setIp("127.0.0.1");
|
||||
fooEndpointAddress.setHostname("localhost");
|
||||
V1EndpointPort fooEndpointPort = new V1EndpointPort();
|
||||
fooEndpointPort.setPort(WIRE_MOCK_SERVER.port());
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
KubernetesServiceInstance fooServiceInstance = new KubernetesServiceInstance("foo", "foo",
|
||||
fooEndpointAddress.getIp(), fooEndpointPort.getPort(), new HashMap<>(), false);
|
||||
instances.add(fooServiceInstance);
|
||||
when(reactiveDiscoveryClient.getInstances(eq("foo"))).thenReturn(Flux.fromIterable(instances));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user