From 871ca162b1359a184f05f8137190be7df1be5396 Mon Sep 17 00:00:00 2001 From: Tglman Date: Thu, 8 Feb 2024 12:16:37 +0100 Subject: [PATCH] test: refactor http tests and migrated to a newer API --- server/pom.xml | 9 +- .../network/http/BaseHttpDatabaseTest.java | 6 +- .../server/network/http/BaseHttpTest.java | 100 +++++++++--------- .../network/http/HttpAuthenticationTest.java | 10 +- .../server/network/http/HttpBatchTest.java | 25 ++--- .../server/network/http/HttpClassTest.java | 28 +---- .../server/network/http/HttpClusterTest.java | 12 +-- .../server/network/http/HttpCommandTest.java | 12 +-- .../network/http/HttpConnectionTest.java | 19 +--- .../server/network/http/HttpDatabaseTest.java | 26 ++--- .../network/http/HttpDisabledTokenTest.java | 16 +-- .../server/network/http/HttpDocumentTest.java | 38 +++---- .../server/network/http/HttpErrorsTest.java | 14 +-- .../server/network/http/HttpFunctionTest.java | 11 +- .../server/network/http/HttpGephiTest.java | 17 ++- .../http/HttpGetStaticContentTest.java | 5 +- .../server/network/http/HttpGraphTest.java | 23 ++-- .../server/network/http/HttpImportTest.java | 5 +- .../network/http/HttpListDatabasesTest.java | 14 +-- .../server/network/http/HttpQueryTest.java | 6 +- .../server/network/http/HttpServerTest.java | 16 ++- .../HttpXRequestedWithXMLHttpRequestTest.java | 17 +-- 22 files changed, 167 insertions(+), 262 deletions(-) diff --git a/server/pom.xml b/server/pom.xml index 79f9a833127..d02b05debfa 100755 --- a/server/pom.xml +++ b/server/pom.xml @@ -71,12 +71,13 @@ 1.77 + - org.apache.httpcomponents - httpclient - 4.5.14 + org.apache.httpcomponents.client5 + httpclient5 + 5.3.1 test - + org.apache.httpcomponents diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpDatabaseTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpDatabaseTest.java index 105dddd6a2c..c81b31ad19d 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpDatabaseTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpDatabaseTest.java @@ -29,8 +29,7 @@ public void createDatabase() throws Exception { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); onAfterDatabaseCreated(); @@ -43,8 +42,7 @@ public void dropDatabase() throws Exception { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 204); super.stopServer(); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpTest.java index 57b2bc65881..0e74fd78b0b 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/BaseHttpTest.java @@ -5,30 +5,24 @@ import com.orientechnologies.orient.server.OServer; import java.io.File; import java.io.IOException; -import org.apache.http.Consts; -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.AuthCache; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.entity.AbstractHttpEntity; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.auth.AuthScope; +import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPatch; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpPut; +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.io.entity.AbstractHttpEntity; +import org.apache.hc.core5.http.io.entity.StringEntity; /** * Base test class for HTTP protocol. @@ -36,6 +30,7 @@ * @author Luca Garulli (l.garulli--(at)--orientdb.com) (l.garulli--at-orientdb.com) */ public abstract class BaseHttpTest { + protected String serverDirectory; private static OServer server; @@ -51,9 +46,11 @@ public abstract class BaseHttpTest { private String databaseName; private Boolean keepAlive = null; - private HttpRequestBase request; + private ClassicHttpRequest request; private AbstractHttpEntity payload; - private HttpResponse response; + private ClassicHttpResponse response; + + private CloseableHttpClient client; private int retry = 1; public enum CONTENT { @@ -65,8 +62,7 @@ public BaseHttpTest payload(final String content, final CONTENT contentType) { payload = new StringEntity( content, - ContentType.create( - contentType == CONTENT.JSON ? "application/json" : "plain/text", Consts.UTF_8)); + ContentType.create(contentType == CONTENT.JSON ? "application/json" : "plain/text")); return this; } @@ -82,6 +78,10 @@ protected void startServer() throws Exception { } protected void stopServer() throws Exception { + if (client != null) { + client.close(); + } + if (server != null) { server.shutdown(); server = null; @@ -100,35 +100,31 @@ protected boolean isInDevelopmentMode() { } protected BaseHttpTest exec() throws IOException { - final HttpHost targetHost = new HttpHost(getHost(), getPort(), getProtocol()); + final HttpHost targetHost = new HttpHost(getProtocol(), getHost(), getPort()); - CredentialsProvider credsProvider = new BasicCredentialsProvider(); + var credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(targetHost), - new UsernamePasswordCredentials(getUserName(), getUserPassword())); - - // Create AuthCache instance - AuthCache authCache = new BasicAuthCache(); - // Generate BASIC scheme object and add it to the local auth cache - BasicScheme basicAuth = new BasicScheme(); - authCache.put(targetHost, basicAuth); + new UsernamePasswordCredentials(getUserName(), getUserPassword().toCharArray())); - // Add AuthCache to the execution context - HttpClientContext context = HttpClientContext.create(); - context.setCredentialsProvider(credsProvider); - context.setAuthCache(authCache); + final BasicCredentialsProvider provider = new BasicCredentialsProvider(); + AuthScope authScope = new AuthScope(targetHost); + provider.setCredentials( + authScope, new UsernamePasswordCredentials(getUserName(), getUserPassword().toCharArray())); - if (keepAlive != null) request.addHeader("Connection", keepAlive ? "Keep-Alive" : "Close"); - - if (payload != null && request instanceof HttpEntityEnclosingRequestBase) - ((HttpEntityEnclosingRequestBase) request).setEntity(payload); + if (keepAlive != null) { + request.addHeader("Connection", keepAlive ? "Keep-Alive" : "Close"); + } - final CloseableHttpClient httpClient = HttpClients.createDefault(); + if (payload != null && request instanceof HttpUriRequestBase httpUriRequestBase) { + httpUriRequestBase.setEntity(payload); + } - // DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retry, false); + client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); + // DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retry, + // false); // context.setAttribute(HttpMethodParams.RETRY_HANDLER, retryhandler); - - response = httpClient.execute(targetHost, request, context); + response = client.execute(request); return this; } @@ -171,8 +167,10 @@ protected BaseHttpTest patch(final String url) throws IOException { return this; } - protected HttpResponse getResponse() throws IOException { - if (response == null) exec(); + protected ClassicHttpResponse getResponse() throws IOException { + if (response == null) { + exec(); + } return response; } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpAuthenticationTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpAuthenticationTest.java index 62b14a8fb3d..c9a8fabc55f 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpAuthenticationTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpAuthenticationTest.java @@ -4,7 +4,9 @@ import java.net.URLEncoder; import org.junit.Assert; -/** @author Luca Garulli (l.garulli--(at)--orientdb.com) (l.garulli--at-orientdb.com) */ +/** + * @author Luca Garulli (l.garulli--(at)--orientdb.com) (l.garulli--at-orientdb.com) + */ public class HttpAuthenticationTest extends BaseHttpDatabaseTest { public void testChangeOfUserOnSameConnectionIsAllowed() throws IOException { Assert.assertEquals( @@ -16,8 +18,7 @@ public void testChangeOfUserOnSameConnectionIsAllowed() throws IOException { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -29,8 +30,7 @@ public void testChangeOfUserOnSameConnectionIsAllowed() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpBatchTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpBatchTest.java index 87ecaf6deee..b4e4d2bba57 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpBatchTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpBatchTest.java @@ -7,8 +7,7 @@ import java.io.InputStreamReader; import java.util.Iterator; import java.util.List; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.Assert; import org.junit.Before; @@ -24,13 +23,12 @@ public void beforeMethod() { getServer().getPlugin("script-interpreter").startup(); } - public void batchUpdate() throws IOException { + public void batchUpdate() throws Exception { Assert.assertEquals( post("command/" + getDatabaseName() + "/sql/") .payload("create class User", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -39,8 +37,7 @@ public void batchUpdate() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); String response = EntityUtils.toString(getResponse().getEntity()); @@ -71,8 +68,7 @@ public void batchUpdate() throws IOException { + "}", CONTENT.JSON) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); // TEST DOUBLE UPDATE @@ -96,8 +92,7 @@ public void batchUpdate() throws IOException { + "}", CONTENT.JSON) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); // TEST WRONG VERSION ON UPDATE @@ -121,8 +116,7 @@ public void batchUpdate() throws IOException { + "}", CONTENT.JSON) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 409); batchWithEmpty(); @@ -139,10 +133,9 @@ private void batchWithEmpty() throws IOException { + "return [$a, $b]\"" + "}]\n" + "}"; - HttpResponse response = - post("batch/" + getDatabaseName()).payload(json, CONTENT.TEXT).getResponse(); + var response = post("batch/" + getDatabaseName()).payload(json, CONTENT.TEXT).getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); + Assert.assertEquals(response.getCode(), 200); InputStream stream = response.getEntity().getContent(); String string = ""; BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClassTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClassTest.java index b6eac0909cb..447c3f8dae6 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClassTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClassTest.java @@ -11,45 +11,27 @@ public class HttpClassTest extends BaseHttpDatabaseTest { @Test public void testExistentClass() throws Exception { - Assert.assertEquals( - get("class/" + getDatabaseName() + "/OUser").getResponse().getStatusLine().getStatusCode(), - 200); + Assert.assertEquals(get("class/" + getDatabaseName() + "/OUser").getResponse().getCode(), 200); } @Test public void testNonExistentClass() throws Exception { Assert.assertEquals( - get("class/" + getDatabaseName() + "/NonExistentCLass") - .getResponse() - .getStatusLine() - .getStatusCode(), - 404); + get("class/" + getDatabaseName() + "/NonExistentCLass").getResponse().getCode(), 404); } @Test public void testCreateClass() throws Exception { Assert.assertEquals( - post("class/" + getDatabaseName() + "/NewClass") - .getResponse() - .getStatusLine() - .getStatusCode(), - 201); + post("class/" + getDatabaseName() + "/NewClass").getResponse().getCode(), 201); } @Test public void testDropClass() throws Exception { Assert.assertEquals( - post("class/" + getDatabaseName() + "/NewClassToDrop") - .getResponse() - .getStatusLine() - .getStatusCode(), - 201); + post("class/" + getDatabaseName() + "/NewClassToDrop").getResponse().getCode(), 201); Assert.assertEquals( - delete("class/" + getDatabaseName() + "/NewClassToDrop") - .getResponse() - .getStatusLine() - .getStatusCode(), - 204); + delete("class/" + getDatabaseName() + "/NewClassToDrop").getResponse().getCode(), 204); } @Override diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClusterTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClusterTest.java index 739f2fc39a1..70365d687d2 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClusterTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpClusterTest.java @@ -12,21 +12,13 @@ public class HttpClusterTest extends BaseHttpDatabaseTest { @Test public void testExistentClass() throws Exception { Assert.assertEquals( - get("cluster/" + getDatabaseName() + "/OUser") - .getResponse() - .getStatusLine() - .getStatusCode(), - 200); + get("cluster/" + getDatabaseName() + "/OUser").getResponse().getCode(), 200); } @Test public void testNonExistentClass() throws Exception { Assert.assertEquals( - get("cluster/" + getDatabaseName() + "/NonExistentCLass") - .getResponse() - .getStatusLine() - .getStatusCode(), - 404); + get("cluster/" + getDatabaseName() + "/NonExistentCLass").getResponse().getCode(), 404); } @Override diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpCommandTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpCommandTest.java index af5437d0447..577df8781a4 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpCommandTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpCommandTest.java @@ -20,8 +20,7 @@ public void commandRootCredentials() throws IOException { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } @@ -33,8 +32,7 @@ public void commandDatabaseCredentials() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } @@ -49,8 +47,7 @@ public void commandWithNamedParams() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); final InputStream response = getResponse().getEntity().getContent(); @@ -73,8 +70,7 @@ public void commandWithPosParams() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); final InputStream response = getResponse().getEntity().getContent(); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpConnectionTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpConnectionTest.java index 209972c4b48..593b489ab54 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpConnectionTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpConnectionTest.java @@ -15,8 +15,7 @@ public class HttpConnectionTest extends BaseHttpDatabaseTest { @Test public void testConnect() throws Exception { - Assert.assertEquals( - get("connect/" + getDatabaseName()).getResponse().getStatusLine().getStatusCode(), 204); + Assert.assertEquals(get("connect/" + getDatabaseName()).getResponse().getCode(), 204); } public void testTooManyConnect() throws Exception { @@ -37,11 +36,7 @@ public void testTooManyConnect() throws Exception { for (int i = 0; i < TOTAL; ++i) { try { final int response = - get("connect/" + getDatabaseName()) - .setRetry(0) - .getResponse() - .getStatusLine() - .getStatusCode(); + get("connect/" + getDatabaseName()).setRetry(0).getResponse().getCode(); Assert.assertEquals(response, 204); good++; } catch (IOException e) { @@ -79,12 +74,7 @@ protected void testConnectAutoDisconnect() throws Exception { int TOTAL = max * 3; for (int i = 0; i < TOTAL; ++i) { - final int response = - get("connect/" + getDatabaseName()) - .setRetry(0) - .getResponse() - .getStatusLine() - .getStatusCode(); + final int response = get("connect/" + getDatabaseName()).setRetry(0).getResponse().getCode(); Assert.assertEquals(response, 204); if (i % 100 == 0) System.out.printf("\nConnections " + i); @@ -100,8 +90,7 @@ protected void testConnectAutoDisconnect() throws Exception { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); final ODocument serverStatus = diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDatabaseTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDatabaseTest.java index bcbb1b74f21..ebd83eb4b1c 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDatabaseTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDatabaseTest.java @@ -2,11 +2,10 @@ import com.orientechnologies.orient.core.OConstants; import com.orientechnologies.orient.core.record.impl.ODocument; -import com.orientechnologies.orient.test.server.network.http.BaseHttpTest.CONTENT; import java.io.IOException; import java.net.URLEncoder; import java.util.Map; -import org.apache.http.HttpResponse; +import org.apache.hc.core5.http.HttpResponse; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -25,8 +24,7 @@ public void testCreateDatabaseNoType() throws Exception { .setUserPassword("root") .post("database/" + getDatabaseName()) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 500); } @@ -37,8 +35,7 @@ public void testCreateDatabaseWrongPassword() throws Exception { .setUserPassword("wrongPasswod") .post("database/wrongpasswd") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 401); } @@ -53,8 +50,7 @@ public void testCreateAndGetDatabase() throws IOException { .post("database/" + getDatabaseName() + "/memory") .payload(pass.toJSON(), CONTENT.JSON) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); HttpResponse response = @@ -63,7 +59,7 @@ public void testCreateAndGetDatabase() throws IOException { .get("database/" + getDatabaseName()) .getResponse(); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + Assert.assertEquals(200, response.getCode()); final ODocument payload = new ODocument().fromJSON(getResponse().getEntity().getContent()); @@ -81,8 +77,7 @@ public void testCreateQueryAndDropDatabase() throws Exception { .post("database/" + getDatabaseName() + "/memory") .payload(pass.toJSON(), CONTENT.JSON) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -95,8 +90,7 @@ public void testCreateQueryAndDropDatabase() throws Exception { + URLEncoder.encode("select from OUSer", "UTF8") + "/10") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -104,8 +98,7 @@ public void testCreateQueryAndDropDatabase() throws Exception { .setUserPassword("root") .delete("database/" + getDatabaseName()) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 204); } @@ -116,8 +109,7 @@ public void testDropUnknownDatabase() throws Exception { .setUserPassword("root") .delete("database/whateverdbname") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 500); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDisabledTokenTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDisabledTokenTest.java index bf624320392..7c0ed03d386 100644 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDisabledTokenTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDisabledTokenTest.java @@ -5,13 +5,13 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import org.apache.http.HttpEntity; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; +import org.apache.hc.client5.http.ClientProtocolException; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.StringEntity; import org.junit.Test; public class HttpDisabledTokenTest extends BaseHttpDatabaseTest { @@ -27,7 +27,7 @@ public void testTokenRequest() throws ClientProtocolException, IOException { request.setEntity(new StringEntity("grant_type=password&username=admin&password=admin")); final CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = httpClient.execute(request); - assertEquals(response.getStatusLine().getStatusCode(), 400); + assertEquals(response.getCode(), 400); HttpEntity entity = response.getEntity(); ByteArrayOutputStream out = new ByteArrayOutputStream(); entity.writeTo(out); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDocumentTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDocumentTest.java index 126e696c982..912929122c2 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDocumentTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpDocumentTest.java @@ -18,7 +18,7 @@ public void create() throws IOException { .payload("{@class:'V', name:'Jay', surname:'Miner',age:99, \"@version\":100}", CONTENT.JSON) .exec(); - Assert.assertEquals(201, getResponse().getStatusLine().getStatusCode()); + Assert.assertEquals(201, getResponse().getCode()); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); @@ -34,7 +34,7 @@ public void read() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:99}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -44,7 +44,7 @@ public void read() throws IOException { get("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 200); + Assert.assertEquals(getResponse().getCode(), 200); final ODocument updated = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(updated.field("name"), "Jay"); @@ -58,7 +58,7 @@ public void updateFull() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -73,7 +73,7 @@ public void updateFull() throws IOException { put("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .payload(created.toJSON(), CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 200); + Assert.assertEquals(getResponse().getCode(), 200); final ODocument updated = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(updated.field("name"), "Jay2"); @@ -87,7 +87,7 @@ public void updateFullNoVersion() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -98,7 +98,7 @@ public void updateFullNoVersion() throws IOException { put("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .payload("{name:'Jay2', surname:'Miner2',age:1}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 200); + Assert.assertEquals(getResponse().getCode(), 200); final ODocument updated = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(updated.field("name"), "Jay2"); @@ -112,7 +112,7 @@ public void updateFullBadVersion() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -123,7 +123,7 @@ public void updateFullBadVersion() throws IOException { put("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .payload("{name:'Jay2', surname:'Miner2',age:1, @version: 2}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 409); + Assert.assertEquals(getResponse().getCode(), 409); } @Test @@ -131,7 +131,7 @@ public void updatePartial() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -146,7 +146,7 @@ public void updatePartial() throws IOException { + "?updateMode=partial") .payload("{age:1}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 200); + Assert.assertEquals(getResponse().getCode(), 200); final ODocument updated = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(updated.field("name"), "Jay"); @@ -160,7 +160,7 @@ public void patchPartial() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -171,7 +171,7 @@ public void patchPartial() throws IOException { patch("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .payload("{age:1,@version:1}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 200); + Assert.assertEquals(getResponse().getCode(), 200); final ODocument updated = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(updated.field("name"), "Jay"); @@ -185,7 +185,7 @@ public void deleteByRid() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -195,11 +195,11 @@ public void deleteByRid() throws IOException { delete("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 204); + Assert.assertEquals(getResponse().getCode(), 204); get("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 404); + Assert.assertEquals(getResponse().getCode(), 404); } @Test @@ -207,7 +207,7 @@ public void deleteWithMVCC() throws IOException { post("document/" + getDatabaseName()) .payload("{@class:'V', name:'Jay', surname:'Miner',age:0}", CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 201); + Assert.assertEquals(getResponse().getCode(), 201); final ODocument created = new ODocument().fromJSON(getResponse().getEntity().getContent()); Assert.assertEquals(created.field("name"), "Jay"); @@ -218,11 +218,11 @@ public void deleteWithMVCC() throws IOException { delete("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .payload(created.toJSON(), CONTENT.JSON) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 204); + Assert.assertEquals(getResponse().getCode(), 204); get("document/" + getDatabaseName() + "/" + created.getIdentity().toString().substring(1)) .exec(); - Assert.assertEquals(getResponse().getStatusLine().getStatusCode(), 404); + Assert.assertEquals(getResponse().getCode(), 404); } @Override diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpErrorsTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpErrorsTest.java index 877c15228f9..1a1504aa56a 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpErrorsTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpErrorsTest.java @@ -14,24 +14,14 @@ public class HttpErrorsTest extends BaseHttpTest { @Test public void testCommandNotFound() throws Exception { Assert.assertEquals( - setUserName("root") - .setUserPassword("root") - .get("commandNotfound") - .getResponse() - .getStatusLine() - .getStatusCode(), + setUserName("root").setUserPassword("root").get("commandNotfound").getResponse().getCode(), 405); } @Test public void testCommandWrongMethod() throws Exception { Assert.assertEquals( - setUserName("root") - .setUserPassword("root") - .post("listDatabases") - .getResponse() - .getStatusLine() - .getStatusCode(), + setUserName("root").setUserPassword("root").post("listDatabases").getResponse().getCode(), 405); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpFunctionTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpFunctionTest.java index c0272e90c69..e8e60a3af35 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpFunctionTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpFunctionTest.java @@ -1,9 +1,8 @@ package com.orientechnologies.orient.test.server.network.http; import com.orientechnologies.orient.core.record.impl.ODocument; -import java.io.IOException; import java.util.List; -import org.apache.http.util.EntityUtils; +import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.Assert; import org.junit.Test; @@ -15,7 +14,7 @@ public class HttpFunctionTest extends BaseHttpDatabaseTest { @Test - public void callFunction() throws IOException { + public void callFunction() throws Exception { // CREATE FUNCTION FIRST Assert.assertEquals( post("command/" + getDatabaseName() + "/sql/") @@ -24,8 +23,7 @@ public void callFunction() throws IOException { + " [name,surname] LANGUAGE javascript", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -34,8 +32,7 @@ public void callFunction() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); String response = EntityUtils.toString(getResponse().getEntity()); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGephiTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGephiTest.java index 8bd9fef7a02..24567774e89 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGephiTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGephiTest.java @@ -1,7 +1,7 @@ package com.orientechnologies.orient.test.server.network.http; import java.io.IOException; -import org.apache.http.HttpResponse; +import org.apache.hc.core5.http.HttpResponse; import org.junit.Assert; import org.junit.Test; @@ -20,12 +20,12 @@ public void commandRootCredentials() throws IOException { .setUserPassword("root") .getResponse(); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + Assert.assertEquals(200, response.getCode()); } @Test public void commandDatabaseCredentials() throws IOException { - HttpResponse response = + var response = get("gephi/" + getDatabaseName() + "/sql/select%20from%20V") .setUserName("admin") .setUserPassword("admin") @@ -33,7 +33,7 @@ public void commandDatabaseCredentials() throws IOException { response.getEntity().writeTo(System.out); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + Assert.assertEquals(200, response.getCode()); } @Override @@ -48,8 +48,7 @@ public void createDatabase() throws Exception { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -60,8 +59,7 @@ public void createDatabase() throws Exception { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( @@ -73,8 +71,7 @@ public void createDatabase() throws Exception { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGetStaticContentTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGetStaticContentTest.java index 0e79c00c538..9641e58e6ff 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGetStaticContentTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGetStaticContentTest.java @@ -7,7 +7,6 @@ import com.orientechnologies.orient.server.network.protocol.http.command.get.OServerCommandGetStaticContent; import java.io.BufferedInputStream; import java.net.URL; -import org.apache.http.HttpResponse; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -54,8 +53,8 @@ public Object call(final String iArgument) { @Test public void testIndexHTML() throws Exception { - HttpResponse response = get("fake/index.htm").getResponse(); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + var response = get("fake/index.htm").getResponse(); + Assert.assertEquals(200, response.getCode()); String expected = OIOUtils.readStreamAsString( diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGraphTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGraphTest.java index 7ffb64b1a91..6db7407c4c7 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGraphTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpGraphTest.java @@ -6,7 +6,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.apache.http.HttpResponse; import org.junit.Assert; import org.junit.Test; @@ -23,15 +22,13 @@ public void updateWithEdges() throws IOException { post("command/" + getDatabaseName() + "/sql/") .payload("create class Foo extends V", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( post("command/" + getDatabaseName() + "/sql/") .payload("create class FooEdge extends E", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); String script = "begin;"; @@ -45,11 +42,11 @@ public void updateWithEdges() throws IOException { "{ \"operations\" : [{ \"type\" : \"script\", \"language\" : \"SQL\", \"script\" :" + " \"%s\"}]}"; - HttpResponse response = + var response = post("batch/" + getDatabaseName() + "/sql/") .payload(String.format(scriptPayload, script), CONTENT.JSON) .getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); + Assert.assertEquals(response.getCode(), 200); final ODocument result = new ODocument().fromJSON(response.getEntity().getContent()); @@ -68,7 +65,7 @@ public void updateWithEdges() throws IOException { .payload(created.toJSON(), CONTENT.JSON) .exec() .getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); + Assert.assertEquals(response.getCode(), 200); final ODocument updated = new ODocument().fromJSON(response.getEntity().getContent()); Assert.assertEquals(updated.field("name"), "fooUpdated"); @@ -83,15 +80,13 @@ public void getGraphResult() throws IOException { post("command/" + getDatabaseName() + "/sql/") .payload("create class Foo extends V", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); Assert.assertEquals( post("command/" + getDatabaseName() + "/sql/") .payload("create class FooEdge extends E", CONTENT.TEXT) .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); String script = "begin;"; @@ -105,11 +100,11 @@ public void getGraphResult() throws IOException { "{ \"operations\" : [{ \"type\" : \"script\", \"language\" : \"SQL\", \"script\" :" + " \"%s\"}]}"; - HttpResponse response = + var response = post("batch/" + getDatabaseName() + "/sql/") .payload(String.format(scriptPayload, script), CONTENT.JSON) .getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 200); + Assert.assertEquals(response.getCode(), 200); final String payload = new ODocument().field("command", "select from E").field("mode", "graph").toJSON(); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpImportTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpImportTest.java index 457f26b7cdc..13d6f4f7fac 100644 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpImportTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpImportTest.java @@ -8,7 +8,6 @@ import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; -import org.apache.http.HttpResponse; import org.junit.Test; /** Created by tglman on 16/03/16. */ @@ -20,8 +19,8 @@ public void testImport() throws IOException { String content = "{\"records\": [{\"@type\": \"d\", \"@rid\": \"#9:0\",\"@version\": 1,\"@class\": \"V\"}]}"; post("import/" + getDatabaseName() + "?merge=true").payload(content, CONTENT.TEXT); - HttpResponse response = getResponse(); - assertEquals(200, response.getStatusLine().getStatusCode()); + var response = getResponse(); + assertEquals(200, response.getCode()); InputStream is = response.getEntity().getContent(); List out = new LinkedList<>(); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpListDatabasesTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpListDatabasesTest.java index 463944a94e6..c07be0f6f41 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpListDatabasesTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpListDatabasesTest.java @@ -14,24 +14,14 @@ public class HttpListDatabasesTest extends BaseHttpTest { @Test public void testListDatabasesRootUser() throws Exception { Assert.assertEquals( - setUserName("root") - .setUserPassword("root") - .get("listDatabases") - .getResponse() - .getStatusLine() - .getStatusCode(), + setUserName("root").setUserPassword("root").get("listDatabases").getResponse().getCode(), 200); } @Test public void testListDatabasesGuestUser() throws Exception { Assert.assertEquals( - setUserName("guest") - .setUserPassword("guest") - .get("listDatabases") - .getResponse() - .getStatusLine() - .getStatusCode(), + setUserName("guest").setUserPassword("guest").get("listDatabases").getResponse().getCode(), 200); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpQueryTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpQueryTest.java index dace0d2399d..dd32057c216 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpQueryTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpQueryTest.java @@ -22,8 +22,7 @@ public void queryRootCredentials() throws IOException { .setUserName("root") .setUserPassword("root") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } @@ -38,8 +37,7 @@ public void queryDatabaseCredentials() throws IOException { .setUserName("admin") .setUserPassword("admin") .getResponse() - .getStatusLine() - .getStatusCode(), + .getCode(), 200); } diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpServerTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpServerTest.java index 6e94a4ab47d..ff5cc0e3161 100755 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpServerTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpServerTest.java @@ -2,15 +2,14 @@ import com.orientechnologies.orient.core.record.impl.ODocument; import java.io.IOException; -import org.apache.http.HttpResponse; import org.junit.Assert; import org.junit.Test; public class HttpServerTest extends BaseHttpDatabaseTest { @Test public void testGetServer() throws Exception { - HttpResponse res = get("server").getResponse(); - Assert.assertEquals(res.getStatusLine().getStatusCode(), 200); + var res = get("server").getResponse(); + Assert.assertEquals(res.getCode(), 200); ODocument payload = new ODocument().fromJSON(res.getEntity().getContent()); @@ -19,9 +18,8 @@ public void testGetServer() throws Exception { @Test public void testGetConnections() throws Exception { - HttpResponse res = - setUserName("root").setUserPassword("root").get("connections/").getResponse(); - Assert.assertEquals(res.getStatusLine().getStatusCode(), 200); + var res = setUserName("root").setUserPassword("root").get("connections/").getResponse(); + Assert.assertEquals(res.getCode(), 200); ODocument payload = new ODocument().fromJSON(res.getEntity().getContent()); @@ -31,14 +29,14 @@ public void testGetConnections() throws Exception { @Test public void testCreateDatabase() throws IOException { String dbName = getClass().getSimpleName() + "testCreateDatabase"; - HttpResponse res = + var res = setUserName("root") .setUserPassword("root") .post("servercommand") .payload("{\"command\":\"create database " + dbName + " plocal\" }", CONTENT.JSON) .getResponse(); - System.out.println(res.getStatusLine().getReasonPhrase()); - Assert.assertEquals(res.getStatusLine().getStatusCode(), 200); + System.out.println(res.getCode()); + Assert.assertEquals(res.getCode(), 200); Assert.assertTrue(getServer().getContext().exists(dbName)); getServer().getContext().drop(dbName); diff --git a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpXRequestedWithXMLHttpRequestTest.java b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpXRequestedWithXMLHttpRequestTest.java index 5403bb9b9ec..de990f43aaf 100644 --- a/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpXRequestedWithXMLHttpRequestTest.java +++ b/server/src/test/java/com/orientechnologies/orient/test/server/network/http/HttpXRequestedWithXMLHttpRequestTest.java @@ -1,13 +1,14 @@ package com.orientechnologies.orient.test.server.network.http; import java.io.IOException; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.message.BasicHeader; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.message.BasicHeader; import org.junit.Assert; import org.junit.Test; -/** @author Enrico Risa */ +/** + * @author Enrico Risa + */ public class HttpXRequestedWithXMLHttpRequestTest extends BaseHttpDatabaseTest { protected void onAfterDatabaseCreated() throws Exception { setUserPassword("123456"); @@ -17,17 +18,17 @@ protected void onAfterDatabaseCreated() throws Exception { public void sendXMLHttpRequest() throws IOException { Header[] headers = {new BasicHeader("X-Requested-With", "XMLHttpRequest")}; - HttpResponse response = get("class/" + getDatabaseName() + "/OUser", headers).getResponse(); + var response = get("class/" + getDatabaseName() + "/OUser", headers).getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 401); + Assert.assertEquals(response.getCode(), 401); Assert.assertEquals(response.containsHeader("WWW-Authenticate"), false); } @Test public void sendHttpRequest() throws IOException { - HttpResponse response = get("class/" + getDatabaseName() + "/OUser").getResponse(); + var response = get("class/" + getDatabaseName() + "/OUser").getResponse(); - Assert.assertEquals(response.getStatusLine().getStatusCode(), 401); + Assert.assertEquals(response.getCode(), 401); Assert.assertEquals(response.containsHeader("WWW-Authenticate"), true); }