2323import com .fasterxml .jackson .databind .node .ObjectNode ;
2424import com .marklogic .client .DatabaseClient ;
2525import com .marklogic .client .DatabaseClient .ConnectionType ;
26+ import com .marklogic .client .DatabaseClientBuilder ;
2627import com .marklogic .client .DatabaseClientFactory ;
27- import com .marklogic .client .DatabaseClientFactory .SecurityContext ;
2828import com .marklogic .client .admin .ServerConfigurationManager ;
2929import com .marklogic .client .impl .OkHttpServices ;
3030import com .marklogic .client .impl .RESTServices ;
4848
4949public abstract class ConnectedRESTQA {
5050
51+ protected static Properties testProperties = null ;
52+
5153 protected static String securityContextType ;
5254 protected static String restServerName = null ;
5355 private static String restSslServerName = null ;
@@ -2019,45 +2021,64 @@ else if (getSslEnabled().trim().equalsIgnoreCase("false") || getSslEnabled() ==
20192021 return bSecurityEnabled ;
20202022 }
20212023
2024+ public static DatabaseClientBuilder newDatabaseClientBuilder () {
2025+ Map <String , Object > props = new HashMap <>();
2026+ testProperties .entrySet ().forEach (entry -> props .put ((String ) entry .getKey (), entry .getValue ()));
2027+ return new DatabaseClientBuilder (props );
2028+ }
2029+
2030+ public static DatabaseClient newBasicAuthClient (String username , String password ) {
2031+ return newDatabaseClientBuilder ()
2032+ .withUsername (username )
2033+ .withPassword (password )
2034+ .withSecurityContextType ("basic" )
2035+ .build ();
2036+ }
2037+
20222038 public static DatabaseClient newClientAsUser (String username , String password ) {
2023- return newClient (getRestServerHostName (), getRestServerPort (), null , newSecurityContext (username , password ), null );
2039+ return newDatabaseClientBuilder ()
2040+ .withUsername (username )
2041+ .withPassword (password )
2042+ .build ();
20242043 }
20252044
2026- public static DatabaseClient newAdminModulesClient () {
2027- return newClient (getRestServerHostName (), getRestServerPort (), "java-unittest-modules" ,
2028- newSecurityContext (getAdminUser (), getAdminPassword ()), null );
2045+ public static DatabaseClient newClientForDatabase (String database ) {
2046+ return newDatabaseClientBuilder ()
2047+ .withDatabase (database )
2048+ .build ();
20292049 }
20302050
2031- public static DatabaseClient newBasicAuthClient (String username , String password ) {
2032- return newClient (getRestServerHostName (), getRestServerPort (), null ,
2033- new DatabaseClientFactory .BasicAuthContext (username , password ), null );
2051+ public static DatabaseClient newAdminModulesClient () {
2052+ return newDatabaseClientBuilder ()
2053+ .withUsername (getAdminUser ())
2054+ .withPassword (getAdminPassword ())
2055+ .withDatabase ("java-unittest-modules" )
2056+ .build ();
20342057 }
20352058
20362059 public static DatabaseClient getDatabaseClient (String user , String password , ConnectionType connType )
20372060 throws KeyManagementException , NoSuchAlgorithmException , IOException {
2038- return newClient (getRestServerHostName (), getRestServerPort (), null , newSecurityContext (user , password ), connType );
2061+ return newDatabaseClientBuilder ()
2062+ .withUsername (user )
2063+ .withPassword (password )
2064+ .withConnectionType (connType )
2065+ .build ();
20392066 }
20402067
20412068 /**
2042- * Intent is for every functional test to create a client ultimately via this method so that basePath can be
2043- * applied in one place.
2044- *
2045- * @param host
2046- * @param port
2047- * @param database
2048- * @param securityContext
2049- * @param connectionType
2050- * @return
2069+ * Only use this in "slow" functional tests until they're converted over to fast.
20512070 */
2052- public static DatabaseClient newClient (String host , int port , String database ,
2053- SecurityContext securityContext , ConnectionType connectionType ) {
2054- connectionType = connectionType != null ? connectionType : getConnType ();
2055- return DatabaseClientFactory .newClient (host , port , basePath , database , securityContext , connectionType );
2056- }
2057-
2071+ @ Deprecated
20582072 public static DatabaseClient getDatabaseClientOnDatabase (String hostName , int port , String databaseName ,
2059- String user , String password , ConnectionType connType ) {
2060- return newClient (hostName , port , databaseName , newSecurityContext (user , password ), connType );
2073+ String user , String password , ConnectionType connType ) {
2074+ return newDatabaseClientBuilder ()
2075+ .withHost (hostName )
2076+ .withPort (port )
2077+ .withUsername (user )
2078+ .withPassword (password )
2079+ .withDatabase (databaseName )
2080+ .withConnectionType (connType )
2081+ .build ();
20612082 }
20622083
20632084 //Return a Server name. For SSL runs returns value in restSslServerName For
@@ -2090,9 +2111,9 @@ private static void overrideTestPropertiesWithSystemProperties(Properties testPr
20902111 if ("true" .equals (System .getProperty ("TEST_USE_REVERSE_PROXY_SERVER" ))) {
20912112 System .out .println ("TEST_USE_REVERSE_PROXY_SERVER is true, so overriding properties to use reverse proxy server" );
20922113 testProperties .setProperty ("httpPort" , "8020" );
2093- testProperties .setProperty ("fastHttpPort " , "8020" );
2094- testProperties .setProperty ("basePath" , "testFunctional" );
2095- testProperties .setProperty ("securityContextType" , "basic" );
2114+ testProperties .setProperty ("marklogic.client.port " , "8020" );
2115+ testProperties .setProperty ("marklogic.client. basePath" , "testFunctional" );
2116+ testProperties .setProperty ("marklogic.client. securityContextType" , "basic" );
20962117 }
20972118 }
20982119
@@ -2110,18 +2131,18 @@ public static void loadGradleProperties() {
21102131
21112132 overrideTestPropertiesWithSystemProperties (properties );
21122133
2113- securityContextType = properties .getProperty ("securityContextType" );
2134+ securityContextType = properties .getProperty ("marklogic.client. securityContextType" );
21142135 restServerName = properties .getProperty ("mlAppServerName" );
21152136 restSslServerName = properties .getProperty ("mlAppServerSSLName" );
21162137
21172138 https_port = properties .getProperty ("httpsPort" );
21182139 http_port = properties .getProperty ("httpPort" );
2119- fast_http_port = properties .getProperty ("fastHttpPort " );
2120- admin_port = properties . getProperty ( "adminPort" );
2121- basePath = properties .getProperty ("basePath" );
2140+ fast_http_port = properties .getProperty ("marklogic.client.port " );
2141+ admin_port = "8002" ; // No need yet for a property for this
2142+ basePath = properties .getProperty ("marklogic.client. basePath" );
21222143
21232144 // Machine names where ML Server runs
2124- host_name = properties .getProperty ("restHost " );
2145+ host_name = properties .getProperty ("marklogic.client.host " );
21252146 ssl_host_name = properties .getProperty ("restSSLHost" );
21262147
21272148 // Users
@@ -2136,9 +2157,11 @@ public static void loadGradleProperties() {
21362157 ml_certificate_password = properties .getProperty ("ml_certificate_password" );
21372158 ml_certificate_file = properties .getProperty ("ml_certificate_file" );
21382159 mlDataConfigDirPath = properties .getProperty ("mlDataConfigDirPath" );
2139- isLBHost = Boolean . parseBoolean (properties .getProperty ("lbHost " ));
2160+ isLBHost = "gateway" . equalsIgnoreCase (properties .getProperty ("marklogic.client.connectionType " ));
21402161 PROPERTY_WAIT = Integer .parseInt (isLBHost ? "15000" : "0" );
21412162
2163+ testProperties = properties ;
2164+
21422165 System .out .println ("For 'slow' tests, will connect to: " + host_name + ":" + http_port + "; basePath: " + basePath +
21432166 "; auth: " + securityContextType );
21442167 System .out .println ("For 'fast' tests, will connect to: " + host_name + ":" + fast_http_port + "; basePath: " + basePath +
0 commit comments