From 1a3f280b07f0a3acaf9007b4bf1723ab7bcbc973 Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Mon, 14 Oct 2024 16:36:13 +0200 Subject: [PATCH] Fix tests about Dynamic IP using ReverseProxy... --- .../tests/util/LeshanTestClient.java | 25 ++++++++++--------- .../integration/tests/util/ReverseProxy.java | 6 +---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestClient.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestClient.java index 1b1da3d4d9..6969ef7125 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestClient.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestClient.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.leshan.core.util.TestToolBox.uriHandler; import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertArg; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.isNotNull; import static org.mockito.ArgumentMatchers.notNull; @@ -140,10 +141,10 @@ public void waitForRegistrationTo(LeshanTestServer server) { public void waitForRegistrationTo(LeshanTestServer server, long timeout, TimeUnit unit) { inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // isNotNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationSuccess(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // isNotNull(), isNotNull()); inOrder.verifyNoMoreInteractions(); } @@ -157,10 +158,10 @@ public Failure waitForRegistrationFailureTo(LeshanTestServer server, long timeou final ArgumentCaptor cCode = ArgumentCaptor.forClass(ResponseCode.class); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // isNotNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationFailure(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull(), cCode.capture(), any(), cExp.capture()); inOrder.verifyNoMoreInteractions(); @@ -169,10 +170,10 @@ public Failure waitForRegistrationFailureTo(LeshanTestServer server, long timeou public void waitForUpdateTo(LeshanTestServer server, long timeout, TimeUnit unit) { inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateSuccess(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull()); inOrder.verifyNoMoreInteractions(); } @@ -183,10 +184,10 @@ public void waitForDeregistrationTo(LeshanTestServer server) { public void waitForDeregistrationTo(LeshanTestServer server, long timeout, TimeUnit unit) { inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onDeregistrationStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // isNotNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onDeregistrationSuccess(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // isNotNull()); inOrder.verifyNoMoreInteractions(); } @@ -197,11 +198,11 @@ public void waitForUpdateTimeoutTo(LeshanTestServer server) { public void waitForUpdateTimeoutTo(LeshanTestServer server, long timeout, TimeUnit unit) { inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateTimeout(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull()); // if client update timeout, it will retry again then try a register so all events can not be consume by inOrder // ... @@ -213,10 +214,10 @@ public void waitForUpdateFailureTo(LeshanTestServer server) { public void waitForUpdateFailureTo(LeshanTestServer server, long timeout, TimeUnit unit) { inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull()); inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateFailure(assertArg( // - s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), // + s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), // notNull(), // notNull(), // TODO we should be able to check response code any(), // diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/ReverseProxy.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/ReverseProxy.java index 85936ee401..cb561201b3 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/ReverseProxy.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/ReverseProxy.java @@ -233,11 +233,7 @@ public InetSocketAddress getClientSideProxyAddress() { * @return address of server to proxified */ public InetSocketAddress getServerAddress() { - try { - return (InetSocketAddress) clientToProxyChannel.getLocalAddress(); - } catch (IOException e) { - throw new IllegalStateException(e); - } + return serverAddress; } /**