mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
refactor(demo): Move all tests to demo.
This commit is contained in:
+74
-5
@@ -13,7 +13,10 @@
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
|
||||
<deps.mysql-driver.version>8.0.33</deps.mysql-driver.version>
|
||||
<log4j.version>2.24.3</log4j.version>
|
||||
</properties>
|
||||
<artifactId>configured-demo</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -24,42 +27,108 @@
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-feature-commentable</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-feature-versioned</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-feature-validators</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-feature-kotlin</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-yaml</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-gson</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-sql</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<version>0.4.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${deps.mysql-driver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-mongodb</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>configured-hocon</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package cc.carm.lib.configuration.tests.test;
|
||||
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.json.JSONConfigFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class JSONConfigTests {
|
||||
|
||||
protected final ConfigurationHolder<?> holder = JSONConfigFactory
|
||||
.from(new File("target"), "config.json")
|
||||
.resourcePath("example.json")
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void onTest() {
|
||||
ConfigurationTest.testDemo(this.holder);
|
||||
ConfigurationTest.testInner(this.holder);
|
||||
|
||||
ConfigurationTest.save(this.holder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cc.carm.lib.configuration.tests.test;
|
||||
|
||||
import cc.carm.lib.configuration.commentable.CommentableMeta;
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLSource;
|
||||
import cc.carm.lib.configuration.validators.Validators;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class YamlTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ConfigurationHolder<YAMLSource> holder = YAMLConfigFactory.from("target/tests.yml")
|
||||
.resourcePath("configs/sample.yml").build();
|
||||
|
||||
Validators.activate(holder);
|
||||
|
||||
ConfigurationTest.testDemo(holder);
|
||||
ConfigurationTest.testInner(holder);
|
||||
|
||||
Map<String, List<String>> headers = holder.extractMetadata(CommentableMeta.HEADER);
|
||||
System.out.println("Header comments: ");
|
||||
headers.forEach((k, v) -> {
|
||||
if (v.isEmpty()) return;
|
||||
System.out.println("- " + k + ": ");
|
||||
v.forEach(s -> System.out.println("- | " + s));
|
||||
});
|
||||
|
||||
Map<String, List<String>> footers = holder.extractMetadata(CommentableMeta.FOOTER);
|
||||
System.out.println("Footer comments: ");
|
||||
footers.forEach((k, v) -> {
|
||||
if (v.isEmpty()) return;
|
||||
System.out.println("- " + k + ": ");
|
||||
v.forEach(s -> System.out.println("- | " + s));
|
||||
});
|
||||
|
||||
|
||||
ConfigurationTest.save(holder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKotlin() {
|
||||
ConfigurationHolder<YAMLSource> holder = YAMLConfigFactory.from("target/kotlin.yml").build();
|
||||
|
||||
ConfigurationTest.testKotlin(holder);
|
||||
|
||||
ConfigurationTest.save(holder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package cc.carm.lib.configuration.tests.test.mongodb;
|
||||
|
||||
import cc.carm.lib.configuration.Configuration;
|
||||
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||
|
||||
interface MongoConfig extends Configuration {
|
||||
ConfiguredValue<String> HOST = ConfiguredValue.of("127.0.0.1");
|
||||
ConfiguredValue<Integer> PORT = ConfiguredValue.of(27017);
|
||||
ConfiguredValue<String> USERNAME = ConfiguredValue.of("minecraft");
|
||||
ConfiguredValue<String> PASSWORD = ConfiguredValue.of("minecraft");
|
||||
ConfiguredValue<String> DATABASE = ConfiguredValue.of("minecraft");
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package cc.carm.lib.configuration.tests.test.mongodb;
|
||||
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.json.JSONConfigFactory;
|
||||
import cc.carm.lib.configuration.source.mongodb.MongoConfigFactory;
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.UuidRepresentation;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class MongoTest {
|
||||
|
||||
boolean local = false;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (!local) return;
|
||||
|
||||
ConfigurationHolder<?> gsonHolder = JSONConfigFactory.from(new File("target/mongo.json")).build();
|
||||
gsonHolder.initialize(MongoConfig.class);
|
||||
|
||||
MongoClientSettings settings = MongoClientSettings.builder()
|
||||
.applyConnectionString(new ConnectionString(
|
||||
"mongodb://" + MongoConfig.HOST.resolve() + ":" + MongoConfig.PORT.resolve()
|
||||
))
|
||||
.credential(MongoCredential.createCredential(
|
||||
MongoConfig.USERNAME.resolve(), MongoConfig.DATABASE.resolve(),
|
||||
MongoConfig.PASSWORD.resolve().toCharArray()
|
||||
))
|
||||
.uuidRepresentation(UuidRepresentation.STANDARD)
|
||||
.build();
|
||||
MongoClient mongoClient = MongoClients.create(settings);
|
||||
MongoDatabase mongoDatabase = mongoClient.getDatabase(MongoConfig.DATABASE.resolve());
|
||||
|
||||
ConfigurationHolder<?> mongoHolder = MongoConfigFactory
|
||||
.from(mongoDatabase, "configs")
|
||||
.namespace("my_plugin")
|
||||
.build();
|
||||
|
||||
// Test the configuration
|
||||
ConfigurationTest.testDemo(mongoHolder);
|
||||
ConfigurationTest.testInner(mongoHolder);
|
||||
|
||||
ConfigurationTest.save(mongoHolder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cc.carm.lib.configuration.tests.test.sql;
|
||||
|
||||
import cc.carm.lib.configuration.demo.DatabaseConfiguration;
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.json.JSONConfigFactory;
|
||||
import cc.carm.lib.configuration.source.sql.SQLConfigFactory;
|
||||
import cc.carm.lib.easysql.EasySQL;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.beecp.BeeDataSourceConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SQLConfigTest {
|
||||
|
||||
boolean local = false;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
if (!local) return;
|
||||
|
||||
ConfigurationHolder<?> gsonHolder = JSONConfigFactory.from(new File("target/sql.json")).build();
|
||||
gsonHolder.initialize(DatabaseConfiguration.class);
|
||||
|
||||
BeeDataSourceConfig config = new BeeDataSourceConfig();
|
||||
config.setDriverClassName(DatabaseConfiguration.DRIVER_NAME.resolve());
|
||||
config.setJdbcUrl(DatabaseConfiguration.buildJDBC());
|
||||
config.setUsername(DatabaseConfiguration.USERNAME.resolve());
|
||||
config.setPassword(DatabaseConfiguration.PASSWORD.resolve());
|
||||
|
||||
SQLManager manager = EasySQL.createManager(config);
|
||||
manager.setDebugMode(true);
|
||||
|
||||
ConfigurationHolder<?> holder = SQLConfigFactory.from(manager)
|
||||
.tableName("test_configs")
|
||||
.namespace("testing")
|
||||
.build();
|
||||
|
||||
ConfigurationTest.testDemo(holder);
|
||||
ConfigurationTest.testInner(holder);
|
||||
|
||||
ConfigurationTest.save(holder);
|
||||
|
||||
EasySQL.shutdownManager(manager);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"example": "true"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" packages="cc.carm.lib.configuration.tests">
|
||||
<Appenders>
|
||||
<console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
|
||||
</console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="info">
|
||||
<filters>
|
||||
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
<RegexFilter regex=".*\$\{[^}]*\}.*" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
</filters>
|
||||
<AppenderRef ref="File"/>
|
||||
<appender-ref ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
||||
Reference in New Issue
Block a user