From 38542b8cbf73a1eb56c75520804ff7a73ba8119a Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Fri, 18 Oct 2024 16:32:06 +0200 Subject: [PATCH] Use user passed values instead of hardcoding --- .../eureka/EurekaServiceRegistrar.java | 2 +- .../eureka/EurekaRegistrationCDITest.java | 11 ++++++++++- .../eureka/EurekaRegistrationTest.java | 11 ++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/service-registration/eureka/src/main/java/io/smallrye/stork/serviceregistration/eureka/EurekaServiceRegistrar.java b/service-registration/eureka/src/main/java/io/smallrye/stork/serviceregistration/eureka/EurekaServiceRegistrar.java index 66d1a729..eb487e2f 100644 --- a/service-registration/eureka/src/main/java/io/smallrye/stork/serviceregistration/eureka/EurekaServiceRegistrar.java +++ b/service-registration/eureka/src/main/java/io/smallrye/stork/serviceregistration/eureka/EurekaServiceRegistrar.java @@ -42,7 +42,7 @@ public Uni registerServiceInstance(String serviceName, Metadata registrationLatch.countDown(), failure -> fail("")); await().atMost(Duration.ofSeconds(10)) @@ -109,6 +110,14 @@ public void testRegistrationServiceInstances(TestInfo info) { assertThat(httpResponse).isNotNull(); assertThat(httpResponse.statusCode()).isEqualTo(200); + JsonObject jsonResponse = httpResponse.bodyAsJsonObject(); + JsonObject application = jsonResponse.getJsonObject("application"); + JsonObject jsonServiceInstance = application.getJsonArray("instance").getJsonObject(0); + + assertThat(jsonServiceInstance.getString("instanceId")).isEqualTo("my-service"); + assertThat(jsonServiceInstance.getString("ipAddr")).isEqualTo("localhost"); + assertThat(jsonServiceInstance.getJsonObject("port").getInteger("$")).isEqualTo(8406); + } } diff --git a/service-registration/eureka/src/test/java/io/smallrye/stork/serviceregistration/eureka/EurekaRegistrationTest.java b/service-registration/eureka/src/test/java/io/smallrye/stork/serviceregistration/eureka/EurekaRegistrationTest.java index 669635e7..43a86bb9 100644 --- a/service-registration/eureka/src/test/java/io/smallrye/stork/serviceregistration/eureka/EurekaRegistrationTest.java +++ b/service-registration/eureka/src/test/java/io/smallrye/stork/serviceregistration/eureka/EurekaRegistrationTest.java @@ -27,6 +27,7 @@ import io.smallrye.stork.impl.EurekaMetadataKey; import io.smallrye.stork.test.StorkTestUtils; import io.smallrye.stork.test.TestConfigProvider; +import io.vertx.core.json.JsonObject; import io.vertx.ext.web.client.WebClientOptions; import io.vertx.mutiny.core.Vertx; import io.vertx.mutiny.core.buffer.Buffer; @@ -77,7 +78,7 @@ public void testRegistrationServiceInstances(TestInfo info) { CountDownLatch registrationLatch = new CountDownLatch(1); eurekaServiceRegistrar.registerServiceInstance(serviceName, Metadata.of(EurekaMetadataKey.class) - .with(EurekaMetadataKey.META_EUREKA_SERVICE_ID, serviceName), "acme.com", 8406).subscribe() + .with(EurekaMetadataKey.META_EUREKA_SERVICE_ID, serviceName), "localhost", 8406).subscribe() .with(success -> registrationLatch.countDown(), failure -> fail("")); await().atMost(Duration.ofSeconds(10)) @@ -93,6 +94,14 @@ public void testRegistrationServiceInstances(TestInfo info) { assertThat(httpResponse).isNotNull(); assertThat(httpResponse.statusCode()).isEqualTo(200); + JsonObject jsonResponse = httpResponse.bodyAsJsonObject(); + JsonObject application = jsonResponse.getJsonObject("application"); + JsonObject jsonServiceInstance = application.getJsonArray("instance").getJsonObject(0); + + assertThat(jsonServiceInstance.getString("instanceId")).isEqualTo("my-service"); + assertThat(jsonServiceInstance.getString("ipAddr")).isEqualTo("localhost"); + assertThat(jsonServiceInstance.getJsonObject("port").getInteger("$")).isEqualTo(8406); + } }