44import com .marklogic .client .DatabaseClientFactory ;
55import com .marklogic .client .ext .SecurityContextType ;
66import com .marklogic .client .ext .modulesloader .impl .PropertiesModuleManager ;
7+ import com .marklogic .mgmt .DefaultManageConfigFactory ;
8+ import com .marklogic .mgmt .ManageConfig ;
79import com .marklogic .mgmt .util .SimplePropertySource ;
810import org .junit .jupiter .api .Test ;
911
@@ -566,9 +568,7 @@ public void mlConfigDir() {
566568
567569 @ Test
568570 public void mlUsernameAndPassword () {
569- sut = new DefaultAppConfigFactory (
570- new SimplePropertySource ("mlUsername" , "customuser" , "mlPassword" , "custompassword" ));
571- AppConfig config = sut .newAppConfig ();
571+ AppConfig config = configure ("mlUsername" , "customuser" , "mlPassword" , "custompassword" );
572572
573573 assertEquals ("customuser" , config .getRestAdminUsername (),
574574 "When mlRestAdminUsername is not set, mlUsername should be used" );
@@ -581,8 +581,7 @@ public void mlUsernameAndPassword() {
581581
582582 @ Test
583583 public void dontModifySetOfDatabasesWithForestsOnOneHostIfItsBeenConfigured () {
584- sut = new DefaultAppConfigFactory (new SimplePropertySource ("mlAppName" , "example" , "mlDatabasesWithForestsOnOneHost" , "db1,db2" ));
585- AppConfig config = sut .newAppConfig ();
584+ AppConfig config = configure ("mlAppName" , "example" , "mlDatabasesWithForestsOnOneHost" , "db1,db2" );
586585
587586 Set <String > set = config .getDatabasesWithForestsOnOneHost ();
588587 assertEquals (2 , set .size ());
@@ -596,16 +595,16 @@ public void dontModifySetOfDatabasesWithForestsOnOneHostIfItsBeenConfigured() {
596595
597596 @ Test
598597 public void appServicesSimpleSsl () {
599- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlAppServicesSimpleSsl" , "true" )). newAppConfig ( );
598+ AppConfig config = configure ( "mlAppServicesSimpleSsl" , "true" );
600599 assertEquals ("TLSv1.2" , config .getAppServicesSslContext ().getProtocol ());
601600
602- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlAppServicesSimpleSsl" , "TLSv1.2" )). newAppConfig ( );
601+ config = configure ( "mlAppServicesSimpleSsl" , "TLSv1.2" );
603602 assertEquals ("TLSv1.2" , config .getAppServicesSslContext ().getProtocol ());
604603
605- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlAppServicesSimpleSsl" , "TLSv1.1" )). newAppConfig ( );
604+ config = configure ( "mlAppServicesSimpleSsl" , "TLSv1.1" );
606605 assertEquals ("TLSv1.1" , config .getAppServicesSslContext ().getProtocol ());
607606
608- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlAppServicesSimpleSsl" , "false" )). newAppConfig ( );
607+ config = configure ( "mlAppServicesSimpleSsl" , "false" );
609608 assertNull (config .getAppServicesSslContext ());
610609
611610 config = new DefaultAppConfigFactory (new SimplePropertySource ()).newAppConfig ();
@@ -614,16 +613,16 @@ public void appServicesSimpleSsl() {
614613
615614 @ Test
616615 public void restSimpleSsl () {
617- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlSimpleSsl" , "true" )). newAppConfig ( );
616+ AppConfig config = configure ( "mlSimpleSsl" , "true" );
618617 assertEquals ("TLSv1.2" , config .getRestSslContext ().getProtocol ());
619618
620- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlSimpleSsl" , "TLSv1.2" )). newAppConfig ( );
619+ config = configure ( "mlSimpleSsl" , "TLSv1.2" );
621620 assertEquals ("TLSv1.2" , config .getRestSslContext ().getProtocol ());
622621
623- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlSimpleSsl" , "TLSv1.1" )). newAppConfig ( );
622+ config = configure ( "mlSimpleSsl" , "TLSv1.1" );
624623 assertEquals ("TLSv1.1" , config .getRestSslContext ().getProtocol ());
625624
626- config = new DefaultAppConfigFactory ( new SimplePropertySource ( "mlSimpleSsl" , "false" )). newAppConfig ( );
625+ config = configure ( "mlSimpleSsl" , "false" );
627626 assertNull (config .getRestSslContext ());
628627
629628 config = new DefaultAppConfigFactory (new SimplePropertySource ()).newAppConfig ();
@@ -632,11 +631,11 @@ public void restSimpleSsl() {
632631
633632 @ Test
634633 public void restUseDefaultKeystore () {
635- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
634+ AppConfig config = configure (
636635 "mlRestUseDefaultKeystore" , "true" ,
637636 "mlRestSslProtocol" , "SSLv3" ,
638637 "mlRestTrustManagementAlgorithm" , "PKIX"
639- )). newAppConfig () ;
638+ );
640639
641640 assertTrue (config .isRestUseDefaultKeystore ());
642641 assertEquals ("SSLv3" , config .getRestSslProtocol ());
@@ -645,11 +644,11 @@ public void restUseDefaultKeystore() {
645644
646645 @ Test
647646 public void appServicesUseDefaultKeystore () {
648- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
647+ AppConfig config = configure (
649648 "mlAppServicesUseDefaultKeystore" , "true" ,
650649 "mlAppServicesSslProtocol" , "SSLv3" ,
651650 "mlAppServicesTrustManagementAlgorithm" , "PKIX"
652- )). newAppConfig () ;
651+ );
653652
654653 assertTrue (config .isAppServicesUseDefaultKeystore ());
655654 assertEquals ("SSLv3" , config .getAppServicesSslProtocol ());
@@ -658,12 +657,12 @@ public void appServicesUseDefaultKeystore() {
658657
659658 @ Test
660659 void cloudApiKeyAndBasePath () {
661- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
660+ AppConfig config = configure (
662661 "mlCloudApiKey" , "my-key" ,
663662 "mlRestBasePath" , "/rest/path" ,
664663 "mlAppServicesBasePath" , "/app/path" ,
665664 "mlTestRestBasePath" , "/test/path"
666- )). newAppConfig () ;
665+ );
667666
668667 assertEquals ("my-key" , config .getCloudApiKey ());
669668 assertEquals ("/rest/path" , config .getRestBasePath ());
@@ -673,10 +672,10 @@ void cloudApiKeyAndBasePath() {
673672
674673 @ Test
675674 void sslHostnameVerifier () {
676- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
675+ AppConfig config = configure (
677676 "mlRestSslHostnameVerifier" , "any" ,
678677 "mlAppServicesSslHostnameVerifier" , "COMmon"
679- )). newAppConfig () ;
678+ );
680679
681680 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .ANY , config .getRestSslHostnameVerifier ());
682681 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .COMMON , config .getAppServicesSslHostnameVerifier ());
@@ -698,38 +697,38 @@ void sslHostnameVerifier() {
698697
699698 @ Test
700699 void mlSslHostnameVerifier () {
701- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
700+ AppConfig config = configure (
702701 "mlSslHostnameVerifier" , "ANY"
703- )). newAppConfig () ;
702+ );
704703
705704 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .ANY , config .getRestSslHostnameVerifier ());
706705 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .ANY , config .getAppServicesSslHostnameVerifier ());
707706
708- config = new DefaultAppConfigFactory ( new SimplePropertySource (
707+ config = configure (
709708 "mlSslHostnameVerifier" , "ANY" ,
710709 "mlRestSslHostnameVerifier" , "STRICT"
711- )). newAppConfig () ;
710+ );
712711
713712 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .STRICT , config .getRestSslHostnameVerifier ());
714713 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .ANY , config .getAppServicesSslHostnameVerifier ());
715714
716- config = new DefaultAppConfigFactory ( new SimplePropertySource (
715+ config = configure (
717716 "mlSslHostnameVerifier" , "ANY" ,
718717 "mlAppServicesSslHostnameVerifier" , "STRICT"
719- )). newAppConfig () ;
718+ );
720719
721720 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .ANY , config .getRestSslHostnameVerifier ());
722721 assertEquals (DatabaseClientFactory .SSLHostnameVerifier .STRICT , config .getAppServicesSslHostnameVerifier ());
723722 }
724723
725724 @ Test
726725 void samlTokens () {
727- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
726+ AppConfig config = configure (
728727 "mlRestAuthentication" , "saml" ,
729728 "mlRestSamlToken" , "my-rest-token" ,
730729 "mlAppServicesAuthentication" , "saml" ,
731730 "mlAppServicesSamlToken" , "my-app-token"
732- )). newAppConfig () ;
731+ );
733732
734733 assertEquals (SecurityContextType .SAML , config .getRestSecurityContextType ());
735734 assertEquals ("my-rest-token" , config .getRestSamlToken ());
@@ -749,33 +748,89 @@ void samlTokens() {
749748
750749 @ Test
751750 void mlAuthentication () {
752- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
751+ AppConfig config = configure (
753752 "mlAuthentication" , "cloud"
754- )). newAppConfig () ;
753+ );
755754
756755 assertEquals (SecurityContextType .CLOUD , config .getRestSecurityContextType ());
757756 assertEquals (SecurityContextType .CLOUD , config .getAppServicesSecurityContextType ());
758757 }
759758
760759 @ Test
761760 void mlAuthenticationAndRestOverridden () {
762- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
761+ AppConfig config = configure (
763762 "mlAuthentication" , "cloud" ,
764763 "mlRestAuthentication" , "basic"
765- )). newAppConfig () ;
764+ );
766765
767766 assertEquals (SecurityContextType .BASIC , config .getRestSecurityContextType ());
768767 assertEquals (SecurityContextType .CLOUD , config .getAppServicesSecurityContextType ());
769768 }
770769
771770 @ Test
772771 void mlAuthenticationAndAppServicesOverridden () {
773- AppConfig config = new DefaultAppConfigFactory ( new SimplePropertySource (
772+ AppConfig config = configure (
774773 "mlAuthentication" , "cloud" ,
775774 "mlAppServicesAuthentication" , "saml"
776- )). newAppConfig () ;
775+ );
777776
778777 assertEquals (SecurityContextType .CLOUD , config .getRestSecurityContextType ());
779778 assertEquals (SecurityContextType .SAML , config .getAppServicesSecurityContextType ());
780779 }
780+
781+ @ Test
782+ void mlAppServicesBasePath () {
783+ AppConfig config = configure (
784+ "mlAppServicesBasePath" , "/my/custom/app-services/path"
785+ );
786+ assertEquals ("/my/custom/app-services/path" , config .getAppServicesBasePath (),
787+ "If a user only specifies mlAppServicesBasePath, then the assumption is that they're using a reverse proxy and " +
788+ "have defined their own custom path for the App-Services app server. They could be using ML Cloud, but " +
789+ "that's not likely as it would make more sense to still define mlCloudBasePath and then set " +
790+ "mlAppServicesBasePath to the custom App-Services part (as a user is not allowed to setup a base path in ML Cloud " +
791+ "that doesn't begin with their common base path)." );
792+ }
793+
794+ @ Test
795+ void mlCloudBasePath () {
796+ AppConfig config = configure (
797+ "mlCloudBasePath" , "/my/domain"
798+ );
799+ assertEquals ("/my/domain/app-services" , config .getAppServicesBasePath (),
800+ "If a user only specifies mlCloudBasePath, then the assumption is that they're good to go with the default " +
801+ "App-Services base path setup in ML Cloud, and so they only need to define the 'cloud base path' that occurs " +
802+ "before '/app-services'" );
803+
804+ String message = "mlCloudBasePath only sets default values for the Admin, Manage, and " +
805+ "App-Services servers; it's up to the user to define the base path for their custom REST server" ;
806+ assertNull (config .getRestBasePath (), message );
807+ assertNull (config .getTestRestBasePath (), message );
808+ }
809+
810+ @ Test
811+ void mlCloudBasePathWithAppServicesBasePath () {
812+ AppConfig config = configure (
813+ "mlCloudBasePath" , "/my/domain" ,
814+ "mlAppServicesBasePath" , "/my-custom-app-services-path"
815+ );
816+ assertEquals ("/my/domain/my-custom-app-services-path" , config .getAppServicesBasePath (),
817+ "If a user specifies both mlCloudBasePath and mlAppServicesBasePath, then the assumption is that they've " +
818+ "changed the default App-Services base path but it still begins with the common base path defined by " +
819+ "mlCloudBasePath." );
820+ }
821+
822+ @ Test
823+ void mlCloudBasePathAndMlRestBasePath () {
824+ AppConfig config = configure (
825+ "mlCloudBasePath" , "/my/domain" ,
826+ "mlRestBasePath" , "/my/rest/server" ,
827+ "mlTestRestBasePath" , "/my/test/server"
828+ );
829+ assertEquals ("/my/domain/my/rest/server" , config .getRestBasePath ());
830+ assertEquals ("/my/domain/my/test/server" , config .getTestRestBasePath ());
831+ }
832+
833+ private AppConfig configure (String ... properties ) {
834+ return new DefaultAppConfigFactory (new SimplePropertySource (properties )).newAppConfig ();
835+ }
781836}
0 commit comments