Skip to content

Commit

Permalink
Fix test interdependencies in gs-gwc
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed Oct 25, 2018
1 parent 0a05b85 commit 2a27cec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/gwc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-platform</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
28 changes: 14 additions & 14 deletions src/gwc/src/test/java/org/geoserver/gwc/GWCIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.utils.DateUtils;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLUnit;
Expand Down Expand Up @@ -1293,16 +1292,18 @@ public void testDiskQuotaStorage() throws Exception {
quota.setQuotaStore("H2");
gwc.saveDiskQuotaConfig(quota, null);
GeoServerDataDirectory dd = GeoServerExtensions.bean(GeoServerDataDirectory.class);
File jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
assertNull("jdbc config should not be there", jdbcConfigFile);
File h2DefaultStore = dd.findFile("gwc/diskquota_page_store_h2");
assertNotNull("jdbc store should be there", h2DefaultStore);
String jdbcConfigPath = "gwc/geowebcache-diskquota-jdbc.xml";
assertNull(
"jdbc config (" + jdbcConfigPath + ") should not be there",
dd.findFile(jdbcConfigPath));
String h2StorePath = "gwc/diskquota_page_store_h2";
assertNotNull("jdbc store (" + h2StorePath + ") should be there", dd.findFile(h2StorePath));
assertTrue(getActualStore(provider) instanceof JDBCQuotaStore);

// disable again and clean up
quota.setEnabled(false);
gwc.saveDiskQuotaConfig(quota, null);
FileUtils.deleteDirectory(h2DefaultStore);
FileUtils.deleteDirectory(dd.findFile("gwc/diskquota_page_store_h2"));

// now enable it in JDBC mode, with H2 local storage
quota.setEnabled(true);
Expand All @@ -1319,24 +1320,23 @@ public void testDiskQuotaStorage() throws Exception {
pool.setMaxOpenPreparedStatements(50);
jdbc.setConnectionPool(pool);
gwc.saveDiskQuotaConfig(quota, jdbc);
jdbcConfigFile = dd.findFile("gwc/geowebcache-diskquota-jdbc.xml");
assertNotNull("jdbc config should be there", jdbcConfigFile);
assertNull("jdbc store should be there", dd.findDataFile("gwc/diskquota_page_store_h2"));
assertNotNull(
"jdbc config (" + jdbcConfigPath + ") should be there",
dd.findFile(jdbcConfigPath));
assertNull(
"jdbc store (" + h2StorePath + ") should be there", dd.findDataFile(h2StorePath));
File newQuotaStore = new File("./target/quota-h2.data.db");
assertTrue(newQuotaStore.exists());

FileInputStream fis = null;
try {
fis = new FileInputStream(jdbcConfigFile);
File jdbcConfigFile = dd.findFile(jdbcConfigPath);
try (FileInputStream fis = new FileInputStream(jdbcConfigFile)) {
Document dom = dom(fis);
// print(dom);
String storedPassword =
XMLUnit.newXpathEngine()
.evaluate("/gwcJdbcConfiguration/connectionPool/password", dom);
// check the password has been encoded properly
assertTrue(storedPassword.startsWith("crypt1:"));
} finally {
IOUtils.closeQuietly(fis);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.io.File;
import org.geoserver.test.GeoServerSystemTestSupport;
import org.geoserver.util.IOUtils;
import org.geoserver.util.PropertyRule;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;

/**
Expand All @@ -20,6 +22,14 @@
*/
public final class GWCExternalConfigTest extends GeoServerSystemTestSupport {

@Rule
public PropertyRule configProp =
PropertyRule.system(GeoserverXMLResourceProvider.GEOWEBCACHE_CONFIG_DIR_PROPERTY);

@Rule
public PropertyRule cacheProp =
PropertyRule.system(GeoserverXMLResourceProvider.GEOWEBCACHE_CACHE_DIR_PROPERTY);

private static final File rootTempDirectory;

private static final String tempDirectory1;
Expand Down Expand Up @@ -55,17 +65,15 @@ private void testUseCase(
String configDirPath, String cacheDirPath, String expectedConfigFirPath) {
// set or clear the gwc configuration directory property
if (configDirPath == null) {
System.clearProperty(GeoserverXMLResourceProvider.GEOWEBCACHE_CONFIG_DIR_PROPERTY);
configProp.clearValue();
} else {
System.setProperty(
GeoserverXMLResourceProvider.GEOWEBCACHE_CONFIG_DIR_PROPERTY, configDirPath);
configProp.setValue(configDirPath);
}
// set or clear the gwc cache directory property
if (cacheDirPath == null) {
System.clearProperty(GeoserverXMLResourceProvider.GEOWEBCACHE_CACHE_DIR_PROPERTY);
cacheProp.clearValue();
} else {
System.setProperty(
GeoserverXMLResourceProvider.GEOWEBCACHE_CACHE_DIR_PROPERTY, cacheDirPath);
cacheProp.setValue(cacheDirPath);
}
// rebuild the spring beans
applicationContext.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public void setValue(String value) {
props.setProperty(name, value);
}

public void clearValue() {
props.remove(name);
}

public String getName() {
return name;
}
Expand Down

0 comments on commit 2a27cec

Please sign in to comment.