mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-05 15:02:26 +01:00
Test for ConfigUpdater regressions
This commit is contained in:
parent
d0df3e3fcf
commit
23c32d00b8
@ -0,0 +1,93 @@
|
||||
package com.djrapitops.plan.system.settings.changes;
|
||||
|
||||
import com.djrapitops.plan.system.settings.ConfigSettingKeyTest;
|
||||
import com.djrapitops.plan.system.settings.config.ConfigReader;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.platform.runner.JUnitPlatform;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import utilities.TestResources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
@RunWith(JUnitPlatform.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class ConfigUpdaterTest {
|
||||
|
||||
private static Path tempDir;
|
||||
|
||||
private static File oldConfig;
|
||||
private static File oldBungeeConfig;
|
||||
|
||||
private static Path newConfig;
|
||||
private static Path newBungeeConfig;
|
||||
|
||||
private static ConfigUpdater UNDER_TEST;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareConfigFiles(@TempDirectory.TempDir Path temporaryDir) throws URISyntaxException, IOException {
|
||||
tempDir = temporaryDir;
|
||||
|
||||
oldConfig = tempDir.resolve("config.yml").toFile();
|
||||
File configResource = TestResources.getTestResourceFile("config/4.5.2-config.yml", ConfigUpdater.class);
|
||||
Files.copy(configResource.toPath(), oldConfig.toPath());
|
||||
|
||||
oldBungeeConfig = tempDir.resolve("bungeeconfig.yml").toFile();
|
||||
File bungeeConfigResource = TestResources.getTestResourceFile("config/4.5.2-bungeeconfig.yml", ConfigUpdater.class);
|
||||
Files.copy(bungeeConfigResource.toPath(), oldBungeeConfig.toPath());
|
||||
|
||||
newConfig = tempDir.resolve("newconfig.yml");
|
||||
TestResources.copyResourceIntoFile(newConfig.toFile(), "/config.yml");
|
||||
|
||||
newBungeeConfig = tempDir.resolve("newbungeeconfig.yml");
|
||||
TestResources.copyResourceIntoFile(newBungeeConfig.toFile(), "/bungeeconfig.yml");
|
||||
|
||||
PluginLogger testLogger = new TestPluginLogger();
|
||||
UNDER_TEST = new ConfigUpdater(testLogger, new ConsoleErrorLogger(testLogger));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverConfigIsPatchedCorrectly() throws IOException, IllegalAccessException {
|
||||
PlanConfig planConfig = new PlanConfig(oldConfig, null);
|
||||
|
||||
UNDER_TEST.applyConfigUpdate(planConfig);
|
||||
|
||||
// Ensure that added settings are present
|
||||
copyMissingFrom(planConfig, newConfig);
|
||||
|
||||
Collection<Setting> settings = ConfigSettingKeyTest.getServerSettings();
|
||||
ConfigSettingKeyTest.assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bungeeConfigIsPatchedCorrectly() throws IOException, IllegalAccessException {
|
||||
PlanConfig planConfig = new PlanConfig(oldBungeeConfig, null);
|
||||
|
||||
UNDER_TEST.applyConfigUpdate(planConfig);
|
||||
|
||||
// Ensure that added settings are present
|
||||
copyMissingFrom(planConfig, newBungeeConfig);
|
||||
|
||||
Collection<Setting> settings = ConfigSettingKeyTest.getProxySettings();
|
||||
ConfigSettingKeyTest.assertValidDefaultValuesForAllSettings(planConfig, settings);
|
||||
}
|
||||
|
||||
private void copyMissingFrom(PlanConfig planConfig, Path newBungeeConfig) throws IOException {
|
||||
try (ConfigReader reader = new ConfigReader(newBungeeConfig)) {
|
||||
planConfig.copyMissing(reader.read());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,10 @@ package utilities;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -31,7 +34,10 @@ public class TestResources {
|
||||
}
|
||||
|
||||
public static File getTestResourceFile(String called, Class testClass) throws URISyntaxException {
|
||||
return Paths.get(testClass.getResource("/" + called).toURI()).toFile();
|
||||
URL resource = testClass.getResource("/" + called);
|
||||
URI resourceURI = resource.toURI();
|
||||
Path resourcePath = Paths.get(resourceURI);
|
||||
return resourcePath.toFile();
|
||||
}
|
||||
|
||||
public static void copyResourceIntoFile(File toFile, String resourcePath) {
|
||||
|
Loading…
Reference in New Issue
Block a user