1212
1313import java .io .File ;
1414
15- import java .io .File ;
16-
1715public class LoadModulesTest extends AbstractAppDeployerTest {
1816
1917 private XccTemplate xccTemplate ;
@@ -86,50 +84,43 @@ public void loadModulesFromMultiplePaths() {
8684
8785 @ Test
8886 public void loadModulesWithCustomPermissions () {
89- appConfig .setModulePermissions (appConfig .getModulePermissions () + ",app-user,execute" );
87+ appConfig .setModulePermissions (appConfig .getModulePermissions () + ",app-user,execute" );
9088
9189 initializeAppDeployer (new DeployRestApiServersCommand (true ), buildLoadModulesCommand ());
9290
9391 appDeployer .deploy (appConfig );
9492
95- PermissionsFragment perms = getDocumentPermissions ("/ext/sample-lib.xqy" , xccTemplate );
96- perms .assertPermissionCount (6 );
93+ PermissionsFragment perms = getDocumentPermissions ("/ext/sample-lib.xqy" , xccTemplate );
94+ perms .assertPermissionCount (6 );
9795
98- // Default permissions set by AppConfig
99- perms .assertPermissionExists ("rest-admin" , "read" );
100- perms .assertPermissionExists ("rest-admin" , "update" );
101- perms .assertPermissionExists ("rest-extension-user" , "execute" );
96+ // Default permissions set by AppConfig
97+ perms .assertPermissionExists ("rest-admin" , "read" );
98+ perms .assertPermissionExists ("rest-admin" , "update" );
99+ perms .assertPermissionExists ("rest-extension-user" , "execute" );
102100
103- // Custom permission
104- perms .assertPermissionExists ("app-user" , "execute" );
101+ // Custom permission
102+ perms .assertPermissionExists ("app-user" , "execute" );
105103
106- // Permissions that the REST API still applies, which seems like a bug
104+ // Permissions that the REST API still applies, which seems like a bug
107105 perms .assertPermissionExists ("rest-reader" , "read" );
108106 perms .assertPermissionExists ("rest-writer" , "update" );
109- }
110-
111- @ Test
112- public void deleteTestModules () {
113- appConfig .setDeleteTestModules (true );
114- appConfig .setDeleteTestModulesPattern ("/ext/lib/*.xqy" );
115-
116- initializeAppDeployer (new DeployRestApiServersCommand (true ), buildLoadModulesCommand (),
117- new DeleteTestModulesCommand ());
118- appDeployer .deploy (appConfig );
119-
120- String xquery = "fn:count(cts:uri-match('/ext/**.xqy'))" ;
121- assertEquals (1 , Integer .parseInt (xccTemplate .executeAdhocQuery (xquery )));
122107 }
123108
124109 @ Test
125110 public void loadModulesWithAssetFileFilterAndTokenReplacement () {
126111 appConfig .setAssetFileFilter (new TestFileFilter ());
127112
128- String xml = xccTemplate .executeAdhocQuery ("doc('/ext/lib/test.xqy')" );
129- Fragment f = parse (xml );
130- f .assertElementValue ("/test/color" , "red" );
131- f .assertElementValue ("/test/description" , "red description" );
132- }
113+ /**
114+ * Add a couple tokens to replace in the modules. It's still a good practice to ensure these tokens don't
115+ * hit on anything accidentally, so their names are capitalized. But since the module token replacement
116+ * follows the Roxy convention by default and prefixes properties with "@ml.", our modules then need
117+ * "@ml.%%COLOR%%", for example.
118+ */
119+ appConfig .getCustomTokens ().put ("COLOR" , "red" );
120+ appConfig .getCustomTokens ().put ("DESCRIPTION" , "${COLOR} description" );
121+
122+ initializeAppDeployer (new DeployRestApiServersCommand (true ), buildLoadModulesCommand ());
123+ appDeployer .deploy (appConfig );
133124
134125 assertEquals ("true" , xccTemplate .executeAdhocQuery ("doc-available('/ext/lib/test.xqy')" ));
135126 assertEquals ("false" , xccTemplate .executeAdhocQuery ("doc-available('/ext/lib/test2.xqy')" ));
@@ -138,7 +129,21 @@ public void loadModulesWithAssetFileFilterAndTokenReplacement() {
138129 Fragment f = parse (xml );
139130 f .assertElementValue ("/test/color" , "red" );
140131 f .assertElementValue ("/test/description" , "red description" );
132+ }
141133
134+ @ Test
135+ public void testServerExists () {
136+ appConfig .getConfigDir ().setBaseDir (new File (("src/test/resources/sample-app/db-only-config" )));
137+ appConfig .setTestRestPort (8541 );
138+ initializeAppDeployer (new DeployRestApiServersCommand (true ), buildLoadModulesCommand ());
139+
140+ appDeployer .deploy (appConfig );
141+
142+ String [] uris = new String [] { "/Default/sample-app/rest-api/options/sample-app-options.xml" ,
143+ "/Default/sample-app/rest-api/options/sample-app-options.xml" };
144+ for (String uri : uris ) {
145+ assertEquals ("true" , xccTemplate .executeAdhocQuery (format ("doc-available('%s')" , uri )));
146+ }
142147 }
143148
144149 @ Test
0 commit comments