milamberspace commented on code in PR #6854:
URL: https://github.com/apache/jmeter/pull/6854#discussion_r4644317100


##########
src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.apache.jmeter.protocol.http.sampler;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Test;
+
+import com.sun.net.httpserver.HttpServer;
+
+public class HttpQueryTest extends JMeterTestCase implements JMeterSerialTest {
+
+    @Test
+    void querySendsRequestBody() throws Exception {
+        String expectedBody = "{\"name\":\"Ori\"}";
+        AtomicReference<String> receivedMethod = new AtomicReference<>();
+        AtomicReference<String> receivedBody = new AtomicReference<>();
+
+        // Port 0 lets the operating system select an available port.
+        HttpServer server = HttpServer.create(
+                new InetSocketAddress("127.0.0.1", 0), 0);
+
+        server.createContext("/search", exchange -> {
+            try {
+                receivedMethod.set(exchange.getRequestMethod());
+                receivedBody.set(new String(
+                        exchange.getRequestBody().readAllBytes(),
+                        StandardCharsets.UTF_8));
+
+                byte[] response = "OK".getBytes(StandardCharsets.UTF_8);
+                exchange.sendResponseHeaders(200, response.length);
+                try (var output = exchange.getResponseBody()) {
+                    output.write(response);
+                }
+            } finally {
+                exchange.close();
+            }
+        });
+
+        server.start();
+        try {
+            HTTPSamplerProxy sampler =
+                    new HTTPSamplerProxy(HTTPSamplerFactory.IMPL_HTTP_CLIENT4);
+            sampler.setProtocol("http");
+            sampler.setDomain("127.0.0.1");
+            sampler.setPort(server.getAddress().getPort());
+            sampler.setPath("/search");
+            sampler.setMethod("QUERY");

Review Comment:
   Please use the new `HTTPConstants.QUERY` constant here (and in the 
assertion).
   
   More importantly, this test passes on `master` as well: HC4 already sends 
any token method through `HttpWebdav`. Only HC4 is exercised, and nothing 
asserts that `QUERY` is now part of `HTTPSamplerBase.getValidMethodsAsArray()`, 
which is the actual change. A parameterized HC4/HC5 test plus a method-list 
assertion would cover it (see review summary).



##########
src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.apache.jmeter.protocol.http.sampler;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Test;
+
+import com.sun.net.httpserver.HttpServer;
+
+public class HttpQueryTest extends JMeterTestCase implements JMeterSerialTest {
+
+    @Test
+    void querySendsRequestBody() throws Exception {
+        String expectedBody = "{\"name\":\"Ori\"}";

Review Comment:
   Nit: a neutral payload such as `{"q":"jmeter"}` would read better than a 
personal name in test data.



##########
xdocs/usermanual/component_reference.xml:
##########
@@ -272,7 +272,7 @@ https.default.protocol=SSLv3
           <code>JAVA</code> implementation). With <code>HttpClient4</code> or 
<code>HttpClient5</code>, the following methods related to WebDav are
           also allowed: <code>COPY</code>, <code>LOCK</code>, 
<code>MKCOL</code>, <code>MOVE</code>,
           <code>PROPFIND</code>, <code>PROPPATCH</code>, <code>UNLOCK</code>, 
<code>REPORT</code>, <code>MKCALENDAR</code>,
-          <code>SEARCH</code>.
+          <code>SEARCH</code>, <code>QUERY</code>.

Review Comment:
   `QUERY` is not a WebDav method (it comes from the IETF HTTPbis *safe method 
with body* specification), so listing it among "methods related to WebDav" is 
misleading. Suggestion: keep the WebDav list unchanged and add a separate 
sentence, e.g.:
   
   ```suggestion
             <code>SEARCH</code>. The <code>QUERY</code> method (safe and 
idempotent request with a body) is also
             available with <code>HttpClient4</code> or 
<code>HttpClient5</code>; it is not supported by the <code>JAVA</code> 
implementation.
   ```



##########
src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.apache.jmeter.protocol.http.sampler;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.jupiter.api.Test;
+
+import com.sun.net.httpserver.HttpServer;
+
+public class HttpQueryTest extends JMeterTestCase implements JMeterSerialTest {

Review Comment:
   A few style points, in line with the other tests of this module:
   - the class can be package-private (JUnit 5), and `TestHttpQuery` would 
match the naming of neighbouring tests (`TestHttpWebdav`, `TestDecompression`, 
...);
   - `JMeterSerialTest` does not seem needed: the server binds port 0 and the 
test does not touch global JMeter properties;
   - the module uses WireMock everywhere else (`com.sun.net.httpserver` would 
be a first here); WireMock's `verifyThat(...withRequestBody(...))` also removes 
the need for the `AtomicReference` captures.
   
   See the suggested replacement in the review summary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to