|
23 | 23 | import com.marklogic.appdeployer.command.modules.LoadModulesCommand;
|
24 | 24 | import com.marklogic.appdeployer.command.security.GenerateTemporaryCertificateCommand;
|
25 | 25 | import com.marklogic.appdeployer.impl.SimpleAppDeployer;
|
| 26 | +import com.marklogic.client.DatabaseClient; |
| 27 | +import com.marklogic.client.DatabaseClientFactory; |
26 | 28 | import com.marklogic.client.ext.modulesloader.impl.DefaultModulesLoader;
|
27 | 29 | import com.marklogic.mgmt.AbstractMgmtTest;
|
28 | 30 | import com.marklogic.mgmt.resource.appservers.ServerManager;
|
29 |
| -import com.marklogic.xcc.template.XccTemplate; |
30 | 31 | import org.junit.jupiter.api.BeforeEach;
|
31 | 32 |
|
32 | 33 | import java.io.File;
|
|
38 | 39 | */
|
39 | 40 | public abstract class AbstractAppDeployerTest extends AbstractMgmtTest {
|
40 | 41 |
|
41 |
| - public final static String SAMPLE_APP_NAME = "sample-app"; |
| 42 | + public final static String SAMPLE_APP_NAME = "sample-app"; |
42 | 43 |
|
43 |
| - protected final static Integer SAMPLE_APP_REST_PORT = 8004; |
44 |
| - protected final static Integer SAMPLE_APP_TEST_REST_PORT = 8005; |
| 44 | + protected final static Integer SAMPLE_APP_REST_PORT = 8004; |
| 45 | + protected final static Integer SAMPLE_APP_TEST_REST_PORT = 8005; |
45 | 46 |
|
46 |
| - // Intended to be used by subclasses |
47 |
| - protected AppDeployer appDeployer; |
48 |
| - protected AppConfig appConfig; |
| 47 | + // Intended to be used by subclasses |
| 48 | + protected AppDeployer appDeployer; |
| 49 | + protected AppConfig appConfig; |
49 | 50 |
|
50 |
| - @BeforeEach |
51 |
| - public void initialize() { |
52 |
| - initializeAppConfig(); |
53 |
| - } |
| 51 | + @BeforeEach |
| 52 | + public void initialize() { |
| 53 | + initializeAppConfig(); |
| 54 | + } |
54 | 55 |
|
55 |
| - protected void initializeAppConfig() { |
56 |
| - initializeAppConfig(new File("src/test/resources/sample-app")); |
57 |
| - } |
| 56 | + protected void initializeAppConfig() { |
| 57 | + initializeAppConfig(new File("src/test/resources/sample-app")); |
| 58 | + } |
58 | 59 |
|
59 |
| - protected void initializeAppConfig(File projectDir) { |
60 |
| - appConfig = new AppConfig(projectDir); |
| 60 | + protected void initializeAppConfig(File projectDir) { |
| 61 | + appConfig = new AppConfig(projectDir); |
61 | 62 | appConfig.setHost(this.manageConfig.getHost());
|
62 |
| - appConfig.setName(SAMPLE_APP_NAME); |
63 |
| - appConfig.setRestPort(SAMPLE_APP_REST_PORT); |
| 63 | + appConfig.setName(SAMPLE_APP_NAME); |
| 64 | + appConfig.setRestPort(SAMPLE_APP_REST_PORT); |
64 | 65 |
|
65 |
| - // Assume that the manager user can also be used as the REST admin user |
66 |
| - appConfig.setRestAdminUsername(manageConfig.getUsername()); |
67 |
| - appConfig.setRestAdminPassword(manageConfig.getPassword()); |
| 66 | + // Assume that the manager user can also be used as the REST admin user |
| 67 | + appConfig.setRestAdminUsername(manageConfig.getUsername()); |
| 68 | + appConfig.setRestAdminPassword(manageConfig.getPassword()); |
68 | 69 | appConfig.setAppServicesUsername(manageConfig.getUsername());
|
69 | 70 | appConfig.setAppServicesPassword(manageConfig.getPassword());
|
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * Initialize an AppDeployer with the given set of commands. Avoids having to create a Spring configuration. |
74 |
| - * |
75 |
| - * @param commands |
76 |
| - */ |
77 |
| - protected void initializeAppDeployer(Command... commands) { |
78 |
| - appDeployer = new SimpleAppDeployer(manageClient, adminManager, commands); |
79 |
| - } |
80 |
| - |
81 |
| - protected void deploySampleApp() { |
82 |
| - appDeployer.deploy(appConfig); |
83 |
| - } |
84 |
| - |
85 |
| - protected void undeploySampleApp() { |
86 |
| - if (appDeployer != null) { |
87 |
| - try { |
88 |
| - appDeployer.undeploy(appConfig); |
89 |
| - } catch (Exception e) { |
90 |
| - throw new RuntimeException("Unexpected error while undeploying sample app: " + e.getMessage(), e); |
91 |
| - } |
92 |
| - } |
93 |
| - } |
94 |
| - |
95 |
| - protected XccTemplate newModulesXccTemplate() { |
96 |
| - return new XccTemplate(appConfig.getHost(), appConfig.getAppServicesPort(), appConfig.getRestAdminUsername(), |
97 |
| - appConfig.getRestAdminPassword(), appConfig.getModulesDatabaseName()); |
98 |
| - } |
99 |
| - |
100 |
| - /** |
101 |
| - * This command is configured to always load modules, ignoring the cache file in the build directory. |
102 |
| - * @return |
103 |
| - */ |
104 |
| - protected LoadModulesCommand buildLoadModulesCommand() { |
105 |
| - LoadModulesCommand command = new LoadModulesCommand(); |
106 |
| - appConfig.setModuleTimestampsPath(null); |
107 |
| - DefaultModulesLoader loader = (DefaultModulesLoader)(new DefaultModulesLoaderFactory().newModulesLoader(appConfig)); |
108 |
| - loader.setModulesManager(null); |
109 |
| - command.setModulesLoader(loader); |
110 |
| - return command; |
111 |
| - } |
112 |
| - |
113 |
| - protected void setConfigBaseDir(String path) { |
114 |
| - appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/" + path)); |
115 |
| - } |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Initialize an AppDeployer with the given set of commands. Avoids having to create a Spring configuration. |
| 75 | + * |
| 76 | + * @param commands |
| 77 | + */ |
| 78 | + protected void initializeAppDeployer(Command... commands) { |
| 79 | + appDeployer = new SimpleAppDeployer(manageClient, adminManager, commands); |
| 80 | + } |
| 81 | + |
| 82 | + protected void deploySampleApp() { |
| 83 | + appDeployer.deploy(appConfig); |
| 84 | + } |
| 85 | + |
| 86 | + protected void undeploySampleApp() { |
| 87 | + if (appDeployer != null) { |
| 88 | + try { |
| 89 | + appDeployer.undeploy(appConfig); |
| 90 | + } catch (Exception e) { |
| 91 | + throw new RuntimeException("Unexpected error while undeploying sample app: " + e.getMessage(), e); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + protected final DatabaseClient newDatabaseClient(String databaseName) { |
| 97 | + return DatabaseClientFactory.newClient(appConfig.getHost(), appConfig.getRestPort(), |
| 98 | + databaseName, new DatabaseClientFactory.DigestAuthContext(appConfig.getRestAdminUsername(), appConfig.getRestAdminPassword())); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * This command is configured to always load modules, ignoring the cache file in the build directory. |
| 103 | + * |
| 104 | + * @return |
| 105 | + */ |
| 106 | + protected LoadModulesCommand buildLoadModulesCommand() { |
| 107 | + LoadModulesCommand command = new LoadModulesCommand(); |
| 108 | + appConfig.setModuleTimestampsPath(null); |
| 109 | + DefaultModulesLoader loader = (DefaultModulesLoader) (new DefaultModulesLoaderFactory().newModulesLoader(appConfig)); |
| 110 | + loader.setModulesManager(null); |
| 111 | + command.setModulesLoader(loader); |
| 112 | + return command; |
| 113 | + } |
| 114 | + |
| 115 | + protected void setConfigBaseDir(String path) { |
| 116 | + appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/" + path)); |
| 117 | + } |
116 | 118 |
|
117 | 119 | /**
|
118 | 120 | * Intended to simplify testing app servers that require SSL.
|
|
0 commit comments