base test

This commit is contained in:
jeffcheasey88 2023-09-04 12:36:18 +02:00
parent 5fde1c1747
commit fbacf54674
11 changed files with 169 additions and 6 deletions

9
config-test.txt Normal file
View file

@ -0,0 +1,9 @@
db_host=170.75.166.204
db_port=3306
db_user=admin1
db_database=pac_test
db_password=admin@Pac
tcp_port=80
token_issuer=localhost
token_expiration=10
groupQuitMinutes=10

1
database-schem.sql Normal file
View file

@ -0,0 +1 @@

View file

@ -58,7 +58,6 @@ public class Main{
router.register(new Response(){
@Route(path = "^(.*)$", type = OPTIONS)
@Override
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
writer.response(200, "Access-Control-Allow-Origin: *",
"Access-Control-Allow-Methods: *", "Access-Control-Allow-Headers: *");

View file

@ -0,0 +1,53 @@
package be.jeffcheasey88.peeratcode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
public class TestDatabaseRepository extends DatabaseRepository{
private Connection con;
private String schem;
public TestDatabaseRepository(Configuration config, File databaseSchem){
super(config);
try{
schem = "";
BufferedReader reader = new BufferedReader(new FileReader(databaseSchem));
String line;
while((line = reader.readLine()) != null) schem+=line+"\n";
reader.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void init(){
try {
Method method = DatabaseRepository.class.getDeclaredMethod("ensureConnection");
method.setAccessible(true);
method.invoke(this);
Field field = DatabaseRepository.class.getDeclaredField("con");
field.setAccessible(true);
this.con = (Connection) field.get(this);
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getCause());
}
}
public void reset(){
try{
this.con.prepareStatement(schem).execute();
}catch(Exception e){
e.printStackTrace();
}
}
}

View file

@ -1,4 +1,4 @@
package be.jeffcheasey88.peeratcode.webclient;
package be.jeffcheasey88.peeratcode;
import static org.junit.Assert.fail;

View file

@ -9,7 +9,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.webclient.WebClient;
import be.jeffcheasey88.peeratcode.WebClient;
@TestInstance(Lifecycle.PER_CLASS)
class PlayerDetailsTests {

View file

@ -10,7 +10,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.webclient.WebClient;
import be.jeffcheasey88.peeratcode.WebClient;
@TestInstance(Lifecycle.PER_CLASS)
public class ScoreTests {

View file

@ -10,7 +10,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.webclient.WebClient;
import be.jeffcheasey88.peeratcode.WebClient;
@TestInstance(Lifecycle.PER_CLASS)
public class TmpRoutesTests {

View file

@ -9,7 +9,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.webclient.WebClient;
import be.jeffcheasey88.peeratcode.WebClient;
@TestInstance(Lifecycle.PER_CLASS)
public class TriggerTests {

View file

@ -0,0 +1,28 @@
package be.jeffcheasey88.peeratcode.userstories;
import java.io.File;
import be.jeffcheasey88.peeratcode.Configuration;
import be.jeffcheasey88.peeratcode.TestDatabaseRepository;
public class BaseUserStoriesTest {
private Configuration config;
private TestDatabaseRepository repo;
public BaseUserStoriesTest(){}
public void init(){
this.config = new Configuration("config-test.txt");
this.repo = new TestDatabaseRepository(config, new File("database-schem.sql"));
}
public Configuration getConfig(){
return this.config;
}
public TestDatabaseRepository getRepository(){
return this.repo;
}
}

View file

@ -0,0 +1,73 @@
package be.jeffcheasey88.peeratcode.userstories;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import be.jeffcheasey88.peeratcode.Main;
import be.jeffcheasey88.peeratcode.WebClient;
@TestInstance(Lifecycle.PER_METHOD)
public class RegisterTests extends BaseUserStoriesTest{
private Thread server;
private WebClient client;
@BeforeEach
public void init(){
super.init();
getRepository().init();
getRepository().reset();
server = new Thread(new Runnable(){
@Override
public void run(){
try {
Main.main(null);
} catch (Exception e){
e.printStackTrace();
};
}
});
server.start();
client = new WebClient("localhost", 80);
}
@AfterEach
public void stop(){
server.interrupt();
}
@Test
public void normalRegister() throws Exception{
client.register("test", "test", "test@peerat.dev", "te", "st", "my desc");
client.assertResponseCode(200);
}
@Test
public void pseudoAlreadyUse(){
}
@Test
public void emailAlreadyUse(){
}
@Test
public void emptyField(){
}
@Test
public void lostField(){
}
@Test
public void alreadyLoggedin(){
}
}