Started creating a tester for Plan

This commit is contained in:
Rsl1122 2017-02-12 17:03:26 +02:00
parent 4e6d84cde2
commit 869df1f374
18 changed files with 2029 additions and 3 deletions

3
.gitignore vendored
View File

@ -9,4 +9,5 @@
/Plan Advanced/nbproject/private/
/Plan/target/
/Plan/nbproject/
/Debugger/nbproject/private/
/Debugger/nbproject/private/
/PlanDebugger/nbproject/private/

47
Plan/nbactions.xml Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<preAction>build-with-dependencies</preAction>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2 -classpath %classpath org.bukkit.craftbukkit.Main -classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2 -classpath %classpath org.bukkit.craftbukkit.Main -classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2 -classpath %classpath org.bukkit.craftbukkit.Main -classpath D:\Minecraft Servers\Buildtools\craftbukkit-1.11.2</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>

View File

@ -54,12 +54,15 @@ import org.bukkit.scheduler.BukkitTask;
/* TODO 2.6.0
Placeholder API
Database cleaning
Play session lenght
Play session length
Location Analysis to view meaningful locations on Dynmap (Investigate dynmap api)
Integrate PlanLite features to Plan and discontinue PlanLite
Seperate serverdata and userdata saving
Database Cleaning of useless data
Fix any bugs that come up
- New Players not counted for some reason.
Sortable player table.
Add -n argument for nickname search.
*/
/**
*

View File

@ -59,5 +59,8 @@ public enum Settings {
public int getNumber() {
return getPlugin(Plan.class).getConfig().getInt(configPath);
}
public String getPath() {
return configPath;
}
}

73
PlanDebugger/build.xml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="PlanDebugger" default="default" basedir=".">
<description>Builds, tests, and runs the project PlanDebugger.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="PlanDebugger-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

3
PlanDebugger/manifest.mf Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=a317dbfb
build.xml.script.CRC32=e58faa21
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=a317dbfb
nbproject/build-impl.xml.script.CRC32=47a3e003
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

View File

@ -0,0 +1,78 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/PlanDebugger.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.craftbukkit-1.11.2.jar=D:\\Minecraft Servers\\Buildtools\\craftbukkit-1.11.2.jar
file.reference.Plan-jar-with-dependencies.jar=..\\Plan\\target\\Plan-jar-with-dependencies.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.Plan-jar-with-dependencies.jar}:\
${file.reference.craftbukkit-1.11.2.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=com.djrapitops.plandebugger.PlanDebugger
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>PlanDebugger</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@ -0,0 +1,117 @@
/*
* Player Analytics Bukkit plugin for monitoring server activity.
* Copyright (C) 2016 Risto Lahtela / Rsl1122
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Plan License. (licence.yml)
* Modified software can only be redistributed if allowed in the licence.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License for more details.
*
* You should have received a copy of the License
* along with this program.
* If not it should be visible on the distribution page.
* Or here
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/licence.yml
*/
package com.djrapitops.plandebugger;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plandebugger.config.ConfigSetter;
import com.djrapitops.plandebugger.config.SettingsList;
import com.djrapitops.plandebugger.tests.IndependentTestRunner;
import com.djrapitops.plandebugger.tests.PluginTestRunner;
import com.djrapitops.plandebugger.tests.TestRunner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import main.java.com.djrapitops.plan.Settings;
import org.bukkit.plugin.java.JavaPlugin;
/**
*
* @author Rsl1122
*/
public class PlanDebugger extends JavaPlugin {
private Plan plan;
private ConfigSetter configSetter;
private String originalDB;
private String debugTime;
@Override
public void onEnable() {
plan = getPlugin(Plan.class);
runConsoleCommand("plan manage backup mysql");
runConsoleCommand("plan manage backup sqlite");
originalDB = plan.getConfig().getString(Settings.DB_TYPE.getPath());
configSetter = new ConfigSetter(this, plan);
debugTime = FormatUtils.formatTimeStamp(new Date().getTime()+"").replaceAll(" ", "");
int[] r = new int[]{0, 0, 0};
TestRunner iTestRunner = new IndependentTestRunner(this, plan);
List<String> errors = iTestRunner.runAllTests();
r[0] = iTestRunner.getTestsRun();
r[1] = iTestRunner.getTestsFailed();
r[2] = iTestRunner.getTestsError();
TestRunner testRunner = new PluginTestRunner(this, plan);
for (SettingsList s : SettingsList.values()) {
configSetter.setSettings(s);
errors.addAll(testRunner.runAllTests());
}
log("\nTEST RESULTS - Run: "+r[0]+" Success: "+(r[0]-r[1]-r[2])+" Failed: "+r[1]+" Errors: "+r[2]+"\n");
log("ERRORS:");
for (String error : errors) {
logError("Error: "+error);
}
}
@Override
public void onDisable() {
plan.getConfig().set(Settings.DB_TYPE.getPath(), originalDB);
configSetter.resetSettings();
log("Tests Complete!");
log("Restore the old database by using the restore command.");
}
public void log(String message) {
getLogger().info(message);
toLog(message);
}
public void logError(String message) {
getLogger().severe(message);
toLog(message);
}
public void toLog(String message) {
File folder = getDataFolder();
if (!folder.exists()) {
folder.mkdir();
}
File log = new File(getDataFolder(), "DebugLog-" + debugTime + ".txt");
try {
if (!log.exists()) {
log.createNewFile();
}
FileWriter fw = new FileWriter(log, true);
try (PrintWriter pw = new PrintWriter(fw)) {
String timestamp = FormatUtils.formatTimeStamp(new Date().getTime()+"");
pw.println("["+timestamp+"] "+message + "\n");
pw.flush();
}
} catch (IOException e) {
logError("Failed to create log.txt file");
}
}
public void runConsoleCommand(String command) {
getServer().dispatchCommand(getServer().getConsoleSender(), command);
}
}

View File

@ -0,0 +1,82 @@
package com.djrapitops.plandebugger.config;
import com.djrapitops.plan.Plan;
import com.djrapitops.plandebugger.PlanDebugger;
import main.java.com.djrapitops.plan.Settings;
import org.bukkit.configuration.file.FileConfiguration;
/**
*
* @author Rsl1122
*/
public class ConfigSetter {
private Plan plan;
private PlanDebugger debug;
private String[] originalSettings;
public ConfigSetter(PlanDebugger debug, Plan plan) {
this.plan = plan;
this.debug = debug;
originalSettings = getDefaultSettings();
}
public void setSettings(SettingsList list) {
setSettings(list.getValues());
debug.log("SETTINGS Set settings to "+list.name());
}
public void setSettings(String[] s) {
FileConfiguration c = plan.getConfig();
c.set(Settings.LOCALE.getPath(), s[0]);
c.set(Settings.GATHERLOCATIONS.getPath(), s[1]);
c.set(Settings.ANALYSIS_LOG_TO_CONSOLE.getPath(), s[2]);
c.set(Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getPath(), s[3]);
c.set(Settings.ANALYSIS_REFRESH_ON_ENABLE.getPath(), s[4]);
c.set(Settings.ANALYSIS_AUTO_REFRESH.getPath(), s[5]);
c.set(Settings.CLEAR_INSPECT_CACHE.getPath(), s[6]);
c.set(Settings.SAVE_CACHE_MIN.getPath(), s[7]);
c.set(Settings.SAVE_SERVER_MIN.getPath(), s[8]);
c.set(Settings.CLEAR_CACHE_X_SAVES.getPath(), s[9]);
c.set(Settings.WEBSERVER_ENABLED.getPath(), s[10]);
c.set(Settings.WEBSERVER_PORT.getPath(), s[11]);
c.set(Settings.SHOW_ALTERNATIVE_IP.getPath(), s[12]);
c.set(Settings.ALTERNATIVE_IP.getPath(), s[13]);
c.set(Settings.SECURITY_IP_UUID.getPath(), s[14]);
c.set(Settings.SECURITY_CODE.getPath(), s[15]);
c.set(Settings.PLANLITE_ENABLED.getPath(), s[16]);
c.set(Settings.USE_ALTERNATIVE_UI.getPath(), s[17]);
plan.saveConfig();
plan.reloadConfig();
plan.onDisable();
plan.onEnable();
}
public void resetSettings() {
setSettings(originalSettings);
}
private String[] getDefaultSettings() {
FileConfiguration c = plan.getConfig();
return new String[]{
c.get(Settings.LOCALE.getPath()) + "",
c.get(Settings.GATHERLOCATIONS.getPath()) + "",
c.get(Settings.ANALYSIS_LOG_TO_CONSOLE.getPath()) + "",
c.get(Settings.ANALYSIS_MINUTES_FOR_ACTIVE.getPath()) + "",
c.get(Settings.ANALYSIS_REFRESH_ON_ENABLE.getPath()) + "",
c.get(Settings.ANALYSIS_AUTO_REFRESH.getPath()) + "",
c.get(Settings.CLEAR_INSPECT_CACHE.getPath()) + "",
c.get(Settings.SAVE_CACHE_MIN.getPath()) + "",
c.get(Settings.SAVE_SERVER_MIN.getPath()) + "",
c.get(Settings.CLEAR_CACHE_X_SAVES.getPath()) + "",
c.get(Settings.WEBSERVER_ENABLED.getPath()) + "",
c.get(Settings.WEBSERVER_PORT.getPath()) + "",
c.get(Settings.SHOW_ALTERNATIVE_IP.getPath()) + "",
c.get(Settings.ALTERNATIVE_IP.getPath()) + "",
c.get(Settings.SECURITY_IP_UUID.getPath()) + "",
c.get(Settings.SECURITY_CODE.getPath()) + "",
c.get(Settings.PLANLITE_ENABLED.getPath()) + "",
c.get(Settings.USE_ALTERNATIVE_UI.getPath()) + ""
};
}
}

View File

@ -0,0 +1,19 @@
package com.djrapitops.plandebugger.config;
/**
*
* @author Rsl1122
*/
public enum SettingsList {
DEFAULT(new String[]{"default", "true", "false", "10", "true", "-1", "5", "2", "1", "5", "true", "8804", "false", "your.ip.here:%port%", "true", "bAkEd", "true", "false"});
private String[] values;
private SettingsList(String[] values) {
this.values = values;
}
public String[] getValues() {
return values;
}
}

View File

@ -0,0 +1,36 @@
package com.djrapitops.plandebugger.tests;
import com.djrapitops.plan.Plan;
import com.djrapitops.plandebugger.PlanDebugger;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Rsl1122
*/
public class IndependentTestRunner extends TestRunner {
private List<Test> tests;
public IndependentTestRunner(PlanDebugger debug, Plan plan) {
super(debug, plan);
}
@Override
public List<String> runAllTests() {
List<String> errors = new ArrayList<>();
for (Test test : tests) {
try {
test.runTest();
} catch (Exception e) {
String msg = "Test "+test.getTestName()+" ran into ERROR: "+e.getMessage();
debug.logError(msg);
for (StackTraceElement x : e.getStackTrace()) {
debug.toLog(x+"");
}
errors.add(msg);
}
}
return errors;
}
}

View File

@ -0,0 +1,38 @@
package com.djrapitops.plandebugger.tests;
import com.djrapitops.plan.Plan;
import com.djrapitops.plandebugger.PlanDebugger;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Rsl1122
*/
public class PluginTestRunner extends TestRunner {
private List<Test> tests;
public PluginTestRunner(PlanDebugger debug, Plan plan) {
super(debug, plan);
}
@Override
public List<String> runAllTests() {
List<String> errors = new ArrayList<>();
for (Test test : tests) {
try {
test.runTest();
} catch (Exception e) {
String msg = "Test "+test.getTestName()+" ran into ERROR: "+e.getMessage();
debug.logError(msg);
for (StackTraceElement x : e.getStackTrace()) {
debug.toLog(x+"");
}
errors.add(msg);
}
}
return errors;
}
}

View File

@ -0,0 +1,35 @@
package com.djrapitops.plandebugger.tests;
import com.djrapitops.plan.Plan;
import com.djrapitops.plandebugger.PlanDebugger;
/**
*
* @author Rsl1122
*/
public abstract class Test {
Plan plan;
PlanDebugger debug;
private String testName;
public Test(Plan plan, PlanDebugger debug, String testName) {
this.plan = plan;
this.debug = debug;
}
public abstract boolean runTest() throws Exception;
public void pass() {
debug.log("Test "+testName+": PASSED");
}
public void fail() {
debug.logError("Test "+testName+": FAILED");
}
public String getTestName() {
return testName;
}
}

View File

@ -0,0 +1,41 @@
package com.djrapitops.plandebugger.tests;
import com.djrapitops.plan.Plan;
import com.djrapitops.plandebugger.PlanDebugger;
import java.util.List;
/**
*
* @author Rsl1122
*/
public abstract class TestRunner {
Plan plan;
PlanDebugger debug;
private int testsRun;
private int testsFailed;
private int testsError;
public TestRunner(PlanDebugger debug, Plan plan) {
this.plan = plan;
this.debug = debug;
testsRun = 0;
testsFailed = 0;
testsError = 0;
}
public abstract List<String> runAllTests();
public int getTestsRun() {
return testsRun;
}
public int getTestsFailed() {
return testsFailed;
}
public int getTestsError() {
return testsError;
}
}

View File

@ -0,0 +1,7 @@
name: PlanDebugger
main: com.djrapitops.plandebugger.PlanDebugger
author: Rsl1122
version: 2.5.1
depend:
- Plan