55import com .marklogic .hub .impl .HubConfigImpl ;
66import com .marklogic .mgmt .ManageConfig ;
77import com .marklogic .mgmt .util .PropertySource ;
8- import org .junit .jupiter .api .BeforeEach ;
98import org .junit .jupiter .api .Test ;
109import org .springframework .core .env .PropertiesPropertySource ;
1110import org .springframework .core .io .ClassPathResource ;
1211import org .springframework .mock .env .MockEnvironment ;
1312
13+ import java .io .IOException ;
1414import java .util .Properties ;
1515
1616import static org .junit .jupiter .api .Assertions .*;
@@ -20,44 +20,68 @@ public class HubCentralTest {
2020 HubCentral hubCentral ;
2121 MockEnvironment mockEnvironment ;
2222
23- @ BeforeEach
24- void beforeEach () throws Exception {
25- Properties defaultProps = new Properties ();
26- defaultProps .load (new ClassPathResource ("application.properties" ).getInputStream ());
27- mockEnvironment = new MockEnvironment ();
28- mockEnvironment .getPropertySources ().addFirst (new PropertiesPropertySource ("default" , defaultProps ));
29-
30- hubCentral = new HubCentral ();
31- hubCentral .environment = mockEnvironment ;
23+ @ Test
24+ void testNewDefaultHubConfig () throws IOException {
25+ setupEnvironment ("application.properties" );
26+ verifyDefaultPropertiesForSslAndAuthentication ();
27+ newDefaultHubConfig ();
3228 }
3329
3430 @ Test
35- void verifyDefaultPropertiesForSslAndAuthentication () {
36- PropertySource props = hubCentral .buildPropertySource ("anyone" , "anyword" );
37- assertEquals ("anyone" , props .getProperty ("mlUsername" ));
38- assertEquals ("anyword" , props .getProperty ("mlPassword" ));
39- assertEquals ("localhost" , props .getProperty ("mlHost" ),
40- "For convenience while doing local development, mlHost still defaults to localhost" );
41- assertEquals ("true" , props .getProperty ("hubDhs" ));
42- assertEquals ("true" , props .getProperty ("hubSsl" ));
31+ void testNewHubConfigForDhsOnAWS () throws IOException {
32+ setupEnvironment ("application-aws.properties" );
33+ verifyPropertiesForSslAndAuthenticationOnDhs ();
34+ newHubConfigForDhs ();
4335 }
4436
45- /**
46- * This is essentially tested via every HC test as well, which is using local defaults.
47- */
4837 @ Test
49- void verifyLocalDefaults () {
50- hubCentral .useLocalDefaults = true ;
51- PropertySource props = hubCentral .buildPropertySource ("anyone" , "anyword" );
52- assertEquals ("anyone" , props .getProperty ("mlUsername" ));
53- assertEquals ("anyword" , props .getProperty ("mlPassword" ));
54- assertEquals ("localhost" , props .getProperty ("mlHost" ));
55- assertEquals ("false" , props .getProperty ("hubDhs" ));
56- assertEquals ("false" , props .getProperty ("hubSsl" ));
38+ void testNewHubConfigForDhsOnAzure () throws IOException {
39+ setupEnvironment ("application-azure.properties" );
40+ verifyPropertiesForSslAndAuthenticationOnDhs ();
41+ newHubConfigForDhs ();
5742 }
5843
59- @ Test
60- void newHubConfig () {
44+ void newDefaultHubConfig () {
45+ Properties customProps = new Properties ();
46+ customProps .setProperty ("mlHost" , "somehost" );
47+ mockEnvironment .getPropertySources ().addFirst (new PropertiesPropertySource ("custom" , customProps ));
48+
49+ HubConfigImpl hubConfig = hubCentral .newHubConfig ("anyone" , "anyword" );
50+
51+ assertEquals ("somehost" , hubConfig .getAppConfig ().getHost ());
52+ assertEquals ((Integer ) 8000 , hubConfig .getAppConfig ().getAppServicesPort ());
53+ assertEquals ("anyone" , hubConfig .getAppConfig ().getAppServicesUsername (),
54+ "The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version" );
55+ assertEquals ("anyword" , hubConfig .getAppConfig ().getAppServicesPassword ());
56+ assertEquals (SecurityContextType .DIGEST , hubConfig .getAppConfig ().getAppServicesSecurityContextType ());
57+ assertNull (hubConfig .getAppConfig ().getAppServicesSslContext ());
58+
59+ assertEquals ("somehost" , hubConfig .getHost ());
60+ assertEquals ("anyone" , hubConfig .getMlUsername ());
61+ assertEquals ("anyword" , hubConfig .getMlPassword ());
62+
63+ assertEquals ("digest" , hubConfig .getAuthMethod (DatabaseKind .STAGING ));
64+ assertEquals ("digest" , hubConfig .getAuthMethod (DatabaseKind .FINAL ));
65+ assertEquals ("digest" , hubConfig .getAuthMethod (DatabaseKind .JOB ));
66+
67+ assertNull (hubConfig .getSslContext (DatabaseKind .STAGING ));
68+ assertNull (hubConfig .getSslContext (DatabaseKind .FINAL ));
69+ assertNull (hubConfig .getSslContext (DatabaseKind .JOB ));
70+
71+ assertFalse (hubConfig .getIsHostLoadBalancer ());
72+ assertFalse (hubConfig .getIsProvisionedEnvironment ());
73+
74+ ManageConfig manageConfig = hubConfig .getManageConfig ();
75+ assertEquals ("anyone" , manageConfig .getUsername ());
76+ assertEquals ("anyone" , manageConfig .getSecurityUsername ());
77+ assertEquals ("somehost" , manageConfig .getHost ());
78+ assertEquals ("anyword" , manageConfig .getPassword ());
79+ assertEquals ("anyword" , manageConfig .getSecurityPassword ());
80+ assertFalse (manageConfig .isConfigureSimpleSsl ());
81+ assertEquals ("http" , manageConfig .getScheme ());
82+ }
83+
84+ void newHubConfigForDhs () {
6185 Properties customProps = new Properties ();
6286 customProps .setProperty ("mlHost" , "somehost" );
6387 mockEnvironment .getPropertySources ().addFirst (new PropertiesPropertySource ("custom" , customProps ));
@@ -66,9 +90,9 @@ void newHubConfig() {
6690
6791 assertEquals ("somehost" , hubConfig .getAppConfig ().getHost ());
6892 assertEquals ((Integer ) 8010 , hubConfig .getAppConfig ().getAppServicesPort (),
69- "8010 is needed by DHS, as 8000 is locked down; this should be defined in application.properties" );
93+ "8010 is needed by DHS, as 8000 is locked down; this should be defined in application.properties" );
7094 assertEquals ("anyone" , hubConfig .getAppConfig ().getAppServicesUsername (),
71- "The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version" );
95+ "The Versions class used appConfig.getAppServicesDatabaseClient to get the ML version" );
7296 assertEquals ("anyword" , hubConfig .getAppConfig ().getAppServicesPassword ());
7397 assertEquals (SecurityContextType .BASIC , hubConfig .getAppConfig ().getAppServicesSecurityContextType ());
7498 assertNotNull (hubConfig .getAppConfig ().getAppServicesSslContext ());
@@ -97,4 +121,31 @@ void newHubConfig() {
97121 assertTrue (manageConfig .isConfigureSimpleSsl ());
98122 assertEquals ("https" , manageConfig .getScheme ());
99123 }
124+
125+ void verifyDefaultPropertiesForSslAndAuthentication () {
126+ PropertySource props = hubCentral .buildPropertySource ("anyone" , "anyword" );
127+ assertEquals ("anyone" , props .getProperty ("mlUsername" ));
128+ assertEquals ("anyword" , props .getProperty ("mlPassword" ));
129+ assertEquals ("localhost" , props .getProperty ("mlHost" ),
130+ "For convenience while doing local development, mlHost still defaults to localhost" );
131+ assertNull (props .getProperty ("hubDhs" ));
132+ assertNull (props .getProperty ("hubSsl" ));
133+ }
134+
135+ void verifyPropertiesForSslAndAuthenticationOnDhs () {
136+ PropertySource props = hubCentral .buildPropertySource ("anyone" , "anyword" );
137+ assertEquals ("anyone" , props .getProperty ("mlUsername" ));
138+ assertEquals ("anyword" , props .getProperty ("mlPassword" ));
139+ assertEquals ("true" , props .getProperty ("hubDhs" ));
140+ }
141+
142+ private void setupEnvironment (String propertyFileName ) throws IOException {
143+ Properties defaultProps = new Properties ();
144+ defaultProps .load (new ClassPathResource (propertyFileName ).getInputStream ());
145+ mockEnvironment = new MockEnvironment ();
146+ mockEnvironment .getPropertySources ().addFirst (new PropertiesPropertySource ("default" , defaultProps ));
147+
148+ hubCentral = new HubCentral ();
149+ hubCentral .environment = mockEnvironment ;
150+ }
100151}
0 commit comments