2020-10-20 18:19:20 +03:00
|
|
|
package InnaIrcBot.logging;
|
2020-10-20 03:37:20 +03:00
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
import InnaIrcBot.config.LogDriverConfiguration;
|
|
|
|
import org.junit.jupiter.api.Disabled;
|
2020-10-20 03:37:20 +03:00
|
|
|
import org.junit.jupiter.api.DisplayName;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
class LogDriverTest {
|
2020-10-20 03:37:20 +03:00
|
|
|
@TempDir
|
|
|
|
Path mainLogsDir,
|
|
|
|
mainSQLiteLogsDir;
|
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
private static final String serverNameFiles = "files.example.com";
|
|
|
|
private static final String serverNameSQLite = "sqlite.example.com";
|
|
|
|
private static final String serverNameMongoDB = "mongo.example.com";
|
2020-10-20 03:37:20 +03:00
|
|
|
private Worker fw1;
|
|
|
|
private Worker fw2;
|
|
|
|
private Worker fw3;
|
|
|
|
|
|
|
|
@DisplayName("BotDriver: test files driver")
|
|
|
|
@Test
|
|
|
|
void driverFilesTest() {
|
2020-10-20 18:19:20 +03:00
|
|
|
initializeFilesLogDriver();
|
|
|
|
createWorkers(serverNameFiles);
|
2020-10-20 03:37:20 +03:00
|
|
|
checkConsistency();
|
|
|
|
checkFilesWorkers();
|
|
|
|
validateDriver();
|
|
|
|
checkFilesWorkers();
|
|
|
|
close();
|
|
|
|
}
|
2020-10-20 18:19:20 +03:00
|
|
|
void checkFilesWorkers(){
|
|
|
|
assertTrue(fw1 instanceof WorkerFiles);
|
|
|
|
assertTrue(fw2 instanceof WorkerFiles);
|
|
|
|
assertTrue(fw3 instanceof WorkerFiles);
|
2020-10-20 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@DisplayName("BotDriver: test SQLite driver")
|
|
|
|
@Test
|
|
|
|
void driverSQLiteTest() {
|
2020-10-20 18:19:20 +03:00
|
|
|
initializeSQLiteLogDriver();
|
|
|
|
createWorkers(serverNameSQLite);
|
2020-10-20 03:37:20 +03:00
|
|
|
checkConsistency();
|
|
|
|
checkSQLiteWorkers();
|
|
|
|
validateDriver();
|
|
|
|
checkSQLiteWorkers();
|
|
|
|
close();
|
|
|
|
}
|
2020-10-20 18:19:20 +03:00
|
|
|
void checkSQLiteWorkers(){
|
|
|
|
assertTrue(fw1 instanceof WorkerSQLite);
|
|
|
|
assertTrue(fw2 instanceof WorkerSQLite);
|
|
|
|
assertTrue(fw3 instanceof WorkerSQLite);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Disabled("MongoDB connection/configuration example. Requires real MongdDB instance created & configured")
|
|
|
|
@DisplayName("BotDriver: test MongoDB driver")
|
|
|
|
@Test
|
|
|
|
void driverMongoTest() {
|
|
|
|
initializeMongoDBLogDriver();
|
|
|
|
createWorkers(serverNameMongoDB);
|
|
|
|
checkConsistency();
|
|
|
|
checkMongoDBWorkers();
|
|
|
|
validateDriver();
|
|
|
|
checkMongoDBWorkers();
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
void checkMongoDBWorkers(){
|
|
|
|
assertTrue(fw1 instanceof WorkerMongoDB);
|
|
|
|
assertTrue(fw2 instanceof WorkerMongoDB);
|
|
|
|
assertTrue(fw3 instanceof WorkerMongoDB);
|
2020-10-20 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
private void createWorkers(String server){
|
2020-10-31 01:20:17 +03:00
|
|
|
/*
|
2020-10-20 18:19:20 +03:00
|
|
|
fw1 = LogDriver.getWorker(server,"system");
|
|
|
|
fw2 = LogDriver.getWorker(server,"#main");
|
|
|
|
fw3 = LogDriver.getWorker(server,"#lpr");
|
2020-10-31 01:20:17 +03:00
|
|
|
|
|
|
|
*/
|
2020-10-20 18:19:20 +03:00
|
|
|
}
|
2020-10-20 03:37:20 +03:00
|
|
|
void checkConsistency(){
|
|
|
|
assertTrue(fw1.isConsistent());
|
|
|
|
assertTrue(fw2.isConsistent());
|
|
|
|
assertTrue(fw3.isConsistent());
|
|
|
|
}
|
|
|
|
|
|
|
|
void validateDriver(){
|
2020-10-31 01:20:17 +03:00
|
|
|
/*
|
2020-10-20 03:37:20 +03:00
|
|
|
assertTrue(fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1"));
|
|
|
|
assertTrue(fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here"));
|
|
|
|
assertTrue(fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests"));
|
|
|
|
assertTrue(fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su"));
|
|
|
|
assertTrue(fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username"));
|
|
|
|
assertTrue(fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1"));
|
|
|
|
|
|
|
|
assertTrue(fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2"));
|
|
|
|
assertTrue(fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here"));
|
|
|
|
assertTrue(fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests"));
|
|
|
|
assertTrue(fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su"));
|
|
|
|
assertTrue(fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username"));
|
|
|
|
assertTrue(fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2"));
|
|
|
|
|
|
|
|
assertTrue(fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3"));
|
|
|
|
assertTrue(fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here"));
|
|
|
|
assertTrue(fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests"));
|
|
|
|
assertTrue(fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su"));
|
|
|
|
assertTrue(fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username"));
|
|
|
|
assertTrue(fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3"));
|
2020-10-31 01:20:17 +03:00
|
|
|
|
|
|
|
*/
|
2020-10-20 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
private void initializeFilesLogDriver(){
|
2020-10-23 13:43:53 +03:00
|
|
|
LogDriverConfiguration filesDrv = new LogDriverConfiguration("FileS",
|
|
|
|
mainLogsDir.toString(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
2020-10-31 01:20:17 +03:00
|
|
|
WorkerSystem.setLogDriver(serverNameFiles);
|
2020-10-20 18:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeSQLiteLogDriver(){
|
2020-10-23 13:43:53 +03:00
|
|
|
LogDriverConfiguration sqliteDrv = new LogDriverConfiguration("SQliTe",
|
|
|
|
mainLogsDir.toString(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
|
2020-10-31 01:20:17 +03:00
|
|
|
WorkerSystem.setLogDriver(serverNameSQLite);
|
2020-10-20 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
2020-10-20 18:19:20 +03:00
|
|
|
private void initializeMongoDBLogDriver(){
|
2020-10-23 13:43:53 +03:00
|
|
|
LogDriverConfiguration mongoDrv = new LogDriverConfiguration("MongoDB",
|
|
|
|
null,
|
|
|
|
"192.168.1.186:27017",
|
|
|
|
"irc",
|
|
|
|
"loper",
|
|
|
|
"password");
|
2020-10-31 01:20:17 +03:00
|
|
|
WorkerSystem.setLogDriver("irc.tomsk.net");
|
2020-10-20 03:37:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void close(){
|
|
|
|
fw1.close();
|
|
|
|
fw2.close();
|
|
|
|
fw3.close();
|
|
|
|
}
|
|
|
|
}
|