This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch 1.4.x
in repository https://gitbox.apache.org/repos/asf/pekko-http.git


The following commit(s) were added to refs/heads/1.4.x by this push:
     new d56f93e68 use Java APIs in tests (1.4.x) (#1182)
d56f93e68 is described below

commit d56f93e689c24421444a000e030826f17e6aee8c
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Jul 25 16:15:30 2026 +0100

    use Java APIs in tests (1.4.x) (#1182)
    
    * use Java APIs in tests
    
    * Update HttpMessageTest.java
---
 .../docs/http/javadsl/HttpClientDecodingExampleTest.java |  6 +++---
 .../javadsl/server/HttpBasicAuthenticatorExample.java    |  2 +-
 .../http/javadsl/server/OAuth2AuthenticatorExample.java  |  2 +-
 .../docs/http/javadsl/server/WebSocketCoreExample.java   |  4 ++--
 .../server/directives/FutureDirectivesExamplesTest.java  | 16 ++++++++--------
 .../apache/pekko/http/javadsl/model/HttpMessageTest.java |  9 ++++-----
 .../java/org/apache/pekko/http/javadsl/HttpAPIsTest.java |  2 +-
 .../pekko/http/javadsl/server/HandlerBindingTest.java    |  2 +-
 .../javadsl/server/directives/PathDirectivesTest.java    |  2 +-
 .../unmarshalling/sse/EventStreamUnmarshallingTest.java  |  4 ++--
 10 files changed, 24 insertions(+), 25 deletions(-)

diff --git 
a/docs/src/test/java/docs/http/javadsl/HttpClientDecodingExampleTest.java 
b/docs/src/test/java/docs/http/javadsl/HttpClientDecodingExampleTest.java
index 7137f5987..208f6aba8 100644
--- a/docs/src/test/java/docs/http/javadsl/HttpClientDecodingExampleTest.java
+++ b/docs/src/test/java/docs/http/javadsl/HttpClientDecodingExampleTest.java
@@ -19,7 +19,7 @@ import org.apache.pekko.http.javadsl.Http;
 import org.apache.pekko.http.javadsl.coding.Coder;
 import org.apache.pekko.http.javadsl.model.HttpRequest;
 import org.apache.pekko.http.javadsl.model.HttpResponse;
-import org.apache.pekko.http.scaladsl.model.headers.HttpEncodings;
+import org.apache.pekko.http.javadsl.model.headers.HttpEncodings;
 
 import java.util.Arrays;
 import java.util.List;
@@ -48,9 +48,9 @@ public class HttpClientDecodingExampleTest {
         response -> {
           // Pick the right coder
           final Coder coder;
-          if (HttpEncodings.gzip().equals(response.encoding())) {
+          if (HttpEncodings.GZIP.equals(response.encoding())) {
             coder = Coder.Gzip;
-          } else if (HttpEncodings.deflate().equals(response.encoding())) {
+          } else if (HttpEncodings.DEFLATE.equals(response.encoding())) {
             coder = Coder.Deflate;
           } else {
             coder = Coder.NoCoding;
diff --git 
a/docs/src/test/java/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java
 
b/docs/src/test/java/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java
index cb125596f..2f4ab7589 100644
--- 
a/docs/src/test/java/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java
+++ 
b/docs/src/test/java/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java
@@ -18,11 +18,11 @@ import java.util.Optional;
 import org.junit.Test;
 
 import org.apache.pekko.http.javadsl.model.HttpRequest;
+import org.apache.pekko.http.javadsl.model.headers.Authorization;
 import org.apache.pekko.http.javadsl.model.headers.Host;
 import org.apache.pekko.http.javadsl.server.Route;
 import 
org.apache.pekko.http.javadsl.server.directives.SecurityDirectives.ProvidedCredentials;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
-import org.apache.pekko.http.scaladsl.model.headers.Authorization;
 
 // #basic-authenticator-java
 import static 
org.apache.pekko.http.javadsl.server.Directives.authenticateBasic;
diff --git 
a/docs/src/test/java/docs/http/javadsl/server/OAuth2AuthenticatorExample.java 
b/docs/src/test/java/docs/http/javadsl/server/OAuth2AuthenticatorExample.java
index eb651155b..967c29d0b 100644
--- 
a/docs/src/test/java/docs/http/javadsl/server/OAuth2AuthenticatorExample.java
+++ 
b/docs/src/test/java/docs/http/javadsl/server/OAuth2AuthenticatorExample.java
@@ -14,10 +14,10 @@
 package docs.http.javadsl.server;
 
 import org.apache.pekko.http.javadsl.model.HttpRequest;
+import org.apache.pekko.http.javadsl.model.headers.Authorization;
 import org.apache.pekko.http.javadsl.model.headers.Host;
 import 
org.apache.pekko.http.javadsl.server.directives.SecurityDirectives.ProvidedCredentials;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
-import org.apache.pekko.http.scaladsl.model.headers.Authorization;
 
 import java.util.Optional;
 
diff --git 
a/docs/src/test/java/docs/http/javadsl/server/WebSocketCoreExample.java 
b/docs/src/test/java/docs/http/javadsl/server/WebSocketCoreExample.java
index 5455fa1c6..2e6385878 100644
--- a/docs/src/test/java/docs/http/javadsl/server/WebSocketCoreExample.java
+++ b/docs/src/test/java/docs/http/javadsl/server/WebSocketCoreExample.java
@@ -26,12 +26,12 @@ import org.apache.pekko.NotUsed;
 import org.apache.pekko.http.impl.util.JavaMapping;
 import org.apache.pekko.http.javadsl.ConnectHttp;
 import org.apache.pekko.http.javadsl.ConnectionContext;
+import org.apache.pekko.http.javadsl.model.AttributeKeys;
 import org.apache.pekko.http.javadsl.model.StatusCodes;
 import org.apache.pekko.http.javadsl.model.ws.WebSocketRequest;
 import org.apache.pekko.http.javadsl.settings.ClientConnectionSettings;
 import org.apache.pekko.http.javadsl.settings.ServerSettings;
 import org.apache.pekko.http.javadsl.settings.WebSocketSettings;
-import org.apache.pekko.http.scaladsl.model.AttributeKeys;
 import org.apache.pekko.japi.JavaPartialFunction;
 import org.apache.pekko.japi.function.Function;
 
@@ -58,7 +58,7 @@ public class WebSocketCoreExample {
 
     if (request.getUri().path().equals("/greeter")) {
       return request
-          .getAttribute(AttributeKeys.webSocketUpgrade())
+          .getAttribute(AttributeKeys.webSocketUpgrade)
           .map(
               upgrade -> {
                 Flow<Message, Message, NotUsed> greeterFlow = greeter();
diff --git 
a/docs/src/test/java/docs/http/javadsl/server/directives/FutureDirectivesExamplesTest.java
 
b/docs/src/test/java/docs/http/javadsl/server/directives/FutureDirectivesExamplesTest.java
index 65af9b1f0..6b79ea13c 100644
--- 
a/docs/src/test/java/docs/http/javadsl/server/directives/FutureDirectivesExamplesTest.java
+++ 
b/docs/src/test/java/docs/http/javadsl/server/directives/FutureDirectivesExamplesTest.java
@@ -18,10 +18,10 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.pekko.http.javadsl.model.HttpRequest;
+import org.apache.pekko.http.javadsl.model.StatusCodes;
 import org.apache.pekko.http.javadsl.marshalling.Marshaller;
 import org.apache.pekko.http.javadsl.server.Route;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
-import org.apache.pekko.http.scaladsl.model.StatusCodes;
 import org.apache.pekko.japi.pf.PFBuilder;
 import org.apache.pekko.pattern.CircuitBreaker;
 import org.apache.pekko.testkit.javadsl.TestKit;
@@ -75,7 +75,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
                                     .matchAny(
                                         ex ->
                                             complete(
-                                                
StatusCodes.InternalServerError(),
+                                                
StatusCodes.INTERNAL_SERVER_ERROR,
                                                 "An error occurred: " + 
ex.getMessage()))
                                     .build())
                             .get()));
@@ -84,7 +84,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
 
     testRoute(route)
         .run(HttpRequest.GET("/divide/10/0"))
-        .assertStatusCode(StatusCodes.InternalServerError())
+        .assertStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
         .assertEntity("An error occurred: / by zero");
     // #onComplete
   }
@@ -114,7 +114,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
 
     testRoute(route)
         .run(HttpRequest.GET("/failure"))
-        .assertStatusCode(StatusCodes.InternalServerError())
+        .assertStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
         .assertEntity("There was an internal server error.");
     // #onSuccess
   }
@@ -148,7 +148,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
 
     testRoute(route)
         .run(HttpRequest.GET("/failure"))
-        .assertStatusCode(StatusCodes.InternalServerError())
+        .assertStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
         .assertEntity("There was an internal server error.");
     // #completeOrRecoverWith
   }
@@ -185,7 +185,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
                                     .matchAny(
                                         ex ->
                                             complete(
-                                                
StatusCodes.InternalServerError(),
+                                                
StatusCodes.INTERNAL_SERVER_ERROR,
                                                 "An error occurred: " + 
ex.toString()))
                                     .build())
                             .get()));
@@ -194,7 +194,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
 
     testRoute(route)
         .run(HttpRequest.GET("/divide/10/0"))
-        .assertStatusCode(StatusCodes.InternalServerError())
+        .assertStatusCode(StatusCodes.INTERNAL_SERVER_ERROR)
         .assertEntity("An error occurred: java.lang.ArithmeticException: / by 
zero");
 
     // The circuit-breaker will eventually be opened
@@ -207,7 +207,7 @@ public class FutureDirectivesExamplesTest extends 
JUnitRouteTest {
                   .run(HttpRequest.GET("/divide/10/0"))
                   .assertEntity(
                       "The server is currently unavailable (because it is 
overloaded or down for maintenance).")
-                  .assertStatusCode(StatusCodes.ServiceUnavailable());
+                  .assertStatusCode(StatusCodes.SERVICE_UNAVAILABLE);
               return null;
             });
 
diff --git 
a/http-core/src/test/java/org/apache/pekko/http/javadsl/model/HttpMessageTest.java
 
b/http-core/src/test/java/org/apache/pekko/http/javadsl/model/HttpMessageTest.java
index 56df3a7e8..8afca552c 100644
--- 
a/http-core/src/test/java/org/apache/pekko/http/javadsl/model/HttpMessageTest.java
+++ 
b/http-core/src/test/java/org/apache/pekko/http/javadsl/model/HttpMessageTest.java
@@ -13,7 +13,6 @@
 
 package org.apache.pekko.http.javadsl.model;
 
-import org.apache.pekko.http.scaladsl.model.AttributeKey$;
 import org.apache.pekko.stream.scaladsl.TLSPlacebo;
 import org.junit.Test;
 import org.scalatestplus.junit.JUnitSuite;
@@ -23,6 +22,7 @@ import javax.net.ssl.SSLSession;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class HttpMessageTest extends JUnitSuite {
   @Test
@@ -31,8 +31,7 @@ public class HttpMessageTest extends JUnitSuite {
     // keys with the same type but different names should be considered 
different
     AttributeKey<String> otherStringKey = AttributeKey.create("other", 
String.class);
 
-    // it should be possible to use 'Scala attribute keys' in the Java API's
-    AttributeKey<Integer> intKey = AttributeKey$.MODULE$.apply("int", 
Integer.class);
+    AttributeKey<Integer> intKey = AttributeKey.create("int", Integer.class);
     // keys with the same name but different types should be considered 
different
     AttributeKey<Integer> otherIntKey = AttributeKey.create("other", 
Integer.class);
 
@@ -64,7 +63,7 @@ public class HttpMessageTest extends JUnitSuite {
     RemoteAddress remoteAddress = RemoteAddress.create(new byte[] {10, 0, 0, 
1});
     HttpRequest newRequest = request.addAttribute(AttributeKeys.remoteAddress, 
remoteAddress);
 
-    assert 
(newRequest.getAttribute(AttributeKeys.remoteAddress).get().equals(remoteAddress));
+    
assertTrue(newRequest.getAttribute(AttributeKeys.remoteAddress).get().equals(remoteAddress));
   }
 
   @Test
@@ -73,6 +72,6 @@ public class HttpMessageTest extends JUnitSuite {
     HttpRequest request =
         HttpRequest.create().addAttribute(AttributeKeys.sslSession, 
SslSessionInfo.create(session));
 
-    assert (request.getAttribute(AttributeKeys.sslSession).get().getSession() 
== session);
+    
assertTrue(request.getAttribute(AttributeKeys.sslSession).get().getSession() == 
session);
   }
 }
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/HttpAPIsTest.java 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/HttpAPIsTest.java
index 3382afa52..fddc5f223 100644
--- a/http-tests/src/test/java/org/apache/pekko/http/javadsl/HttpAPIsTest.java
+++ b/http-tests/src/test/java/org/apache/pekko/http/javadsl/HttpAPIsTest.java
@@ -17,8 +17,8 @@ import org.apache.pekko.event.LoggingAdapter;
 import org.apache.pekko.http.javadsl.model.HttpRequest;
 import org.apache.pekko.http.javadsl.model.HttpResponse;
 import org.apache.pekko.http.javadsl.settings.ClientConnectionSettings;
+import org.apache.pekko.http.javadsl.settings.ConnectionPoolSettings;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
-import org.apache.pekko.http.scaladsl.settings.ConnectionPoolSettings;
 import org.apache.pekko.japi.function.Function;
 import org.apache.pekko.stream.javadsl.Flow;
 import com.typesafe.config.ConfigFactory;
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/HandlerBindingTest.java
 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/HandlerBindingTest.java
index bc3e54ca7..81510e220 100644
--- 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/HandlerBindingTest.java
+++ 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/HandlerBindingTest.java
@@ -17,9 +17,9 @@ import static 
org.apache.pekko.http.javadsl.unmarshalling.StringUnmarshallers.IN
 
 import org.junit.Test;
 
+import org.apache.pekko.http.javadsl.model.HttpRequest;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
 import org.apache.pekko.http.javadsl.testkit.TestRouteResult;
-import org.apache.pekko.http.scaladsl.model.HttpRequest;
 
 import static org.apache.pekko.http.javadsl.server.Directives.*;
 
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/PathDirectivesTest.java
 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/PathDirectivesTest.java
index 191d3af5f..9b580a490 100644
--- 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/PathDirectivesTest.java
+++ 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/PathDirectivesTest.java
@@ -17,12 +17,12 @@ import static 
org.apache.pekko.http.javadsl.server.PathMatchers.*;
 
 import org.junit.Test;
 
+import org.apache.pekko.http.javadsl.model.HttpRequest;
 import org.apache.pekko.http.javadsl.model.StatusCodes;
 import org.apache.pekko.http.javadsl.model.headers.Host;
 import org.apache.pekko.http.javadsl.server.PathMatchers;
 import org.apache.pekko.http.javadsl.testkit.JUnitRouteTest;
 import org.apache.pekko.http.javadsl.testkit.TestRoute;
-import org.apache.pekko.http.scaladsl.model.HttpRequest;
 
 public class PathDirectivesTest extends JUnitRouteTest {
   @Test
diff --git 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/unmarshalling/sse/EventStreamUnmarshallingTest.java
 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/unmarshalling/sse/EventStreamUnmarshallingTest.java
index eb91d3970..64e269fdd 100644
--- 
a/http-tests/src/test/java/org/apache/pekko/http/javadsl/unmarshalling/sse/EventStreamUnmarshallingTest.java
+++ 
b/http-tests/src/test/java/org/apache/pekko/http/javadsl/unmarshalling/sse/EventStreamUnmarshallingTest.java
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Test;
 import org.scalatestplus.junit.JUnitSuite;
-import static org.apache.pekko.util.FutureConverters.asJava;
 
 public class EventStreamUnmarshallingTest extends JUnitSuite {
 
@@ -48,7 +47,8 @@ public class EventStreamUnmarshallingTest extends JUnitSuite {
 
       Assert.assertEquals(events, unmarshalledEvents);
     } finally {
-      asJava(system.terminate()).toCompletableFuture().get(42, 
TimeUnit.SECONDS);
+      system.terminate();
+      system.getWhenTerminated().toCompletableFuture().get(42, 
TimeUnit.SECONDS);
     }
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to