Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 3ddf61e

Browse files
committed
Incremental deploy now works across commands
1 parent 4cd3568 commit 3ddf61e

File tree

5 files changed

+91
-36
lines changed

5 files changed

+91
-36
lines changed

src/main/java/com/marklogic/appdeployer/command/ResourceFileManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public ResourceFileManagerImpl(String propertiesFilePath) {
3636
*/
3737
@Override
3838
public boolean shouldResourceFileBeProcessed(File file) {
39+
// Need to initialize this on every check because the properties file may have been updated by
40+
// some other command
41+
this.initialize();
3942
boolean shouldBeProcessed = hasFileBeenModifiedSinceLastLoaded(file);
4043
if (shouldBeProcessed) {
4144
if (logger.isDebugEnabled()) {

src/main/java/com/marklogic/appdeployer/command/ResourceFilenameFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ protected boolean filenameHasSupportedExtension(String filename) {
119119
protected boolean acceptFileBasedOnIncrementalCheck(File dir, String filename) {
120120
File resourceFile = new File(dir, filename);
121121
if (filesToIgnoreIncrementalCheck.contains(resourceFile)) {
122-
if (logger.isInfoEnabled()) {
123-
logger.info("Ignoring incremental check for file: " + resourceFile.getAbsolutePath());
122+
if (logger.isDebugEnabled()) {
123+
logger.debug("Ignoring incremental check for file: " + resourceFile.getAbsolutePath());
124124
}
125125
return true;
126126
} else {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.marklogic.appdeployer.command;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.mgmt.ManageClient;
5+
import org.junit.Before;
6+
7+
public abstract class AbstractIncrementalDeployTest extends AbstractAppDeployerTest {
8+
9+
protected ManageClient originalManageClient;
10+
11+
@Before
12+
public void setupIncrementalDeployTest() {
13+
appConfig.setIncrementalDeploy(true);
14+
this.originalManageClient = this.manageClient;
15+
deleteResourceTimestampsFile();
16+
}
17+
18+
public void deleteResourceTimestampsFile() {
19+
new ResourceFileManagerImpl().deletePropertiesFile();
20+
}
21+
}

src/test/java/com/marklogic/appdeployer/command/security/IncrementallyDeployRolesTest.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
package com.marklogic.appdeployer.command.security;
22

3-
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4-
import com.marklogic.appdeployer.command.ResourceFileManagerImpl;
5-
import com.marklogic.appdeployer.command.ResourceFilenameFilter;
6-
import com.marklogic.mgmt.ManageClient;
3+
import com.marklogic.appdeployer.command.AbstractIncrementalDeployTest;
74
import com.marklogic.mgmt.resource.security.RoleManager;
85
import org.junit.After;
96
import org.junit.Before;
107
import org.junit.Test;
118

129
import java.io.File;
1310

14-
public class IncrementallyDeployRolesTest extends AbstractAppDeployerTest {
11+
public class IncrementallyDeployRolesTest extends AbstractIncrementalDeployTest {
1512

1613
private final static String ROLE_INSTALL = "sampleapp-install";
1714
private final static String ROLE_MODULES = "sampleapp-modules";
1815

1916
private RoleManager roleManager;
20-
private DeployRolesCommand deployRolesCommand;
21-
private ManageClient originalManageClient;
2217

2318
@Before
2419
public void setup() {
25-
appConfig.setIncrementalDeploy(true);
2620
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/roles-with-permissions"));
27-
2821
roleManager = new RoleManager(manageClient);
2922
assertRolesDontExist();
30-
31-
originalManageClient = this.manageClient;
32-
deployRolesCommand = new DeployRolesCommand();
3323
}
3424

3525
@After
@@ -42,7 +32,7 @@ public void teardown() {
4232

4333
@Test
4434
public void filesShouldNotBeDeployedDuringSecondDeployment() {
45-
initializeAppDeployer(deployRolesCommand);
35+
initializeAppDeployer(new DeployRolesCommand());
4636
deleteResourceTimestampsFile();
4737
deploySampleApp();
4838
assertRolesExist();
@@ -57,7 +47,7 @@ public void filesShouldNotBeDeployedDuringSecondDeployment() {
5747

5848
@Test
5949
public void filesShouldBeDeployedDuringSecondDeployment() {
60-
initializeAppDeployer(deployRolesCommand);
50+
initializeAppDeployer(new DeployRolesCommand());
6151
deleteResourceTimestampsFile();
6252
deploySampleApp();
6353
assertRolesExist();
@@ -75,15 +65,6 @@ public void filesShouldBeDeployedDuringSecondDeployment() {
7565
}
7666
}
7767

78-
/**
79-
* The properties file may exist from a previous run of the test, so this is used to delete it.
80-
*/
81-
private void deleteResourceTimestampsFile() {
82-
ResourceFilenameFilter filter = (ResourceFilenameFilter) deployRolesCommand.getResourceFilenameFilter();
83-
ResourceFileManagerImpl manager = (ResourceFileManagerImpl) filter.getResourceFileManager();
84-
manager.deletePropertiesFile();
85-
}
86-
8768
private void assertRolesExist() {
8869
assertTrue(roleManager.exists(ROLE_INSTALL));
8970
assertTrue(roleManager.exists(ROLE_MODULES));
Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,96 @@
11
package com.marklogic.appdeployer.command.security;
22

3-
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4-
import com.marklogic.mgmt.ManageClient;
3+
import com.marklogic.appdeployer.command.AbstractIncrementalDeployTest;
4+
import com.marklogic.appdeployer.command.ResourceFileManagerImpl;
5+
import com.marklogic.mgmt.resource.security.RoleManager;
56
import com.marklogic.mgmt.resource.security.UserManager;
67
import org.junit.After;
8+
import org.junit.Before;
79
import org.junit.Test;
810

9-
public class IncrementallyDeployUsersTest extends AbstractAppDeployerTest {
11+
import java.io.FileReader;
12+
import java.io.IOException;
13+
import java.util.Properties;
1014

11-
private ManageClient originalManageClient;
15+
public class IncrementallyDeployUsersTest extends AbstractIncrementalDeployTest {
16+
17+
private UserManager userManager;
18+
private RoleManager roleManager;
19+
20+
@Before
21+
public void setup() {
22+
userManager = new UserManager(manageClient);
23+
roleManager = new RoleManager(manageClient);
24+
}
1225

1326
@After
1427
public void teardown() {
1528
this.manageClient = originalManageClient;
29+
initializeAppDeployer(new DeployUsersCommand(), new DeployRolesCommand());
1630
undeploySampleApp();
17-
assertUsersDontExist(new UserManager(manageClient));
31+
assertUsersDontExist();
32+
assertRolesDontExist();
1833
}
1934

2035
@Test
2136
public void test() {
2237
this.originalManageClient = this.manageClient;
23-
UserManager userManager = new UserManager(manageClient);
24-
assertUsersDontExist(userManager);
38+
assertUsersDontExist();
2539

2640
initializeAppDeployer(new DeployUsersCommand());
2741
deploySampleApp();
28-
assertUsersExist(userManager);
42+
assertUsersExist();
2943

3044
// Ensure that no calls can be made to the Manage API. The deployment should succeed because neither of
3145
// the role files have been modified.
3246
this.manageClient = null;
47+
initializeAppDeployer(new DeployUsersCommand());
3348
deploySampleApp();
34-
assertUsersExist(userManager);
49+
assertUsersExist();
3550
}
3651

37-
private void assertUsersExist(UserManager userManager) {
52+
@Test
53+
public void usersAndRoles() throws IOException {
54+
this.originalManageClient = this.manageClient;
55+
56+
assertUsersDontExist();
57+
assertRolesDontExist();
58+
59+
initializeAppDeployer(new DeployUsersCommand(), new DeployRolesCommand());
60+
deploySampleApp();
61+
assertUsersExist();
62+
assertRolesExist();
63+
64+
this.manageClient = null;
65+
initializeAppDeployer(new DeployUsersCommand(), new DeployRolesCommand());
66+
deploySampleApp();
67+
assertUsersExist();
68+
assertRolesExist();
69+
70+
Properties props = new Properties();
71+
FileReader reader = new FileReader(ResourceFileManagerImpl.DEFAULT_FILE_PATH);
72+
props.load(reader);
73+
reader.close();
74+
assertEquals("There should be 2 entries for users and 2 entries for roles", 4, props.size());
75+
}
76+
77+
private void assertUsersExist() {
3878
assertTrue(userManager.exists("sample-app-jane"));
3979
assertTrue(userManager.exists("sample-app-john"));
4080
}
4181

42-
private void assertUsersDontExist(UserManager userManager) {
82+
private void assertUsersDontExist() {
4383
assertFalse(userManager.exists("sample-app-jane"));
4484
assertFalse(userManager.exists("sample-app-john"));
4585
}
86+
87+
private void assertRolesExist() {
88+
assertTrue(roleManager.exists("sample-app-role1"));
89+
assertTrue(roleManager.exists("sample-app-role2"));
90+
}
91+
92+
private void assertRolesDontExist() {
93+
assertFalse(roleManager.exists("sample-app-role1"));
94+
assertFalse(roleManager.exists("sample-app-role2"));
95+
}
4696
}

0 commit comments

Comments
 (0)