Skip to content

Commit

Permalink
Lancement du main avant tous les tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charllie committed Dec 14, 2015
1 parent 2d021ec commit 212ee6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fr/enseirb/t3/it340/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void main(String[] args) throws SQLException, ClassNotFoundExcepti
engine.setConfiguration(cfg);

// Choix du port
port((args.length > 0) ? Integer.parseInt(args[0]) : getPort());
port(getPort());

// Gestion des urls
get("/", new VisualisationAccueil(), engine);
Expand Down
30 changes: 14 additions & 16 deletions src/test/java/fr/enseirb/t3/it340/servlets/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -22,18 +20,17 @@
import java.util.*;

import static org.junit.Assert.*;
import static spark.Spark.*;
import static spark.Spark.stop;

public class TestApp {

String args[] = new String[1];
@BeforeClass
public static void beforeClass() throws SQLException, IOException, ClassNotFoundException {
App.main(null);
}

@Before
public void before() {
Random rn = new Random();
int min = 1025;
int max = 65535;
args[0] = Integer.toString(rn.nextInt((max - min) + 1) + min);
BddUtilisateur.ajout("labri@labri.com", "labri");
BddUtilisateur.ajout("charlie@heloise.com", "mdp");
BddLabo.ajout(1, "Labri");
Expand All @@ -50,7 +47,7 @@ public void testGetProperties() throws IOException {

@Test
public void testMainGetVisiteur() throws SQLException, IOException, ClassNotFoundException {
String format = "http://0.0.0.0:" + args[0] + "%s";
String format = "http://localhost:" + App.getPort() + "%s";
HttpGet request;
HttpResponse response;
Set<String> urls200 = new HashSet<String>();
Expand All @@ -76,7 +73,6 @@ public void testMainGetVisiteur() throws SQLException, IOException, ClassNotFoun
urls302.add("/atelier/1/creneaux/1/inscrire");
urls302.add("/enseignant");

App.main(args);
CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build();

// Test 200 OK
Expand All @@ -103,13 +99,12 @@ public void testMainGetVisiteur() throws SQLException, IOException, ClassNotFoun

@Test
public void testMainGetLabo() throws SQLException, IOException, ClassNotFoundException {
String format = "http://0.0.0.0:" + args[0] + "%s";
String format = "http://localhost:" + App.getPort() + "%s";
HttpGet request;
HttpResponse response;
Set<String> urls200 = new HashSet<String>();
Set<String> urls302 = new HashSet<String>();

App.main(args);
CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build();

// Authentification en tant que labo
Expand Down Expand Up @@ -164,13 +159,12 @@ public void testMainGetLabo() throws SQLException, IOException, ClassNotFoundExc

@Test
public void testMainGetEnseignant() throws SQLException, IOException, ClassNotFoundException {
String format = "http://0.0.0.0:" + args[0] + "%s";
String format = "http://localhost:" + App.getPort() + "%s";
HttpGet request;
HttpResponse response;
Set<String> urls200 = new HashSet<String>();
Set<String> urls302 = new HashSet<String>();

App.main(args);
CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build();

// Authentification en tant qu'enseignant
Expand Down Expand Up @@ -225,7 +219,6 @@ public void testMainGetEnseignant() throws SQLException, IOException, ClassNotFo

@After
public void dispose() throws SQLException, IOException, ClassNotFoundException {
stop();
Connection connection = BddConnecteur.getConnection();
Statement statement = connection.createStatement();
statement.execute("DROP TABLE Enregistrement");
Expand All @@ -238,4 +231,9 @@ public void dispose() throws SQLException, IOException, ClassNotFoundException {
connection.close();
BddConnecteur.dispose();
}

@AfterClass
public static void disposeClass() {
stop();
}
}

0 comments on commit 212ee6b

Please sign in to comment.