Base test

This commit is contained in:
jeffcheasey88 2023-09-04 12:44:48 +02:00
parent 5fde1c1747
commit 14b12634f8
10 changed files with 161 additions and 5 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
bin/
.project
config.txt
config-test.txt
dist/
testApi/
.apt_generated/*

1
database-schem.sql Normal file
View file

@ -0,0 +1 @@

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(){
}
}